mirror of https://github.com/apache/jclouds.git
fixed issue where body of a Payload arg wasn't being added to the http request
This commit is contained in:
parent
6e975662c1
commit
1063924f6a
|
@ -166,7 +166,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
static final Map<MethodKey, Method> delegationMap = newHashMap();
|
static final Map<MethodKey, Method> delegationMap = newHashMap();
|
||||||
|
|
||||||
static Map<Method, Map<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
static Map<Method, Map<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
||||||
final Class<? extends Annotation> annotation) {
|
final Class<? extends Annotation> annotation) {
|
||||||
return new MapMaker().makeComputingMap(new Function<Method, Map<Integer, Set<Annotation>>>() {
|
return new MapMaker().makeComputingMap(new Function<Method, Map<Integer, Set<Annotation>>>() {
|
||||||
public Map<Integer, Set<Annotation>> apply(final Method method) {
|
public Map<Integer, Set<Annotation>> apply(final Method method) {
|
||||||
return new MapMaker().makeComputingMap(new GetAnnotationsForMethodParameterIndex(method, annotation));
|
return new MapMaker().makeComputingMap(new GetAnnotationsForMethodParameterIndex(method, annotation));
|
||||||
|
@ -200,7 +200,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Class<? extends HttpRequestOptions[]> optionsVarArgsClass = new HttpRequestOptions[] {}
|
private static final Class<? extends HttpRequestOptions[]> optionsVarArgsClass = new HttpRequestOptions[] {}
|
||||||
.getClass();
|
.getClass();
|
||||||
|
|
||||||
private static final Function<? super Entry<String, String>, ? extends Part> ENTRY_TO_PART = new Function<Entry<String, String>, Part>() {
|
private static final Function<? super Entry<String, String>, ? extends Part> ENTRY_TO_PART = new Function<Entry<String, String>, Part>() {
|
||||||
|
|
||||||
|
@ -212,17 +212,17 @@ public class RestAnnotationProcessor<T> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private final Map<Method, Set<Integer>> methodToIndexesOfOptions = new MapMaker()
|
private final Map<Method, Set<Integer>> methodToIndexesOfOptions = new MapMaker()
|
||||||
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
||||||
public Set<Integer> apply(final Method method) {
|
public Set<Integer> apply(final Method method) {
|
||||||
Set<Integer> toReturn = newHashSet();
|
Set<Integer> toReturn = newHashSet();
|
||||||
for (int index = 0; index < method.getParameterTypes().length; index++) {
|
for (int index = 0; index < method.getParameterTypes().length; index++) {
|
||||||
Class<?> type = method.getParameterTypes()[index];
|
Class<?> type = method.getParameterTypes()[index];
|
||||||
if (HttpRequestOptions.class.isAssignableFrom(type) || optionsVarArgsClass.isAssignableFrom(type))
|
if (HttpRequestOptions.class.isAssignableFrom(type) || optionsVarArgsClass.isAssignableFrom(type))
|
||||||
toReturn.add(index);
|
toReturn.add(index);
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
}
|
||||||
});
|
return toReturn;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
private final ParseSax.Factory parserFactory;
|
private final ParseSax.Factory parserFactory;
|
||||||
private final HttpUtils utils;
|
private final HttpUtils utils;
|
||||||
|
@ -240,7 +240,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static Function<HttpResponse, ?> createResponseParser(ParseSax.Factory parserFactory, Injector injector,
|
public static Function<HttpResponse, ?> createResponseParser(ParseSax.Factory parserFactory, Injector injector,
|
||||||
Method method, HttpRequest request) {
|
Method method, HttpRequest request) {
|
||||||
Function<HttpResponse, ?> transformer;
|
Function<HttpResponse, ?> transformer;
|
||||||
Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(method);
|
Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(method);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
|
@ -261,7 +261,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static Function<Exception, ?> createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(
|
public static Function<Exception, ?> createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(
|
||||||
Injector injector, Method method) {
|
Injector injector, Method method) {
|
||||||
ExceptionParser annotation = method.getAnnotation(ExceptionParser.class);
|
ExceptionParser annotation = method.getAnnotation(ExceptionParser.class);
|
||||||
if (annotation != null) {
|
if (annotation != null) {
|
||||||
return injector.getInstance(annotation.value());
|
return injector.getInstance(annotation.value());
|
||||||
|
@ -272,7 +272,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Inject
|
@Inject
|
||||||
public RestAnnotationProcessor(Injector injector, ParseSax.Factory parserFactory, HttpUtils utils,
|
public RestAnnotationProcessor(Injector injector, ParseSax.Factory parserFactory, HttpUtils utils,
|
||||||
TypeLiteral<T> typeLiteral) {
|
TypeLiteral<T> typeLiteral) {
|
||||||
this.declaring = (Class<T>) typeLiteral.getRawType();
|
this.declaring = (Class<T>) typeLiteral.getRawType();
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.parserFactory = parserFactory;
|
this.parserFactory = parserFactory;
|
||||||
|
@ -387,7 +387,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
public GeneratedHttpRequest<T> createRequest(Method method, Object... args) {
|
public GeneratedHttpRequest<T> createRequest(Method method, Object... args) {
|
||||||
inputParamValidator.validateMethodParametersOrThrow(method, args);
|
inputParamValidator.validateMethodParametersOrThrow(method, args);
|
||||||
ClassMethodArgs cma = logger.isTraceEnabled() ? new ClassMethodArgs(method.getDeclaringClass(), method, args)
|
ClassMethodArgs cma = logger.isTraceEnabled() ? new ClassMethodArgs(method.getDeclaringClass(), method, args)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
URI endpoint = callerEndpoint;
|
URI endpoint = callerEndpoint;
|
||||||
try {
|
try {
|
||||||
|
@ -457,7 +457,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, skips, declaring, method,
|
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, skips, declaring, method,
|
||||||
args);
|
args);
|
||||||
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
|
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
|
||||||
addFiltersIfAnnotated(method, request);
|
addFiltersIfAnnotated(method, request);
|
||||||
|
|
||||||
|
@ -472,8 +472,9 @@ public class RestAnnotationProcessor<T> {
|
||||||
} else if (formParams.size() > 0) {
|
} else if (formParams.size() > 0) {
|
||||||
payload = Payloads.newUrlEncodedFormPayload(formParams, skips);
|
payload = Payloads.newUrlEncodedFormPayload(formParams, skips);
|
||||||
} else if (headers.containsKey(CONTENT_TYPE)) {
|
} else if (headers.containsKey(CONTENT_TYPE)) {
|
||||||
payload = Payloads.newByteArrayPayload(new byte[]{});
|
if (payload == null)
|
||||||
payload.getContentMetadata().setContentType(Iterables.get(headers.get(CONTENT_TYPE),0));
|
payload = Payloads.newByteArrayPayload(new byte[] {});
|
||||||
|
payload.getContentMetadata().setContentType(Iterables.get(headers.get(CONTENT_TYPE), 0));
|
||||||
}
|
}
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
request.setPayload(payload);
|
request.setPayload(payload);
|
||||||
|
@ -496,14 +497,14 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static URI replaceQuery(Provider<UriBuilder> uriBuilderProvider, URI in, String newQuery,
|
public static URI replaceQuery(Provider<UriBuilder> uriBuilderProvider, URI in, String newQuery,
|
||||||
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
||||||
UriBuilder builder = uriBuilderProvider.get().uri(in);
|
UriBuilder builder = uriBuilderProvider.get().uri(in);
|
||||||
builder.replaceQuery(makeQueryLine(parseQueryToMap(newQuery), sorter, skips));
|
builder.replaceQuery(makeQueryLine(parseQueryToMap(newQuery), sorter, skips));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMatrixParams(UriBuilder builder, Collection<Entry<String, String>> tokenValues, Method method,
|
private void addMatrixParams(UriBuilder builder, Collection<Entry<String, String>> tokenValues, Method method,
|
||||||
Object... args) {
|
Object... args) {
|
||||||
if (declaring.isAnnotationPresent(MatrixParams.class)) {
|
if (declaring.isAnnotationPresent(MatrixParams.class)) {
|
||||||
MatrixParams matrix = declaring.getAnnotation(MatrixParams.class);
|
MatrixParams matrix = declaring.getAnnotation(MatrixParams.class);
|
||||||
addMatrix(builder, matrix, tokenValues);
|
addMatrix(builder, matrix, tokenValues);
|
||||||
|
@ -520,7 +521,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Multimap<String, String> addFormParams(Collection<Entry<String, String>> tokenValues, Method method,
|
private Multimap<String, String> addFormParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||||
Object... args) {
|
Object... args) {
|
||||||
Multimap<String, String> formMap = LinkedListMultimap.create();
|
Multimap<String, String> formMap = LinkedListMultimap.create();
|
||||||
if (declaring.isAnnotationPresent(FormParams.class)) {
|
if (declaring.isAnnotationPresent(FormParams.class)) {
|
||||||
FormParams form = declaring.getAnnotation(FormParams.class);
|
FormParams form = declaring.getAnnotation(FormParams.class);
|
||||||
|
@ -539,7 +540,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Multimap<String, String> addQueryParams(Collection<Entry<String, String>> tokenValues, Method method,
|
private Multimap<String, String> addQueryParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||||
Object... args) {
|
Object... args) {
|
||||||
Multimap<String, String> queryMap = LinkedListMultimap.create();
|
Multimap<String, String> queryMap = LinkedListMultimap.create();
|
||||||
if (declaring.isAnnotationPresent(QueryParams.class)) {
|
if (declaring.isAnnotationPresent(QueryParams.class)) {
|
||||||
QueryParams query = declaring.getAnnotation(QueryParams.class);
|
QueryParams query = declaring.getAnnotation(QueryParams.class);
|
||||||
|
@ -558,7 +559,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addForm(Multimap<String, String> formParams, FormParams form,
|
private void addForm(Multimap<String, String> formParams, FormParams form,
|
||||||
Collection<Entry<String, String>> tokenValues) {
|
Collection<Entry<String, String>> tokenValues) {
|
||||||
for (int i = 0; i < form.keys().length; i++) {
|
for (int i = 0; i < form.keys().length; i++) {
|
||||||
if (form.values()[i].equals(FormParams.NULL)) {
|
if (form.values()[i].equals(FormParams.NULL)) {
|
||||||
formParams.removeAll(form.keys()[i]);
|
formParams.removeAll(form.keys()[i]);
|
||||||
|
@ -570,7 +571,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMapPayload(Map<String, String> postParams, MapPayloadParams mapDefaults,
|
private void addMapPayload(Map<String, String> postParams, MapPayloadParams mapDefaults,
|
||||||
Collection<Entry<String, String>> tokenValues) {
|
Collection<Entry<String, String>> tokenValues) {
|
||||||
for (int i = 0; i < mapDefaults.keys().length; i++) {
|
for (int i = 0; i < mapDefaults.keys().length; i++) {
|
||||||
if (mapDefaults.values()[i].equals(MapPayloadParams.NULL)) {
|
if (mapDefaults.values()[i].equals(MapPayloadParams.NULL)) {
|
||||||
postParams.put(mapDefaults.keys()[i], null);
|
postParams.put(mapDefaults.keys()[i], null);
|
||||||
|
@ -581,7 +582,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQuery(Multimap<String, String> queryParams, QueryParams query,
|
private void addQuery(Multimap<String, String> queryParams, QueryParams query,
|
||||||
Collection<Entry<String, String>> tokenValues) {
|
Collection<Entry<String, String>> tokenValues) {
|
||||||
for (int i = 0; i < query.keys().length; i++) {
|
for (int i = 0; i < query.keys().length; i++) {
|
||||||
if (query.values()[i].equals(QueryParams.NULL)) {
|
if (query.values()[i].equals(QueryParams.NULL)) {
|
||||||
queryParams.removeAll(query.keys()[i]);
|
queryParams.removeAll(query.keys()[i]);
|
||||||
|
@ -624,7 +625,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static URI getEndpointInParametersOrNull(Method method, final Object[] args, Injector injector) {
|
public static URI getEndpointInParametersOrNull(Method method, final Object[] args, Injector injector) {
|
||||||
Map<Integer, Set<Annotation>> map = indexWithAtLeastOneAnnotation(method,
|
Map<Integer, Set<Annotation>> map = indexWithAtLeastOneAnnotation(method,
|
||||||
methodToIndexOfParamToEndpointParamAnnotations);
|
methodToIndexOfParamToEndpointParamAnnotations);
|
||||||
if (map.size() >= 1 && args.length > 0) {
|
if (map.size() >= 1 && args.length > 0) {
|
||||||
EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0);
|
EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0);
|
||||||
Function<Object, URI> parser = injector.getInstance(firstAnnotation.parser());
|
Function<Object, URI> parser = injector.getInstance(firstAnnotation.parser());
|
||||||
|
@ -633,8 +634,8 @@ public class RestAnnotationProcessor<T> {
|
||||||
int index = map.keySet().iterator().next();
|
int index = map.keySet().iterator().next();
|
||||||
try {
|
try {
|
||||||
URI returnVal = parser.apply(args[index]);
|
URI returnVal = parser.apply(args[index]);
|
||||||
checkArgument(returnVal != null, String.format("endpoint for [%s] not configured for %s", args[index],
|
checkArgument(returnVal != null,
|
||||||
method));
|
String.format("endpoint for [%s] not configured for %s", args[index], method));
|
||||||
return returnVal;
|
return returnVal;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
throw new IllegalArgumentException(String.format("argument at index %d on method %s", index, method), e);
|
throw new IllegalArgumentException(String.format("argument at index %d on method %s", index, method), e);
|
||||||
|
@ -651,12 +652,12 @@ public class RestAnnotationProcessor<T> {
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
URI returnVal = parser.apply(argsToParse);
|
URI returnVal = parser.apply(argsToParse);
|
||||||
checkArgument(returnVal != null, String.format("endpoint for [%s] not configured for %s", argsToParse,
|
checkArgument(returnVal != null,
|
||||||
method));
|
String.format("endpoint for [%s] not configured for %s", argsToParse, method));
|
||||||
return returnVal;
|
return returnVal;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
throw new IllegalArgumentException(String.format("argument at indexes %s on method %s", map.keySet(),
|
throw new IllegalArgumentException(String.format("argument at indexes %s on method %s", map.keySet(),
|
||||||
method), e);
|
method), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -697,13 +698,13 @@ public class RestAnnotationProcessor<T> {
|
||||||
ResponseParser annotation = method.getAnnotation(ResponseParser.class);
|
ResponseParser annotation = method.getAnnotation(ResponseParser.class);
|
||||||
if (annotation == null) {
|
if (annotation == null) {
|
||||||
if (method.getReturnType().equals(void.class)
|
if (method.getReturnType().equals(void.class)
|
||||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
|
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
|
||||||
return Key.get(ReleasePayloadAndReturn.class);
|
return Key.get(ReleasePayloadAndReturn.class);
|
||||||
} else if (method.getReturnType().equals(boolean.class) || method.getReturnType().equals(Boolean.class)
|
} else if (method.getReturnType().equals(boolean.class) || method.getReturnType().equals(Boolean.class)
|
||||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureBooleanLiteral)) {
|
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureBooleanLiteral)) {
|
||||||
return Key.get(ReturnTrueIf2xx.class);
|
return Key.get(ReturnTrueIf2xx.class);
|
||||||
} else if (method.getReturnType().equals(InputStream.class)
|
} else if (method.getReturnType().equals(InputStream.class)
|
||||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureInputStreamLiteral)) {
|
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureInputStreamLiteral)) {
|
||||||
return Key.get(ReturnInputStream.class);
|
return Key.get(ReturnInputStream.class);
|
||||||
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
||||||
Type returnVal;
|
Type returnVal;
|
||||||
|
@ -724,10 +725,10 @@ public class RestAnnotationProcessor<T> {
|
||||||
parserType = Types.newParameterizedType(ParseJson.class, returnVal);
|
parserType = Types.newParameterizedType(ParseJson.class, returnVal);
|
||||||
return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
|
return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
|
||||||
} else if (method.getReturnType().equals(String.class)
|
} else if (method.getReturnType().equals(String.class)
|
||||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||||
return Key.get(ReturnStringIf2xx.class);
|
return Key.get(ReturnStringIf2xx.class);
|
||||||
} else if (method.getReturnType().equals(URI.class)
|
} else if (method.getReturnType().equals(URI.class)
|
||||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
|
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
|
||||||
return Key.get(ParseURIFromListOrLocationHeaderIf20x.class);
|
return Key.get(ParseURIFromListOrLocationHeaderIf20x.class);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("You must specify a ResponseParser annotation on: " + method.toString());
|
throw new IllegalStateException("You must specify a ResponseParser annotation on: " + method.toString());
|
||||||
|
@ -759,7 +760,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
} else {
|
} else {
|
||||||
if (postBinders[0] instanceof org.jclouds.rest.MapBinder) {
|
if (postBinders[0] instanceof org.jclouds.rest.MapBinder) {
|
||||||
throw new IllegalArgumentException("we currently do not support multiple varargs postBinders in: "
|
throw new IllegalArgumentException("we currently do not support multiple varargs postBinders in: "
|
||||||
+ method.getName());
|
+ method.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (arg instanceof org.jclouds.rest.MapBinder) {
|
} else if (arg instanceof org.jclouds.rest.MapBinder) {
|
||||||
|
@ -808,8 +809,8 @@ public class RestAnnotationProcessor<T> {
|
||||||
Set<String> requests = getHttpMethods(method);
|
Set<String> requests = getHttpMethods(method);
|
||||||
if (requests == null || requests.size() != 1) {
|
if (requests == null || requests.size() != 1) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"You must use at least one, but no more than one http method or pathparam annotation on: "
|
"You must use at least one, but no more than one http method or pathparam annotation on: "
|
||||||
+ method.toString());
|
+ method.toString());
|
||||||
}
|
}
|
||||||
return requests.iterator().next();
|
return requests.iterator().next();
|
||||||
}
|
}
|
||||||
|
@ -831,12 +832,12 @@ public class RestAnnotationProcessor<T> {
|
||||||
mapBinder.bindToRequest(request, mapParams);
|
mapBinder.bindToRequest(request, mapParams);
|
||||||
} else {
|
} else {
|
||||||
OUTER: for (Entry<Integer, Set<Annotation>> entry : filterValues(
|
OUTER: for (Entry<Integer, Set<Annotation>> entry : filterValues(
|
||||||
methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()),
|
methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()),
|
||||||
new Predicate<Set<Annotation>>() {
|
new Predicate<Set<Annotation>>() {
|
||||||
public boolean apply(Set<Annotation> input) {
|
public boolean apply(Set<Annotation> input) {
|
||||||
return input.size() >= 1;
|
return input.size() >= 1;
|
||||||
}
|
}
|
||||||
}).entrySet()) {
|
}).entrySet()) {
|
||||||
boolean shouldBreak = false;
|
boolean shouldBreak = false;
|
||||||
BinderParam payloadAnnotation = (BinderParam) entry.getValue().iterator().next();
|
BinderParam payloadAnnotation = (BinderParam) entry.getValue().iterator().next();
|
||||||
Binder binder = injector.getInstance(payloadAnnotation.value());
|
Binder binder = injector.getInstance(payloadAnnotation.value());
|
||||||
|
@ -872,24 +873,24 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Integer, Set<Annotation>> indexWithOnlyOneAnnotation(Method method, String description,
|
public static Map<Integer, Set<Annotation>> indexWithOnlyOneAnnotation(Method method, String description,
|
||||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine);
|
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine);
|
||||||
if (indexToPayloadAnnotation.size() > 1) {
|
if (indexToPayloadAnnotation.size() > 1) {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"You must not specify more than one %s annotation on: %s; found %s", description, method.toString(),
|
"You must not specify more than one %s annotation on: %s; found %s", description, method.toString(),
|
||||||
indexToPayloadAnnotation));
|
indexToPayloadAnnotation));
|
||||||
}
|
}
|
||||||
return indexToPayloadAnnotation;
|
return indexToPayloadAnnotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Integer, Set<Annotation>> indexWithAtLeastOneAnnotation(Method method,
|
private static Map<Integer, Set<Annotation>> indexWithAtLeastOneAnnotation(Method method,
|
||||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.get(method),
|
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.get(method),
|
||||||
new Predicate<Set<Annotation>>() {
|
new Predicate<Set<Annotation>>() {
|
||||||
public boolean apply(Set<Annotation> input) {
|
public boolean apply(Set<Annotation> input) {
|
||||||
return input.size() == 1;
|
return input.size() == 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return indexToPayloadAnnotation;
|
return indexToPayloadAnnotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -908,7 +909,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
} else {
|
} else {
|
||||||
if (options[0] instanceof HttpRequestOptions) {
|
if (options[0] instanceof HttpRequestOptions) {
|
||||||
throw new IllegalArgumentException("we currently do not support multiple varargs options in: "
|
throw new IllegalArgumentException("we currently do not support multiple varargs options in: "
|
||||||
+ method.getName());
|
+ method.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -920,7 +921,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Multimap<String, String> buildHeaders(Collection<Entry<String, String>> tokenValues, Method method,
|
public Multimap<String, String> buildHeaders(Collection<Entry<String, String>> tokenValues, Method method,
|
||||||
final Object... args) {
|
final Object... args) {
|
||||||
Multimap<String, String> headers = LinkedHashMultimap.create();
|
Multimap<String, String> headers = LinkedHashMultimap.create();
|
||||||
addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues);
|
addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues);
|
||||||
Map<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
|
Map<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
|
||||||
|
@ -967,7 +968,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHeaderIfAnnotationPresentOnMethod(Multimap<String, String> headers, Method method,
|
public void addHeaderIfAnnotationPresentOnMethod(Multimap<String, String> headers, Method method,
|
||||||
Collection<Entry<String, String>> tokenValues) {
|
Collection<Entry<String, String>> tokenValues) {
|
||||||
if (declaring.isAnnotationPresent(Headers.class)) {
|
if (declaring.isAnnotationPresent(Headers.class)) {
|
||||||
Headers header = declaring.getAnnotation(Headers.class);
|
Headers header = declaring.getAnnotation(Headers.class);
|
||||||
addHeader(headers, header, tokenValues);
|
addHeader(headers, header, tokenValues);
|
||||||
|
@ -979,7 +980,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHeader(Multimap<String, String> headers, Headers header,
|
private void addHeader(Multimap<String, String> headers, Headers header,
|
||||||
Collection<Entry<String, String>> tokenValues) {
|
Collection<Entry<String, String>> tokenValues) {
|
||||||
for (int i = 0; i < header.keys().length; i++) {
|
for (int i = 0; i < header.keys().length; i++) {
|
||||||
String value = header.values()[i];
|
String value = header.values()[i];
|
||||||
value = replaceTokens(value, tokenValues);
|
value = replaceTokens(value, tokenValues);
|
||||||
|
|
|
@ -104,6 +104,7 @@ import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.PayloadEnclosing;
|
import org.jclouds.io.PayloadEnclosing;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.BaseRestClientTest;
|
import org.jclouds.rest.BaseRestClientTest;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
@ -208,7 +209,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testDelegateAsync() throws SecurityException, NoSuchMethodException, InterruptedException,
|
public void testDelegateAsync() throws SecurityException, NoSuchMethodException, InterruptedException,
|
||||||
ExecutionException {
|
ExecutionException {
|
||||||
Injector child = injectorForClient();
|
Injector child = injectorForClient();
|
||||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||||
|
|
||||||
|
@ -223,7 +224,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
AsyncCaller caller = child.getInstance(AsyncCaller.class);
|
AsyncCaller caller = child.getInstance(AsyncCaller.class);
|
||||||
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/foo HTTP/1.1"), eq(function))).andReturn(
|
expect(mock.submit(requestLineEquals("GET http://localhost:9999/client/foo HTTP/1.1"), eq(function))).andReturn(
|
||||||
createNiceMock(ListenableFuture.class)).atLeastOnce();
|
createNiceMock(ListenableFuture.class)).atLeastOnce();
|
||||||
replay(mock);
|
replay(mock);
|
||||||
|
|
||||||
caller.getCallee().onePath("foo");
|
caller.getCallee().onePath("foo");
|
||||||
|
@ -252,7 +253,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDelegateWithOverridingEndpoint() throws SecurityException, NoSuchMethodException,
|
public void testDelegateWithOverridingEndpoint() throws SecurityException, NoSuchMethodException,
|
||||||
InterruptedException, ExecutionException {
|
InterruptedException, ExecutionException {
|
||||||
Injector child = injectorForClient();
|
Injector child = injectorForClient();
|
||||||
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
TransformingHttpCommandExecutorService mock = child.getInstance(TransformingHttpCommandExecutorService.class);
|
||||||
|
|
||||||
|
@ -267,7 +268,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
Caller caller = child.getInstance(Caller.class);
|
Caller caller = child.getInstance(Caller.class);
|
||||||
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/foo HTTP/1.1"), eq(function))).andReturn(
|
expect(mock.submit(requestLineEquals("GET http://localhost:1111/client/foo HTTP/1.1"), eq(function))).andReturn(
|
||||||
Futures.<Void> immediateFuture(null)).atLeastOnce();
|
Futures.<Void> immediateFuture(null)).atLeastOnce();
|
||||||
replay(mock);
|
replay(mock);
|
||||||
|
|
||||||
caller.getCallee().onePath("foo");
|
caller.getCallee().onePath("foo");
|
||||||
|
@ -278,9 +279,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
private Injector injectorForClient() {
|
private Injector injectorForClient() {
|
||||||
|
|
||||||
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
RestContextSpec<Caller, AsyncCaller> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo",
|
||||||
Caller.class, AsyncCaller.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
null, Caller.class, AsyncCaller.class,
|
||||||
new CallerCalleeModule()));
|
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new CallerCalleeModule()));
|
||||||
|
|
||||||
return createContextBuilder(contextSpec).buildInjector();
|
return createContextBuilder(contextSpec).buildInjector();
|
||||||
|
|
||||||
|
@ -295,7 +296,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Target( { ElementType.METHOD })
|
@Target({ ElementType.METHOD })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@javax.ws.rs.HttpMethod("FOO")
|
@javax.ws.rs.HttpMethod("FOO")
|
||||||
public @interface FOO {
|
public @interface FOO {
|
||||||
|
@ -330,10 +331,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public void testUnEncodeQuery() {
|
public void testUnEncodeQuery() {
|
||||||
URI expects = URI
|
URI expects = URI
|
||||||
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef:sushi&metadata=foo:bar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef:sushi&metadata=foo:bar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
||||||
|
|
||||||
URI start = URI
|
URI start = URI
|
||||||
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
|
||||||
URI value = RestAnnotationProcessor.replaceQuery(uriBuilderProvider, start, start.getQuery(), null, '/', ':');
|
URI value = RestAnnotationProcessor.replaceQuery(uriBuilderProvider, start, start.getQuery(), null, '/', ':');
|
||||||
assertEquals(value, expects);
|
assertEquals(value, expects);
|
||||||
}
|
}
|
||||||
|
@ -373,21 +374,34 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@POST
|
@POST
|
||||||
@Path("")
|
@Path("")
|
||||||
public void post(HttpRequestOptions options);
|
public void post(HttpRequestOptions options);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("")
|
@Path("")
|
||||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
public void post();
|
public void post();
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("")
|
||||||
|
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
public void post(Payload payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
public void testHttpRequestOptionsNoPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestPayloadParamVarargs.class.getMethod("post");
|
Method method = TestPayloadParamVarargs.class.getMethod("post");
|
||||||
HttpRequest request = factory(TestQuery.class).createRequest(method);
|
HttpRequest request = factory(TestQuery.class).createRequest(method);
|
||||||
assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "", "application/octet-stream", false);
|
assertPayloadEquals(request, "", "application/octet-stream", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = TestPayloadParamVarargs.class.getMethod("post", Payload.class);
|
||||||
|
HttpRequest request = factory(TestQuery.class).createRequest(method, Payloads.newStringPayload("foo"));
|
||||||
|
assertRequestLineEquals(request, "POST http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
|
assertPayloadEquals(request, "foo", "application/octet-stream", false);
|
||||||
|
}
|
||||||
|
|
||||||
public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException {
|
public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class);
|
Method method = TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class);
|
||||||
verifyTestPostOptions(method);
|
verifyTestPostOptions(method);
|
||||||
|
@ -395,7 +409,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
public void testPayloadParamVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
public void testPayloadParamVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0)
|
Method method = TestPayloadParamVarargs.class.getMethod("varargs", Array.newInstance(HttpRequestOptions.class, 0)
|
||||||
.getClass());
|
.getClass());
|
||||||
verifyTestPostOptions(method);
|
verifyTestPostOptions(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +506,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException {
|
public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class);
|
Method method = TestOverriddenEndpoint.class.getMethod("foo", URI.class);
|
||||||
HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method,
|
HttpRequest request = factory(TestOverriddenEndpoint.class).createRequest(method,
|
||||||
new Object[] { URI.create("http://wowsa:8001") });
|
new Object[] { URI.create("http://wowsa:8001") });
|
||||||
assertEquals(request.getEndpoint().getHost(), "wowsa");
|
assertEquals(request.getEndpoint().getHost(), "wowsa");
|
||||||
assertEquals(request.getEndpoint().getPort(), 8001);
|
assertEquals(request.getEndpoint().getPort(), 8001);
|
||||||
assertEquals(request.getEndpoint().getPath(), "");
|
assertEquals(request.getEndpoint().getPath(), "");
|
||||||
|
@ -600,45 +614,45 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@POST
|
@POST
|
||||||
@Path("")
|
@Path("")
|
||||||
void withParamFileBinaryPart(@FormParam("name") String name,
|
void withParamFileBinaryPart(@FormParam("name") String name,
|
||||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM) File path);
|
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM) File path);
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("")
|
@Path("")
|
||||||
void withParamByteArrayBinaryPart(
|
void withParamByteArrayBinaryPart(
|
||||||
@FormParam("name") String name,
|
@FormParam("name") String name,
|
||||||
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
@PartParam(name = "file", contentType = MediaType.APPLICATION_OCTET_STREAM, filename = "{name}.tar.gz") byte[] content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestMultipartForm.class.getMethod("withStringPart", String.class);
|
Method method = TestMultipartForm.class.getMethod("withStringPart", String.class);
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"foobledata");
|
"foobledata");
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
"Content-Disposition: form-data; name=\"fooble\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"foobledata\r\n" + //
|
"foobledata\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class);
|
Method method = TestMultipartForm.class.getMethod("withParamStringPart", String.class, String.class);
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", "foobledata");
|
"name", "foobledata");
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"foobledata\r\n" + //
|
"foobledata\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
@ -648,38 +662,38 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
|
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", file);
|
"name", file);
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"foobledata\r\n" + //
|
"foobledata\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class);
|
Method method = TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart", String.class, byte[].class);
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", "goo".getBytes());
|
"name", "goo".getBytes());
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"; filename=\"name.tar.gz\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"; filename=\"name.tar.gz\"\r\n" + //
|
||||||
"Content-Type: application/octet-stream\r\n" + //
|
"Content-Type: application/octet-stream\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"goo\r\n" + //
|
"goo\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
};
|
};
|
||||||
|
|
||||||
public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException {
|
public void testMultipartWithParamFileBinaryPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
@ -689,20 +703,20 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
|
|
||||||
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
GeneratedHttpRequest<TestMultipartForm> httpRequest = factory(TestMultipartForm.class).createRequest(method,
|
||||||
"name", file);
|
"name", file);
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest,//
|
assertPayloadEquals(httpRequest,//
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
"Content-Disposition: form-data; name=\"name\"\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"name\r\n" + // /
|
"name\r\n" + // /
|
||||||
"----JCLOUDS--\r\n" + //
|
"----JCLOUDS--\r\n" + //
|
||||||
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
"Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"\r\n" + //
|
||||||
"Content-Type: application/octet-stream\r\n" + //
|
"Content-Type: application/octet-stream\r\n" + //
|
||||||
"\r\n" + //
|
"\r\n" + //
|
||||||
"'(2\r\n" + //
|
"'(2\r\n" + //
|
||||||
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
"----JCLOUDS----\r\n", "multipart/form-data; boundary=--JCLOUDS--", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TestPut {
|
public interface TestPut {
|
||||||
|
@ -761,7 +775,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
ListenableFuture<? extends Set<String>> testUnwrap4();
|
ListenableFuture<? extends Set<String>> testUnwrap4();
|
||||||
|
|
||||||
@Target( { ElementType.METHOD })
|
@Target({ ElementType.METHOD })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@HttpMethod("ROWDY")
|
@HttpMethod("ROWDY")
|
||||||
public @interface ROWDY {
|
public @interface ROWDY {
|
||||||
|
@ -816,7 +830,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Wrapper> parser = (Function<HttpResponse, Wrapper>) RestAnnotationProcessor
|
Function<HttpResponse, Wrapper> parser = (Function<HttpResponse, Wrapper>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))).foo, "bar");
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))).foo, "bar");
|
||||||
|
|
||||||
|
@ -831,10 +845,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||||
"foo", "bar"));
|
ImmutableMap.of("foo", "bar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,10 +861,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||||
"foo", "bar"));
|
ImmutableMap.of("foo", "bar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -863,10 +877,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), ImmutableMap.of(
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))),
|
||||||
"foo", "bar"));
|
ImmutableMap.of("foo", "bar"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,7 +893,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
||||||
|
|
||||||
|
@ -894,7 +908,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{ foo:\"bar\"}"))), "bar");
|
||||||
|
|
||||||
|
@ -909,10 +923,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))),
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))),
|
||||||
ImmutableSet.of("0.7.0", "0.7.1"));
|
ImmutableSet.of("0.7.0", "0.7.1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -924,10 +938,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
// now test that it works!
|
// now test that it works!
|
||||||
|
|
||||||
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
Function<HttpResponse, Map<String, String>> parser = (Function<HttpResponse, Map<String, String>>) RestAnnotationProcessor
|
||||||
.createResponseParser(parserFactory, injector, method, request);
|
.createResponseParser(parserFactory, injector, method, request);
|
||||||
|
|
||||||
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))),
|
assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))),
|
||||||
ImmutableSet.of("0.7.0", "0.7.1"));
|
ImmutableSet.of("0.7.0", "0.7.1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestRequestFilter1 implements HttpRequestFilter {
|
static class TestRequestFilter1 implements HttpRequestFilter {
|
||||||
|
@ -1014,7 +1028,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
|
||||||
HttpRequest request = factory(TestConstantPathParam.class).createRequest(method,
|
HttpRequest request = factory(TestConstantPathParam.class).createRequest(method,
|
||||||
new Object[] { "1", "localhost" });
|
new Object[] { "1", "localhost" });
|
||||||
assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1");
|
assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, null, null, false);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
@ -1151,7 +1165,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class);
|
Method oneHeader = TestHeader.class.getMethod("twoHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||||
.getHeaders();
|
.getHeaders();
|
||||||
assertEquals(headers.size(), 2);
|
assertEquals(headers.size(), 2);
|
||||||
assertEquals(headers.get("slash"), Collections.singletonList("/robot"));
|
assertEquals(headers.get("slash"), Collections.singletonList("/robot"));
|
||||||
assertEquals(headers.get("hyphen"), Collections.singletonList("-robot"));
|
assertEquals(headers.get("hyphen"), Collections.singletonList("-robot"));
|
||||||
|
@ -1169,7 +1183,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class);
|
Method oneHeader = TestClassHeader.class.getMethod("oneHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestClassHeader.class).createRequest(oneHeader,
|
Multimap<String, String> headers = factory(TestClassHeader.class).createRequest(oneHeader,
|
||||||
new Object[] { "robot" }).getHeaders();
|
new Object[] { "robot" }).getHeaders();
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
||||||
}
|
}
|
||||||
|
@ -1178,7 +1192,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class);
|
Method oneHeader = TestHeader.class.getMethod("oneHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
Multimap<String, String> headers = factory(TestHeader.class).createRequest(oneHeader, new Object[] { "robot" })
|
||||||
.getHeaders();
|
.getHeaders();
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot"));
|
||||||
}
|
}
|
||||||
|
@ -1187,17 +1201,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class);
|
Method twoHeaders = TestHeader.class.getMethod("twoHeaders", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeaders,
|
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeaders,
|
||||||
new Object[] { "robot", "eggs" }).getHeaders();
|
new Object[] { "robot", "eggs" }).getHeaders();
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot/eggs"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/robot/eggs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class);
|
Method twoHeadersOutOfOrder = TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeadersOutOfOrder,
|
Multimap<String, String> headers = factory(TestHeader.class).createRequest(twoHeadersOutOfOrder,
|
||||||
new Object[] { "robot", "eggs" }).getHeaders();
|
new Object[] { "robot", "eggs" }).getHeaders();
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
|
||||||
}
|
}
|
||||||
|
@ -1211,8 +1225,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testQueryInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
Method oneQuery = TestQueryReplace.class.getMethod("queryInOptions", String.class, TestReplaceQueryOptions.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery,
|
String query = factory(TestQueryReplace.class)
|
||||||
new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
.createRequest(oneQuery, new Object[] { "robot", new TestReplaceQueryOptions() }).getEndpoint().getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1220,13 +1234,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@POST
|
@POST
|
||||||
@Path("/objects/{id}/action/{action}")
|
@Path("/objects/{id}/action/{action}")
|
||||||
ListenableFuture<String> action(@PathParam("id") String id, @PathParam("action") String action,
|
ListenableFuture<String> action(@PathParam("id") String id, @PathParam("action") String action,
|
||||||
@BinderParam(BindMapToMatrixParams.class) Map<String, String> options);
|
@BinderParam(BindMapToMatrixParams.class) Map<String, String> options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTestMapMatrixParams() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testTestMapMatrixParams() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class);
|
Method method = TestMapMatrixParams.class.getMethod("action", String.class, String.class, Map.class);
|
||||||
HttpRequest request = factory(TestMapMatrixParams.class).createRequest(method,
|
HttpRequest request = factory(TestMapMatrixParams.class).createRequest(method,
|
||||||
new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") });
|
new Object[] { "robot", "kill", ImmutableMap.of("death", "slow") });
|
||||||
assertRequestLineEquals(request, "POST http://localhost:9999/objects/robot/action/kill;death=slow HTTP/1.1");
|
assertRequestLineEquals(request, "POST http://localhost:9999/objects/robot/action/kill;death=slow HTTP/1.1");
|
||||||
assertEquals(request.getHeaders().size(), 0);
|
assertEquals(request.getHeaders().size(), 0);
|
||||||
}
|
}
|
||||||
|
@ -1268,7 +1282,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class);
|
Method oneQuery = TestQueryReplace.class.getMethod("twoQuery", String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||||
.getQuery();
|
.getQuery();
|
||||||
assertEquals(query, "slash=/robot&hyphen=-robot");
|
assertEquals(query, "slash=/robot&hyphen=-robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1284,7 +1298,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class);
|
Method oneQuery = TestClassQuery.class.getMethod("oneQuery", String.class);
|
||||||
String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
String query = factory(TestClassQuery.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||||
.getQuery();
|
.getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1292,7 +1306,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class);
|
Method oneQuery = TestQueryReplace.class.getMethod("oneQuery", String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
String query = factory(TestQueryReplace.class).createRequest(oneQuery, new Object[] { "robot" }).getEndpoint()
|
||||||
.getQuery();
|
.getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot");
|
assertEquals(query, "x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,16 +1314,16 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class);
|
Method twoQuerys = TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" })
|
String query = factory(TestQueryReplace.class).createRequest(twoQuerys, new Object[] { "robot", "eggs" })
|
||||||
.getEndpoint().getQuery();
|
.getEndpoint().getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/robot/eggs");
|
assertEquals(query, "x-amz-copy-source=/robot/eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
Method twoQuerysOutOfOrder = TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class, String.class);
|
||||||
String query = factory(TestQueryReplace.class).createRequest(twoQuerysOutOfOrder,
|
String query = factory(TestQueryReplace.class)
|
||||||
new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
.createRequest(twoQuerysOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getQuery();
|
||||||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1322,9 +1336,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
||||||
TestReplaceMatrixOptions.class);
|
TestReplaceMatrixOptions.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix,
|
String path = factory(TestMatrixReplace.class)
|
||||||
new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
.createRequest(oneMatrix, new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1365,7 +1379,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||||
.getPath();
|
.getPath();
|
||||||
assertEquals(path, "/;slash=/robot;hyphen=-robot");
|
assertEquals(path, "/;slash=/robot;hyphen=-robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1382,7 +1396,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
||||||
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||||
.getPath();
|
.getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1390,7 +1404,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||||
.getPath();
|
.getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,17 +1412,17 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
||||||
.getEndpoint().getPath();
|
.getEndpoint().getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||||
String.class);
|
String.class);
|
||||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixsOutOfOrder,
|
String path = factory(TestMatrixReplace.class)
|
||||||
new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1460,7 +1474,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||||
HttpRequest request = factory(TestQuery.class).createRequest(method,
|
HttpRequest request = factory(TestQuery.class).createRequest(method,
|
||||||
new PayloadEnclosingImpl(newStringPayload("whoops")));
|
new PayloadEnclosingImpl(newStringPayload("whoops")));
|
||||||
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
assertRequestLineEquals(request, "PUT http://localhost:9999?x-ms-version=2009-07-17 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
assertNonPayloadHeadersEqual(request, "");
|
||||||
assertPayloadEquals(request, "whoops", "application/unknown", false);
|
assertPayloadEquals(request, "whoops", "application/unknown", false);
|
||||||
|
@ -1478,7 +1492,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
public void testPutInputStreamPayloadEnclosingGenerateMD5() throws SecurityException, NoSuchMethodException,
|
||||||
IOException {
|
IOException {
|
||||||
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
Method method = TestTransformers.class.getMethod("put", PayloadEnclosing.class);
|
||||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(toInputStream("whoops")));
|
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newInputStreamPayload(toInputStream("whoops")));
|
||||||
|
|
||||||
|
@ -1537,7 +1551,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
|
public void testPutPayloadWithGeneratedMD5AndNoContentType() throws SecurityException, NoSuchMethodException,
|
||||||
IOException {
|
IOException {
|
||||||
Payload payload = newStringPayload("whoops");
|
Payload payload = newStringPayload("whoops");
|
||||||
calculateMD5(payload, crypto.md5());
|
calculateMD5(payload, crypto.md5());
|
||||||
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
||||||
|
@ -1558,7 +1572,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPutInputStreamPayloadWithMD5() throws NoSuchAlgorithmException, IOException, SecurityException,
|
public void testPutInputStreamPayloadWithMD5() throws NoSuchAlgorithmException, IOException, SecurityException,
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
Payload payload = newStringPayload("whoops");
|
Payload payload = newStringPayload("whoops");
|
||||||
calculateMD5(payload, crypto.md5());
|
calculateMD5(payload, crypto.md5());
|
||||||
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
Method method = TestTransformers.class.getMethod("put", Payload.class);
|
||||||
|
@ -1582,9 +1596,9 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> Class<? extends Function<HttpResponse, ?>> unwrap(RestAnnotationProcessor<T> processor,
|
public static <T> Class<? extends Function<HttpResponse, ?>> unwrap(RestAnnotationProcessor<T> processor,
|
||||||
Method method) {
|
Method method) {
|
||||||
return (Class<? extends Function<HttpResponse, ?>>) RestAnnotationProcessor.getParserOrThrowException(method)
|
return (Class<? extends Function<HttpResponse, ?>>) RestAnnotationProcessor.getParserOrThrowException(method)
|
||||||
.getTypeLiteral().getRawType();
|
.getTypeLiteral().getRawType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testURI() throws SecurityException, NoSuchMethodException {
|
public void testURI() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -1620,8 +1634,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException {
|
public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException {
|
||||||
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
|
||||||
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
|
||||||
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>("GET", URI
|
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>("GET",
|
||||||
.create("http://localhost"), TestTransformers.class, method);
|
URI.create("http://localhost"), TestTransformers.class, method);
|
||||||
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
|
||||||
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
||||||
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
||||||
|
@ -1662,7 +1676,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
ListenableFuture<String> put(@PathParam("id") @ParamParser(FirstCharacter.class) String id,
|
ListenableFuture<String> put(@PathParam("id") @ParamParser(FirstCharacter.class) String id,
|
||||||
@BinderParam(BindToStringPayload.class) String payload);
|
@BinderParam(BindToStringPayload.class) String payload);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
|
@ -1674,7 +1688,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@Headers(keys = "foo", values = "--{id}--")
|
@Headers(keys = "foo", values = "--{id}--")
|
||||||
@ResponseParser(ReturnTrueIf2xx.class)
|
@ResponseParser(ReturnTrueIf2xx.class)
|
||||||
ListenableFuture<String> putHeader(@PathParam("id") String id,
|
ListenableFuture<String> putHeader(@PathParam("id") String id,
|
||||||
@BinderParam(BindToStringPayload.class) String payload);
|
@BinderParam(BindToStringPayload.class) String payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
public void testCreateGetVarArgOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -1688,8 +1702,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(request.getHeaders().size(), 2);
|
assertEquals(request.getHeaders().size(), 2);
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||||
.rfc822DateFormat(date)));
|
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
public void testCreateGetOptionsThatProducesHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -1702,8 +1716,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(request.getHeaders().size(), 2);
|
assertEquals(request.getHeaders().size(), 2);
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
assertEquals(request.getHeaders().get(HttpHeaders.HOST), Collections.singletonList("localhost"));
|
||||||
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE), Collections.singletonList(dateService
|
assertEquals(request.getHeaders().get(HttpHeaders.IF_MODIFIED_SINCE),
|
||||||
.rfc822DateFormat(date)));
|
Collections.singletonList(dateService.rfc822DateFormat(date)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PrefixOptions extends BaseHttpRequestOptions {
|
public class PrefixOptions extends BaseHttpRequestOptions {
|
||||||
|
@ -1766,7 +1780,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@Test(dataProvider = "strings")
|
@Test(dataProvider = "strings")
|
||||||
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
Method method = TestRequest.class.getMethod("get", String.class, String.class);
|
||||||
HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { key, "localhost" });
|
HttpRequest request = factory(TestRequest.class).createRequest(method, new Object[] { key, "localhost" });
|
||||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||||
|
@ -1809,7 +1823,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
|
||||||
HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(method,
|
HttpRequest request = factory(TestVirtualHostMethod.class).createRequest(method,
|
||||||
new Object[] { "1", "localhost" });
|
new Object[] { "1", "localhost" });
|
||||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||||
|
@ -1874,7 +1888,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOneHeader() throws SecurityException, NoSuchMethodException {
|
public void testOneHeader() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("oneHeader", String.class);
|
Method method = TestHeaders.class.getMethod("oneHeader", String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||||
ImmutableMultimap.<String, String> of().entries(), method, "robot");
|
ImmutableMultimap.<String, String> of().entries(), method, "robot");
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("header"), Collections.singletonList("robot"));
|
assertEquals(headers.get("header"), Collections.singletonList("robot"));
|
||||||
}
|
}
|
||||||
|
@ -1883,7 +1897,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOneIntHeader() throws SecurityException, NoSuchMethodException {
|
public void testOneIntHeader() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("oneIntHeader", int.class);
|
Method method = TestHeaders.class.getMethod("oneIntHeader", int.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||||
ImmutableMultimap.<String, String> of().entries(), method, 1);
|
ImmutableMultimap.<String, String> of().entries(), method, 1);
|
||||||
assertEquals(headers.size(), 1);
|
assertEquals(headers.size(), 1);
|
||||||
assertEquals(headers.get("header"), Collections.singletonList("1"));
|
assertEquals(headers.get("header"), Collections.singletonList("1"));
|
||||||
}
|
}
|
||||||
|
@ -1892,7 +1906,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException {
|
public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class);
|
Method method = TestHeaders.class.getMethod("twoDifferentHeaders", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||||
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
||||||
assertEquals(headers.size(), 2);
|
assertEquals(headers.size(), 2);
|
||||||
assertEquals(headers.get("header1"), Collections.singletonList("robot"));
|
assertEquals(headers.get("header1"), Collections.singletonList("robot"));
|
||||||
assertEquals(headers.get("header2"), Collections.singletonList("egg"));
|
assertEquals(headers.get("header2"), Collections.singletonList("egg"));
|
||||||
|
@ -1902,7 +1916,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException {
|
public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class);
|
Method method = TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class);
|
||||||
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
Multimap<String, String> headers = factory(TestHeaders.class).buildHeaders(
|
||||||
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
ImmutableMultimap.<String, String> of().entries(), method, "robot", "egg");
|
||||||
assertEquals(headers.size(), 2);
|
assertEquals(headers.size(), 2);
|
||||||
Collection<String> values = headers.get("header");
|
Collection<String> values = headers.get("header");
|
||||||
assert values.contains("robot");
|
assert values.contains("robot");
|
||||||
|
@ -1925,7 +1939,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
void twoEndpointParams(@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam1,
|
void twoEndpointParams(@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam1,
|
||||||
@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam2);
|
@EndpointParam(parser = ConvertTwoToURI.class) String EndpointParam2);
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class ConvertTwoToURI implements Function<Object, URI> {
|
public static class ConvertTwoToURI implements Function<Object, URI> {
|
||||||
|
@ -1945,7 +1959,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testOneEndpointParam() throws SecurityException, NoSuchMethodException {
|
public void testOneEndpointParam() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEndpointParams.class.getMethod("oneEndpointParam", String.class);
|
Method method = TestEndpointParams.class.getMethod("oneEndpointParam", String.class);
|
||||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, new Object[] { "robot" },
|
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method, new Object[] { "robot" },
|
||||||
injector);
|
injector);
|
||||||
assertEquals(uri, URI.create("robot"));
|
assertEquals(uri, URI.create("robot"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1955,7 +1969,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException {
|
public void testTwoDifferentEndpointParams() throws SecurityException, NoSuchMethodException {
|
||||||
Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class);
|
Method method = TestEndpointParams.class.getMethod("twoEndpointParams", String.class, String.class);
|
||||||
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method,
|
URI uri = factory(TestEndpointParams.class).getEndpointInParametersOrNull(method,
|
||||||
new Object[] { "robot", "egg" }, injector);
|
new Object[] { "robot", "egg" }, injector);
|
||||||
assertEquals(uri, URI.create("robot/egg"));
|
assertEquals(uri, URI.create("robot/egg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1967,12 +1981,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{foo}")
|
@Path("/{foo}")
|
||||||
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
|
public ListenableFuture<Void> putWithPath(@PathParam("foo") String path,
|
||||||
@BinderParam(BindToStringPayload.class) String content);
|
@BinderParam(BindToStringPayload.class) String content);
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("")
|
@Path("")
|
||||||
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
|
public void twoEntities(@BinderParam(BindToStringPayload.class) String payload1,
|
||||||
@BinderParam(BindToStringPayload.class) String payload2);
|
@BinderParam(BindToStringPayload.class) String payload2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2070,23 +2084,23 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
|
||||||
Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class);
|
Method twoForms = TestFormReplace.class.getMethod("twoForms", String.class, String.class);
|
||||||
Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload()
|
Object form = factory(TestFormReplace.class).createRequest(twoForms, "robot", "eggs").getPayload()
|
||||||
.getRawContent();
|
.getRawContent();
|
||||||
assertEquals(form, "x-amz-copy-source=/robot/eggs");
|
assertEquals(form, "x-amz-copy-source=/robot/eggs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException,
|
||||||
UnsupportedEncodingException {
|
UnsupportedEncodingException {
|
||||||
Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class);
|
Method twoFormsOutOfOrder = TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class, String.class);
|
||||||
Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload()
|
Object form = factory(TestFormReplace.class).createRequest(twoFormsOutOfOrder, "robot", "eggs").getPayload()
|
||||||
.getRawContent();
|
.getRawContent();
|
||||||
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <T> RestAnnotationProcessor<T> factory(Class<T> clazz) {
|
private <T> RestAnnotationProcessor<T> factory(Class<T> clazz) {
|
||||||
return ((RestAnnotationProcessor<T>) injector.getInstance(Key.get(newParameterizedType(
|
return ((RestAnnotationProcessor<T>) injector.getInstance(Key.get(newParameterizedType(
|
||||||
RestAnnotationProcessor.class, clazz))));
|
RestAnnotationProcessor.class, clazz))));
|
||||||
}
|
}
|
||||||
|
|
||||||
DateService dateService = new SimpleDateFormatDateService();
|
DateService dateService = new SimpleDateFormatDateService();
|
||||||
|
@ -2094,16 +2108,15 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "userfoo", null,
|
||||||
String.class, Integer.class, ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(),
|
String.class, Integer.class,
|
||||||
new AbstractModule() {
|
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
|
bind(URI.class).annotatedWith(Localhost2.class).toInstance(URI.create("http://localhost:1111"));
|
||||||
URI.create("http://localhost:1111"));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
injector = createContextBuilder(contextSpec).buildInjector();
|
injector = createContextBuilder(contextSpec).buildInjector();
|
||||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||||
|
|
|
@ -300,7 +300,7 @@ public class ElasticStackAsyncClientTest extends RestClientTest<ElasticStackAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/write HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/write HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||||
assertPayloadEquals(httpRequest, "", MediaType.APPLICATION_OCTET_STREAM, false);
|
assertPayloadEquals(httpRequest, "foo", MediaType.APPLICATION_OCTET_STREAM, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -316,7 +316,7 @@ public class ElasticStackAsyncClientTest extends RestClientTest<ElasticStackAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/write/2048 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST https://api.elasticstack.com/drives/100/write/2048 HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||||
assertPayloadEquals(httpRequest, "", MediaType.APPLICATION_OCTET_STREAM, false);
|
assertPayloadEquals(httpRequest, "foo", MediaType.APPLICATION_OCTET_STREAM, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
|
|
@ -76,7 +76,8 @@ public class ElasticStackClientLiveTest extends
|
||||||
|
|
||||||
// TODO block until complete
|
// TODO block until complete
|
||||||
System.err.println("state " + client.getDriveInfo(info2.getUuid()));
|
System.err.println("state " + client.getDriveInfo(info2.getUuid()));
|
||||||
assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid()).getInput()), "foo");
|
assertEquals(Utils.toStringAndClose(client.readDrive(info2.getUuid(),
|
||||||
|
ReadDriveOptions.Builder.offset(0).size(3)).getInput()), "foo");
|
||||||
} finally {
|
} finally {
|
||||||
client.destroyDrive(info2.getUuid());
|
client.destroyDrive(info2.getUuid());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue