> You could change your code to utilize the following Jersey feature:
>
> MultivaluedMap<String, String> queryParams =
> UriComponent.decodeQuery(uri, false);
>
> For example, sometimes you can have a query parameter with no
> value and your regex will will not match that case.
Great idea, the modified code works fine:
import java.net.URI;
import java.util.List;
import java.util.Map.Entry;
import javax.ws.rs.core.MultivaluedMap;
import com.meterware.httpunit.GetMethodWebRequest;
import com.sun.jersey.api.uri.UriComponent;
public class UnitTestUtil {
public static final GetMethodWebRequest
bypassBugInServletUnit(String complete) {
URI uri = URI.create(complete);
// This is the culprit that strips away query...
GetMethodWebRequest ret = new
GetMethodWebRequest(complete);
// ... and forces us to add them afterwards
String query = uri.getQuery();
if (query != null) {
MultivaluedMap<String, String> queryParams =
UriComponent.decodeQuery(uri, false);
for (Entry<String, List<String>> entry:
queryParams.entrySet()) {
final List<String> values =
entry.getValue();
final String[] array = new
String[values.size()];
ret.setParameter(entry.getKey(),
values.toArray(array));
}
}
return ret;
}
}