From 7f1a543fb6b42ae50ad779b5645f68bf90f96039 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 8 Jul 2011 02:05:19 -0700 Subject: [PATCH] fixed problem where empty query string doesn't work: Issue 576 --- .../org/jclouds/http/utils/ModifyRequest.java | 3 ++- .../internal/RestAnnotationProcessorTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jclouds/http/utils/ModifyRequest.java b/core/src/main/java/org/jclouds/http/utils/ModifyRequest.java index ba1c0b2860..b2b7933467 100644 --- a/core/src/main/java/org/jclouds/http/utils/ModifyRequest.java +++ b/core/src/main/java/org/jclouds/http/utils/ModifyRequest.java @@ -168,8 +168,9 @@ public class ModifyRequest { while (pairs.hasNext()) { Map.Entry 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()) diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index d94e3081d3..10fdda1062 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -1865,6 +1865,11 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @QueryParams(keys = "acl") ListenableFuture getQueryNull(@PathParam("id") String id); + @GET + @Path("/{id}") + @QueryParams(keys = "acl", values="") + ListenableFuture getQueryEmpty(@PathParam("id") String id); + @PUT @Path("/{id}") ListenableFuture 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