Issue 76: added support for default query parameters on an interface

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1870 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-09-02 23:09:30 +00:00
parent 8889daaa9b
commit 086bab21f3
3 changed files with 30 additions and 3 deletions

View File

@ -214,6 +214,14 @@ public class JaxrsAnnotationProcessor {
builder.path(declaring);
builder.path(method);
if (declaring.isAnnotationPresent(Query.class)) {
Query query = declaring.getAnnotation(Query.class);
if (query.value().equals(Query.NULL))
builder.replaceQuery(query.key());
else
builder.queryParam(query.key(), query.value());
}
if (method.isAnnotationPresent(Query.class)) {
Query query = method.getAnnotation(Query.class);
if (query.value().equals(Query.NULL))

View File

@ -23,7 +23,7 @@
*/
package org.jclouds.rest;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
@ -37,10 +37,10 @@ import javax.ws.rs.QueryParam;
* @see QueryParam
* @author Adrian Cole
*/
@Target(METHOD)
@Target( { TYPE, METHOD })
@Retention(RUNTIME)
public @interface Query {
public static final String NULL = "QUERY_NULL";
String key();

View File

@ -90,6 +90,25 @@ public class JaxrsAnnotationProcessorTest {
public @interface FOO {
}
@Query(key = "x-ms-version", value = "2009-07-17")
public class TestQuery {
@FOO
@Query(key = "x-ms-rubbish", value = "bin")
public void foo() {
}
}
public void testQuery() throws SecurityException, NoSuchMethodException {
Method method = TestQuery.class.getMethod("foo");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(endpoint, method,
new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
assertEquals(httpMethod.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin");
assertEquals(httpMethod.getMethod(), "FOO");
}
public class TestCustomMethod {
@FOO
public void foo() {