fixed problem where empty query string doesn't work: Issue 576

This commit is contained in:
Adrian Cole 2011-07-08 02:05:19 -07:00
parent b037be29fa
commit 7f1a543fb6
2 changed files with 17 additions and 1 deletions

View File

@ -168,8 +168,9 @@ public class ModifyRequest {
while (pairs.hasNext()) {
Map.Entry<String, String> pair = pairs.next();
formBuilder.append(Strings2.urlEncode(pair.getKey(), skips));
if (pair.getValue() != null && !pair.getValue().equals("")) {
if (pair.getValue() != null)
formBuilder.append("=");
if (pair.getValue() != null && !pair.getValue().equals("")) {
formBuilder.append(Strings2.urlEncode(pair.getValue(), skips));
}
if (pairs.hasNext())

View File

@ -1865,6 +1865,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@QueryParams(keys = "acl")
ListenableFuture<String> getQueryNull(@PathParam("id") String id);
@GET
@Path("/{id}")
@QueryParams(keys = "acl", values="")
ListenableFuture<String> getQueryEmpty(@PathParam("id") String id);
@PUT
@Path("/{id}")
ListenableFuture<String> put(@PathParam("id") @ParamParser(FirstCharacter.class) String id,
@ -1947,6 +1952,16 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(request.getHeaders().size(), 0);
}
public void testCreateGetQueryEmpty() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("getQueryEmpty", String.class);
HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { "1" });
assertEquals(request.getEndpoint().getHost(), "localhost");
assertEquals(request.getEndpoint().getPath(), "/1");
assertEquals(request.getEndpoint().getQuery(), "acl=");
assertEquals(request.getMethod(), HttpMethod.GET);
assertEquals(request.getHeaders().size(), 0);
}
public class PayloadOptions extends BaseHttpRequestOptions {
@Override