diff --git a/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java index a42c5dd742..b59127c0a6 100644 --- a/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/JaxrsAnnotationProcessor.java @@ -45,6 +45,7 @@ import javax.inject.Named; import javax.inject.Singleton; import javax.ws.rs.HeaderParam; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriBuilder; @@ -93,6 +94,7 @@ public class JaxrsAnnotationProcessor { private final Map>> methodToIndexOfParamToEntityAnnotation = createMethodToIndexOfParamToAnnotation(EntityParam.class); private final Map>> methodToIndexOfParamToHeaderParamAnnotations = createMethodToIndexOfParamToAnnotation(HeaderParam.class); private final Map>> methodToIndexOfParamToHostPrefixParamAnnotations = createMethodToIndexOfParamToAnnotation(HostPrefixParam.class); + private final Map>> methodToindexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class); private final Map>> methodToindexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class); private final Map>> methodToindexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(MapEntityParam.class); private final Map>> methodToindexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class); @@ -202,6 +204,7 @@ public class JaxrsAnnotationProcessor { methodToIndexOfParamToEntityAnnotation.get(method).get(index); methodToIndexOfParamToHeaderParamAnnotations.get(method).get(index); methodToIndexOfParamToHostPrefixParamAnnotations.get(method).get(index); + methodToindexOfParamToQueryParamAnnotations.get(method).get(index); methodToindexOfParamToPathParamAnnotations.get(method).get(index); methodToindexOfParamToPostParamAnnotations.get(method).get(index); methodToindexOfParamToParamParserAnnotations.get(method).get(index); @@ -282,6 +285,10 @@ public class JaxrsAnnotationProcessor { addQuery(builder, query); } + for (Entry query : getQueryParamKeyValues(method, args).entrySet()) { + builder.queryParam(query.getKey(), query.getValue()); + } + Multimap headers = buildHeaders(method, args); HttpRequestOptions options = findOptionsIn(method, args); @@ -646,6 +653,21 @@ public class JaxrsAnnotationProcessor { return pathParamValues; } + private Map getQueryParamKeyValues(Method method, Object[] args) { + Map queryParamValues = Maps.newHashMap(); + queryParamValues.putAll(constants); + Map> indexToQueryParam = methodToindexOfParamToQueryParamAnnotations + .get(method); + for (Entry> entry : indexToQueryParam.entrySet()) { + for (Annotation key : entry.getValue()) { + String paramKey = ((QueryParam) key).value(); + String paramValue = args[entry.getKey()].toString(); + queryParamValues.put(paramKey, paramValue); + } + } + return queryParamValues; + } + private Map buildPostParams(Method method, Object[] args) { Map postParams = Maps.newHashMap(); Map> indexToPathParam = methodToindexOfParamToPostParamAnnotations diff --git a/core/src/test/java/org/jclouds/rest/JaxrsAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/JaxrsAnnotationProcessorTest.java index 014f36fd98..42e9f5aee4 100644 --- a/core/src/test/java/org/jclouds/rest/JaxrsAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/JaxrsAnnotationProcessorTest.java @@ -48,6 +48,7 @@ import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import org.jclouds.concurrent.WithinThreadExecutorService; import org.jclouds.concurrent.config.ExecutorServiceModule; @@ -115,6 +116,11 @@ public class JaxrsAnnotationProcessorTest { @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) public void foo2() { } + + @FOO + @QueryParams(keys = { "foo", "fooble" }, values = { "bar", "baz" }) + public void foo3(@QueryParam("robbie") String robbie) { + } } public void testQuery() throws SecurityException, NoSuchMethodException { @@ -138,6 +144,16 @@ public class JaxrsAnnotationProcessorTest { assertEquals(httpMethod.getMethod(), "FOO"); } + public void testQuery3() throws SecurityException, NoSuchMethodException { + Method method = TestQuery.class.getMethod("foo3", String.class); + HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(method, + new Object[] {"wonder"}); + assertEquals(httpMethod.getEndpoint().getHost(), "localhost"); + assertEquals(httpMethod.getEndpoint().getPath(), ""); + assertEquals(httpMethod.getEndpoint().getQuery(), + "x-ms-version=2009-07-17&foo=bar&fooble=baz&robbie=wonder"); + assertEquals(httpMethod.getMethod(), "FOO"); + } @Endpoint(Localhost.class) public class TestCustomMethod { @FOO