mirror of https://github.com/apache/jclouds.git
Merge pull request #1196 from jclouds/guava-14.0-rc2
update to guava 14.0-rc2
This commit is contained in:
commit
0ccf0aa4f4
|
@ -45,7 +45,7 @@ import com.google.common.reflect.Invokable;
|
|||
*/
|
||||
@Singleton
|
||||
public class AtmosBlobRequestSigner implements BlobRequestSigner {
|
||||
private final RestAnnotationProcessor<AtmosAsyncClient> processor;
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final BlobToObject blobToObject;
|
||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner {
|
|||
private final Invokable<?, ?> createMethod;
|
||||
|
||||
@Inject
|
||||
public AtmosBlobRequestSigner(RestAnnotationProcessor<AtmosAsyncClient> processor, BlobToObject blobToObject,
|
||||
public AtmosBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject,
|
||||
BlobToHttpGetOptions blob2ObjectGetOptions) throws SecurityException, NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
|
|
|
@ -65,7 +65,7 @@ public class BindCloneDriveOptionsToPlainTextStringTest {
|
|||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.s3.options.PutObjectOptions;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -45,7 +46,7 @@ import com.google.common.reflect.Invokable;
|
|||
*/
|
||||
@Singleton
|
||||
public class S3BlobRequestSigner<T extends S3AsyncClient> implements BlobRequestSigner {
|
||||
private final RestAnnotationProcessor<T> processor;
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final BlobToObject blobToObject;
|
||||
private final BlobToHttpGetOptions blob2HttpGetOptions;
|
||||
|
||||
|
@ -54,16 +55,17 @@ public class S3BlobRequestSigner<T extends S3AsyncClient> implements BlobRequest
|
|||
private final Invokable<?, ?> createMethod;
|
||||
|
||||
@Inject
|
||||
public S3BlobRequestSigner(RestAnnotationProcessor<T> processor, BlobToObject blobToObject,
|
||||
BlobToHttpGetOptions blob2HttpGetOptions, Class<T> interfaceType) throws SecurityException,
|
||||
public S3BlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject,
|
||||
BlobToHttpGetOptions blob2HttpGetOptions, Class<T> interfaceClass) throws SecurityException,
|
||||
NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
|
||||
this.getMethod = Invokable.from(interfaceType.getMethod("getObject", String.class, String.class,
|
||||
TypeToken<T> interfaceType = TypeToken.of(interfaceClass);
|
||||
this.getMethod = interfaceType.method(interfaceClass.getMethod("getObject", String.class, String.class,
|
||||
GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(interfaceType.getMethod("deleteObject", String.class, String.class));
|
||||
this.createMethod = Invokable.from(interfaceType.getMethod("putObject", String.class, S3Object.class,
|
||||
this.deleteMethod = interfaceType.method(interfaceClass.getMethod("deleteObject", String.class, String.class));
|
||||
this.createMethod = interfaceType.method(interfaceClass.getMethod("putObject", String.class, S3Object.class,
|
||||
PutObjectOptions[].class));
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,11 @@ import com.google.common.reflect.Invokable;
|
|||
@Test(testName = "FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest")
|
||||
public class FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest {
|
||||
|
||||
GeneratedHttpRequest<S3Client> putBucket;
|
||||
GeneratedHttpRequest putBucket;
|
||||
|
||||
@BeforeClass
|
||||
void setUp() throws SecurityException, NoSuchMethodException {
|
||||
putBucket = GeneratedHttpRequest.builder(S3Client.class)
|
||||
putBucket = GeneratedHttpRequest.builder()
|
||||
.method("PUT")
|
||||
.endpoint("https://adriancole-blobstore113.s3.amazonaws.com/")
|
||||
.invocation(
|
||||
|
|
|
@ -55,7 +55,9 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.ByteProcessor;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -63,7 +65,7 @@ import com.google.inject.Provider;
|
|||
@Singleton
|
||||
public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRequestSigner {
|
||||
|
||||
private final RestAnnotationProcessor<T> processor;
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final Crypto crypto;
|
||||
|
||||
private final Provider<Long> unixEpochTimestampProvider;
|
||||
|
@ -85,8 +87,8 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
@Inject
|
||||
protected SwiftBlobSigner(BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto,
|
||||
@TimeStamp Provider<Long> unixEpochTimestampProvider,
|
||||
@TemporaryUrlKey Supplier<String> temporaryUrlKeySupplier, RestAnnotationProcessor<T> processor,
|
||||
Class<T> interfaceType) throws SecurityException, NoSuchMethodException {
|
||||
@TemporaryUrlKey Supplier<String> temporaryUrlKeySupplier, RestAnnotationProcessor processor,
|
||||
TypeLiteral<T> interfaceType) throws SecurityException, NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.crypto = checkNotNull(crypto, "crypto");
|
||||
|
||||
|
@ -96,10 +98,13 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
|
||||
|
||||
this.getMethod = Invokable.from(interfaceType.getMethod("getObject", String.class, String.class,
|
||||
TypeToken<?> owner = TypeToken.of(interfaceType.getType());
|
||||
this.getMethod = owner.method(interfaceType.getRawType().getMethod("getObject", String.class, String.class,
|
||||
GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(interfaceType.getMethod("removeObject", String.class, String.class));
|
||||
this.createMethod = Invokable.from(interfaceType.getMethod("putObject", String.class, SwiftObject.class));
|
||||
this.deleteMethod = owner
|
||||
.method(interfaceType.getRawType().getMethod("removeObject", String.class, String.class));
|
||||
this.createMethod = owner.method(interfaceType.getRawType().getMethod("putObject", String.class,
|
||||
SwiftObject.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,7 +118,7 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
public HttpRequest signGetBlob(String container, String name, long timeInSeconds) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
GeneratedHttpRequest<T> request = processor.apply(Invocation.create(getMethod,
|
||||
GeneratedHttpRequest request = processor.apply(Invocation.create(getMethod,
|
||||
ImmutableList.<Object> of(container, name)));
|
||||
return cleanRequest(signForTemporaryAccess(request, timeInSeconds));
|
||||
}
|
||||
|
@ -138,7 +143,7 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(blob, "blob");
|
||||
GeneratedHttpRequest<T> request = processor.apply(Invocation.create(createMethod,
|
||||
GeneratedHttpRequest request = processor.apply(Invocation.create(createMethod,
|
||||
ImmutableList.<Object> of(container, blobToObject.apply(blob))));
|
||||
return cleanRequest(signForTemporaryAccess(request, timeInSeconds));
|
||||
}
|
||||
|
|
|
@ -43,10 +43,10 @@ public class BasePayloadTest {
|
|||
}
|
||||
}), new GsonModule());
|
||||
|
||||
protected GeneratedHttpRequest<?> requestForArgs(List<Object> args) {
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -40,10 +40,10 @@ public class BasePayloadTest {
|
|||
}
|
||||
}));
|
||||
|
||||
protected GeneratedHttpRequest<?> requestForArgs(List<Object> args) {
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -125,23 +125,23 @@ public class BlobStoreUtilsTest {
|
|||
}
|
||||
|
||||
public void testGetKeyForAzureS3AndRackspace() {
|
||||
GeneratedHttpRequest<?> request = requestForEndpointAndArgs(
|
||||
GeneratedHttpRequest request = requestForEndpointAndArgs(
|
||||
"https://jclouds.blob.core.windows.net/adriancole-blobstore0/five",
|
||||
ImmutableList.<Object> of("adriancole-blobstore0", "five"));
|
||||
assertEquals(getNameFor(request), "five");
|
||||
}
|
||||
|
||||
public void testGetKeyForAtmos() {
|
||||
GeneratedHttpRequest<?> request = requestForEndpointAndArgs(
|
||||
GeneratedHttpRequest request = requestForEndpointAndArgs(
|
||||
"https://storage4.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22/adriancole-blobstore0/four",
|
||||
ImmutableList.<Object> of("adriancole-blobstore0/four"));
|
||||
assertEquals(getNameFor(request), "four");
|
||||
}
|
||||
|
||||
GeneratedHttpRequest<?> requestForEndpointAndArgs(String endpoint, List<Object> args) {
|
||||
GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create(endpoint)).invocation(invocation)
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create(endpoint)).invocation(invocation)
|
||||
.build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -29,10 +29,10 @@ import com.google.common.reflect.Invokable;
|
|||
|
||||
public class BasePayloadTest {
|
||||
|
||||
protected GeneratedHttpRequest<?> requestForArgs(List<Object> args) {
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>14.0-rc1</version>
|
||||
<version>14.0-rc2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
|
|
|
@ -55,7 +55,7 @@ import com.google.common.base.Optional;
|
|||
public abstract class CallerArg0ToPagedIterable<T, I extends CallerArg0ToPagedIterable<T, I>> implements
|
||||
Function<IterableWithMarker<T>, PagedIterable<T>>, InvocationContext<I> {
|
||||
|
||||
private GeneratedHttpRequest<?> request;
|
||||
private GeneratedHttpRequest request;
|
||||
|
||||
@Override
|
||||
public PagedIterable<T> apply(IterableWithMarker<T> input) {
|
||||
|
|
|
@ -214,8 +214,8 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
|
|||
}
|
||||
|
||||
@Override
|
||||
protected GeneratedHttpRequest<?> getRequest() {
|
||||
return (GeneratedHttpRequest<?>) super.getRequest();
|
||||
protected GeneratedHttpRequest getRequest() {
|
||||
return (GeneratedHttpRequest) super.getRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -112,8 +112,7 @@ public final class FunctionalReflection {
|
|||
args = ImmutableList.copyOf(args);
|
||||
else
|
||||
args = Collections.unmodifiableList(args);
|
||||
Invokable<?, Object> invokable = Invokable.from(invoked);
|
||||
// not yet support the proxy arg
|
||||
Invokable<?, Object> invokable = enclosingType.method(invoked);
|
||||
Invocation invocation = Invocation.create(invokable, args);
|
||||
try {
|
||||
return invocationFunction.apply(invocation);
|
||||
|
|
|
@ -45,7 +45,7 @@ public class BindMapToStringPayload implements MapBinder {
|
|||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
checkNotNull(postParams, "postParams");
|
||||
GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request"));
|
||||
GeneratedHttpRequest r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request"));
|
||||
Invokable<?, ?> invoked = r.getInvocation().getInvokable();
|
||||
checkArgument(invoked.isAnnotationPresent(Payload.class),
|
||||
"method %s must have @Payload annotation to use this binder", invoked);
|
||||
|
|
|
@ -36,10 +36,10 @@ import com.google.inject.TypeLiteral;
|
|||
@Singleton
|
||||
public class AsyncHttpApiProvider<A> implements Provider<A> {
|
||||
private final Class<? super A> asyncApiType;
|
||||
private final DelegatesToInvocationFunction<A, A, InvokeHttpMethod<A, A>> httpInvoker;
|
||||
private final DelegatesToInvocationFunction<A, InvokeHttpMethod> httpInvoker;
|
||||
|
||||
@Inject
|
||||
private AsyncHttpApiProvider(DelegatesToInvocationFunction<A, A, InvokeHttpMethod<A, A>> httpInvoker,
|
||||
private AsyncHttpApiProvider(DelegatesToInvocationFunction<A, InvokeHttpMethod> httpInvoker,
|
||||
TypeLiteral<A> asyncApiType) {
|
||||
this.httpInvoker = httpInvoker;
|
||||
this.asyncApiType = asyncApiType.getRawType();
|
||||
|
|
|
@ -38,11 +38,11 @@ import com.google.inject.Provider;
|
|||
public class CallGetOnFuturesProvider<S, A> implements Provider<S> {
|
||||
|
||||
private final Class<? super S> apiType;
|
||||
private final DelegatesToInvocationFunction<S, A, InvokeAndCallGetOnFutures<A>> syncInvoker;
|
||||
private final DelegatesToInvocationFunction<S, InvokeAndCallGetOnFutures<A>> syncInvoker;
|
||||
|
||||
@Inject
|
||||
private CallGetOnFuturesProvider(Cache<Invokable<?, ?>, Invokable<?, ?>> invokables,
|
||||
DelegatesToInvocationFunction<S, A, InvokeAndCallGetOnFutures<A>> syncInvoker, Class<S> apiType,
|
||||
DelegatesToInvocationFunction<S, InvokeAndCallGetOnFutures<A>> syncInvoker, Class<S> apiType,
|
||||
Class<A> asyncApiType) {
|
||||
this.syncInvoker = syncInvoker;
|
||||
this.apiType = apiType;
|
||||
|
|
|
@ -38,11 +38,11 @@ import com.google.inject.Provider;
|
|||
@Singleton
|
||||
public class HttpApiProvider<S, A> implements Provider<S> {
|
||||
private final Class<? super S> apiType;
|
||||
private final DelegatesToInvocationFunction<S, A, InvokeHttpMethod<S, A>> httpInvoker;
|
||||
private final DelegatesToInvocationFunction<S, InvokeHttpMethod> httpInvoker;
|
||||
|
||||
@Inject
|
||||
private HttpApiProvider(Cache<Invokable<?, ?>, Invokable<?, ?>> invokables,
|
||||
DelegatesToInvocationFunction<S, A, InvokeHttpMethod<S, A>> httpInvoker, Class<S> apiType, Class<A> asyncApiType) {
|
||||
DelegatesToInvocationFunction<S, InvokeHttpMethod> httpInvoker, Class<S> apiType, Class<A> asyncApiType) {
|
||||
this.httpInvoker = httpInvoker;
|
||||
this.apiType = apiType;
|
||||
RestModule.putInvokables(TypeToken.of(apiType), TypeToken.of(asyncApiType), invokables);
|
||||
|
@ -54,5 +54,4 @@ public class HttpApiProvider<S, A> implements Provider<S> {
|
|||
public S get() {
|
||||
return (S) Proxy.newProxyInstance(apiType.getClassLoader(), new Class<?>[] { apiType }, httpInvoker);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public class RestModule extends AbstractModule {
|
|||
"invoked %s has different typed exceptions than delegated invoked %s", invoked, delegatedMethod);
|
||||
invoked.setAccessible(true);
|
||||
delegatedMethod.setAccessible(true);
|
||||
cache.put(Invokable.from(invoked), Invokable.from(delegatedMethod));
|
||||
cache.put(sync.method(invoked), async.method(delegatedMethod));
|
||||
} catch (SecurityException e) {
|
||||
throw propagate(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
|
||||
import org.jclouds.reflect.Invocation;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provider;
|
||||
|
@ -36,43 +35,29 @@ import com.google.inject.name.Names;
|
|||
*/
|
||||
public class SetCaller {
|
||||
|
||||
private final ThreadLocal<TypeToken<?>> callerEnclosingType = new ThreadLocal<TypeToken<?>>();
|
||||
private final ThreadLocal<Invocation> caller = new ThreadLocal<Invocation>();
|
||||
|
||||
public void enter(TypeToken<?> callerEnclosingType, Invocation caller) {
|
||||
checkState(this.callerEnclosingType.get() == null, "A scoping block is already in progress");
|
||||
this.callerEnclosingType.set(callerEnclosingType);
|
||||
public void enter(Invocation caller) {
|
||||
checkState(this.caller.get() == null, "A scoping block is already in progress");
|
||||
this.caller.set(caller);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
checkState(caller.get() != null, "No scoping block in progress");
|
||||
callerEnclosingType.remove();
|
||||
caller.remove();
|
||||
}
|
||||
|
||||
public static class Module extends AbstractModule {
|
||||
public void configure() {
|
||||
SetCaller delegateScope = new SetCaller();
|
||||
bind(CALLER_ENCLOSING_TYPE).toProvider(delegateScope.new CallerEnclosingTypeProvider());
|
||||
bind(CALLER_INVOCATION).toProvider(delegateScope.new CallerInvocationProvider());
|
||||
bind(SetCaller.class).toInstance(delegateScope);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Key<TypeToken<?>> CALLER_ENCLOSING_TYPE = Key.get(new TypeLiteral<TypeToken<?>>() {
|
||||
}, Names.named("caller"));
|
||||
|
||||
private static final Key<Invocation> CALLER_INVOCATION = Key.get(new TypeLiteral<Invocation>() {
|
||||
}, Names.named("caller"));
|
||||
|
||||
class CallerEnclosingTypeProvider implements Provider<TypeToken<?>> {
|
||||
@Override
|
||||
public TypeToken<?> get() {
|
||||
return callerEnclosingType.get();
|
||||
}
|
||||
}
|
||||
|
||||
class CallerInvocationProvider implements Provider<Invocation> {
|
||||
@Override
|
||||
public Invocation get() {
|
||||
|
|
|
@ -39,7 +39,6 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
import com.google.common.util.concurrent.UncheckedTimeoutException;
|
||||
|
@ -52,22 +51,19 @@ public class BlockOnFuture implements Function<ListenableFuture<?>, Object> {
|
|||
* @param invocation
|
||||
* context for how the future was created
|
||||
*/
|
||||
BlockOnFuture create(TypeToken<?> enclosingType, Invocation invocation);
|
||||
BlockOnFuture create(Invocation invocation);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private Logger logger = Logger.NULL;
|
||||
|
||||
private final Map<String, Long> timeouts;
|
||||
private final TypeToken<?> enclosingType;
|
||||
private final Invocation invocation;
|
||||
|
||||
@Inject
|
||||
@VisibleForTesting
|
||||
BlockOnFuture(@Named("TIMEOUTS") Map<String, Long> timeouts, @Assisted TypeToken<?> enclosingType,
|
||||
@Assisted Invocation invocation) {
|
||||
BlockOnFuture(@Named("TIMEOUTS") Map<String, Long> timeouts, @Assisted Invocation invocation) {
|
||||
this.timeouts = timeouts;
|
||||
this.enclosingType = enclosingType;
|
||||
this.invocation = invocation;
|
||||
}
|
||||
|
||||
|
@ -124,7 +120,7 @@ public class BlockOnFuture implements Function<ListenableFuture<?>, Object> {
|
|||
timeoutMillis = fromNullable(timeouts.get(commandName)).or(defaultMillis);
|
||||
} else {
|
||||
// TODO: remove old logic, once Named annotations are present on all methods
|
||||
String className = enclosingType.getRawType().getSimpleName().replace("AsyncClient", "Client")
|
||||
String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client")
|
||||
.replace("AsyncApi", "Api");
|
||||
timeoutMillis = fromNullable(timeouts.get(className + "." + invoked.getName())).or(
|
||||
fromNullable(timeouts.get(className))).or(defaultMillis);
|
||||
|
|
|
@ -72,13 +72,11 @@ import com.google.inject.util.Types;
|
|||
/**
|
||||
* @param <S>
|
||||
* The enclosing type of the interface that a dynamic proxy like this implements
|
||||
* @param <A>
|
||||
* The enclosing type that is processed by this proxy
|
||||
* @param <F>
|
||||
* The function that implements this dynamic proxy
|
||||
*/
|
||||
@Beta
|
||||
public final class DelegatesToInvocationFunction<S, A, F extends Function<Invocation, Object>> implements
|
||||
public final class DelegatesToInvocationFunction<S, F extends Function<Invocation, Object>> implements
|
||||
InvocationHandler {
|
||||
|
||||
private static final Object[] NO_ARGS = {};
|
||||
|
@ -120,8 +118,7 @@ public final class DelegatesToInvocationFunction<S, A, F extends Function<Invoca
|
|||
args = ImmutableList.copyOf(args);
|
||||
else
|
||||
args = Collections.unmodifiableList(args);
|
||||
Invokable<?, Object> invokable = Invokable.from(invoked);
|
||||
// not yet support the proxy arg
|
||||
Invokable<?, Object> invokable = enclosingType.method(invoked);
|
||||
Invocation invocation = Invocation.create(invokable, args);
|
||||
try {
|
||||
return handle(invocation);
|
||||
|
@ -161,7 +158,7 @@ public final class DelegatesToInvocationFunction<S, A, F extends Function<Invoca
|
|||
private Object propagateContextToDelegate(Invocation caller) {
|
||||
Class<?> returnType = unwrapIfOptional(caller.getInvokable().getReturnType());
|
||||
Function<Invocation, Object> delegate;
|
||||
setCaller.enter(enclosingType, caller);
|
||||
setCaller.enter(caller);
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Key<Function<Invocation, Object>> delegateType = (Key<Function<Invocation, Object>>) methodInvokerFor(returnType);
|
||||
|
|
|
@ -30,101 +30,67 @@ import org.jclouds.reflect.Invocation;
|
|||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author adriancole
|
||||
*
|
||||
* @param <A>
|
||||
* enclosing type of the interface parsed to generate this request.
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public final class GeneratedHttpRequest<A> extends HttpRequest {
|
||||
public static <A> Builder<A> builder(Class<A> enclosingType) {
|
||||
return new Builder<A>(TypeToken.of(enclosingType));
|
||||
public final class GeneratedHttpRequest extends HttpRequest {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static <A> Builder<A> builder(TypeToken<A> enclosingType) {
|
||||
return new Builder<A>(enclosingType);
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromGeneratedHttpRequest(this);
|
||||
}
|
||||
|
||||
public Builder<A> toBuilder() {
|
||||
return new Builder<A>(enclosingType).fromGeneratedHttpRequest(this);
|
||||
}
|
||||
|
||||
public final static class Builder<A> extends HttpRequest.Builder<Builder<A>> {
|
||||
private final TypeToken<A> enclosingType;
|
||||
|
||||
private Builder(TypeToken<A> enclosingType) {
|
||||
this.enclosingType = checkNotNull(enclosingType, "enclosingType");
|
||||
}
|
||||
|
||||
public final static class Builder extends HttpRequest.Builder<Builder> {
|
||||
private Invocation invocation;
|
||||
private Optional<TypeToken<?>> callerEnclosingType = Optional.absent();
|
||||
private Optional<Invocation> caller = Optional.absent();
|
||||
|
||||
/**
|
||||
* @see GeneratedHttpRequest#getInvocation()
|
||||
*/
|
||||
public Builder<A> invocation(Invocation invocation) {
|
||||
public Builder invocation(Invocation invocation) {
|
||||
this.invocation = checkNotNull(invocation, "invocation");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GeneratedHttpRequest#getCallerEnclosingType()
|
||||
*/
|
||||
public Builder<A> callerEnclosingType(@Nullable TypeToken<?> callerEnclosingType) {
|
||||
this.callerEnclosingType = Optional.<TypeToken<?>> fromNullable(callerEnclosingType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see GeneratedHttpRequest#getCaller()
|
||||
*/
|
||||
public Builder<A> caller(@Nullable Invocation caller) {
|
||||
public Builder caller(@Nullable Invocation caller) {
|
||||
this.caller = Optional.fromNullable(caller);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GeneratedHttpRequest<A> build() {
|
||||
return new GeneratedHttpRequest<A>(method, endpoint, headers.build(), payload, filters.build(), enclosingType,
|
||||
invocation, callerEnclosingType, caller);
|
||||
public GeneratedHttpRequest build() {
|
||||
return new GeneratedHttpRequest(method, endpoint, headers.build(), payload, filters.build(), invocation,
|
||||
caller);
|
||||
}
|
||||
|
||||
public Builder<A> fromGeneratedHttpRequest(GeneratedHttpRequest<A> in) {
|
||||
return super.fromHttpRequest(in).invocation(in.invocation)
|
||||
.callerEnclosingType(in.getCallerEnclosingType().orNull()).caller(in.getCaller().orNull());
|
||||
public Builder fromGeneratedHttpRequest(GeneratedHttpRequest in) {
|
||||
return super.fromHttpRequest(in).invocation(in.invocation).caller(in.getCaller().orNull());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder<A> self() {
|
||||
protected Builder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private final TypeToken<A> enclosingType;
|
||||
private final Invocation invocation;
|
||||
private final Optional<TypeToken<?>> callerEnclosingType;
|
||||
private final Optional<Invocation> caller;
|
||||
|
||||
protected GeneratedHttpRequest(String method, URI endpoint, Multimap<String, String> headers,
|
||||
@Nullable Payload payload, Iterable<HttpRequestFilter> filters, TypeToken<A> enclosingType,
|
||||
Invocation invocation, Optional<TypeToken<?>> callerEnclosingType, Optional<Invocation> caller) {
|
||||
@Nullable Payload payload, Iterable<HttpRequestFilter> filters, Invocation invocation,
|
||||
Optional<Invocation> caller) {
|
||||
super(method, endpoint, headers, payload, filters);
|
||||
this.enclosingType = checkNotNull(enclosingType, "enclosingType");
|
||||
this.invocation = checkNotNull(invocation, "invocation");
|
||||
this.callerEnclosingType = checkNotNull(callerEnclosingType, "callerEnclosingType");
|
||||
this.caller = checkNotNull(caller, "caller");
|
||||
}
|
||||
|
||||
/**
|
||||
* different than {@link #getDeclaringClass()} when this is a member of a class it was not declared in.
|
||||
*/
|
||||
public TypeToken<?> getEnclosingType() {
|
||||
return enclosingType;
|
||||
}
|
||||
|
||||
/**
|
||||
* what was interpreted to create this request
|
||||
*/
|
||||
|
@ -132,14 +98,6 @@ public final class GeneratedHttpRequest<A> extends HttpRequest {
|
|||
return invocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* different than {@link #getDeclaringClass()} when {@link #getCaller()} is a member of a class it was not declared
|
||||
* in.
|
||||
*/
|
||||
public Optional<TypeToken<?>> getCallerEnclosingType() {
|
||||
return callerEnclosingType;
|
||||
}
|
||||
|
||||
public Optional<Invocation> getCaller() {
|
||||
return caller;
|
||||
}
|
||||
|
|
|
@ -27,22 +27,13 @@ import org.jclouds.reflect.Invocation;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
class GetAcceptHeaders<T> implements Function<Invocation, Set<String>> {
|
||||
private Class<T> enclosingType;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
GetAcceptHeaders(TypeLiteral<T> enclosingType) {
|
||||
this.enclosingType = (Class<T>) enclosingType.getRawType();
|
||||
}
|
||||
class GetAcceptHeaders implements Function<Invocation, Set<String>> {
|
||||
|
||||
@Override
|
||||
public Set<String> apply(Invocation invocation) {
|
||||
Optional<Consumes> accept = Optional.fromNullable(invocation.getInvokable().getAnnotation(Consumes.class)).or(
|
||||
Optional.fromNullable(enclosingType.getAnnotation(Consumes.class)));
|
||||
Optional.fromNullable(invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Consumes.class)));
|
||||
return (accept.isPresent()) ? ImmutableSet.copyOf(accept.get().value()) : ImmutableSet.<String> of();
|
||||
}
|
||||
}
|
|
@ -45,35 +45,30 @@ import com.google.common.cache.CacheBuilder;
|
|||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.FutureFallback;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public class InvokeHttpMethod<S, A> implements Function<Invocation, Object> {
|
||||
public class InvokeHttpMethod implements Function<Invocation, Object> {
|
||||
|
||||
@Resource
|
||||
private Logger logger = Logger.NULL;
|
||||
|
||||
private final Injector injector;
|
||||
private final TypeToken<A> enclosingType;
|
||||
private final Cache<Invokable<?, ?>, Invokable<?, ?>> sync2AsyncInvokables;
|
||||
private final RestAnnotationProcessor<A> annotationProcessor;
|
||||
private final RestAnnotationProcessor annotationProcessor;
|
||||
private final HttpCommandExecutorService http;
|
||||
private final TransformerForRequest<A> transformerForRequest;
|
||||
private final TransformerForRequest transformerForRequest;
|
||||
private final ListeningExecutorService userExecutor;
|
||||
private final BlockOnFuture.Factory blocker;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
private InvokeHttpMethod(Injector injector, TypeLiteral<A> enclosingType,
|
||||
Cache<Invokable<?, ?>, Invokable<?, ?>> sync2AsyncInvokables, RestAnnotationProcessor<A> annotationProcessor,
|
||||
HttpCommandExecutorService http, TransformerForRequest<A> transformerForRequest,
|
||||
private InvokeHttpMethod(Injector injector, Cache<Invokable<?, ?>, Invokable<?, ?>> sync2AsyncInvokables,
|
||||
RestAnnotationProcessor annotationProcessor, HttpCommandExecutorService http,
|
||||
TransformerForRequest transformerForRequest,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, BlockOnFuture.Factory blocker) {
|
||||
this.injector = injector;
|
||||
this.enclosingType = (TypeToken<A>) TypeToken.of(enclosingType.getType());
|
||||
this.sync2AsyncInvokables = sync2AsyncInvokables;
|
||||
this.annotationProcessor = annotationProcessor;
|
||||
this.http = http;
|
||||
|
@ -105,7 +100,7 @@ public class InvokeHttpMethod<S, A> implements Function<Invocation, Object> {
|
|||
checkNotNull(sync2AsyncInvokables.getIfPresent(in.getInvokable()), "invokable %s not in %s",
|
||||
in.getInvokable(), sync2AsyncInvokables), in.getArgs());
|
||||
checkState(isFuture(async.getInvokable()), "not a future: %s", async);
|
||||
return blocker.create(enclosingType, async).apply(createFuture(async));
|
||||
return blocker.create(async).apply(createFuture(async));
|
||||
}
|
||||
|
||||
private boolean isFuture(Invokable<?, ?> in) {
|
||||
|
@ -115,7 +110,7 @@ public class InvokeHttpMethod<S, A> implements Function<Invocation, Object> {
|
|||
public ListenableFuture<?> createFuture(Invocation invocation) {
|
||||
String name = invocation.getInvokable().toString();
|
||||
logger.trace(">> converting %s", name);
|
||||
GeneratedHttpRequest<A> request = annotationProcessor.apply(invocation);
|
||||
GeneratedHttpRequest request = annotationProcessor.apply(invocation);
|
||||
logger.trace("<< converted %s to %s", name, request.getRequestLine());
|
||||
|
||||
Function<HttpResponse, ?> transformer = transformerForRequest.apply(request);
|
||||
|
@ -138,7 +133,7 @@ public class InvokeHttpMethod<S, A> implements Function<Invocation, Object> {
|
|||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
InvokeHttpMethod<?, ?> that = InvokeHttpMethod.class.cast(o);
|
||||
InvokeHttpMethod that = InvokeHttpMethod.class.cast(o);
|
||||
return equal(this.annotationProcessor, that.annotationProcessor);
|
||||
}
|
||||
|
||||
|
|
|
@ -78,8 +78,6 @@ import org.jclouds.io.payloads.Part.PartOptions;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.Parameter;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.InputParamValidator;
|
||||
import org.jclouds.rest.annotations.ApiVersion;
|
||||
|
@ -122,7 +120,8 @@ import com.google.common.collect.LinkedListMultimap;
|
|||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.primitives.Chars;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.Parameter;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -130,11 +129,9 @@ import com.google.inject.TypeLiteral;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author adriancole
|
||||
*
|
||||
* @param <A>
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class RestAnnotationProcessor<A> implements Function<Invocation, GeneratedHttpRequest<A>> {
|
||||
public class RestAnnotationProcessor implements Function<Invocation, GeneratedHttpRequest> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
@ -152,17 +149,13 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
private final String apiVersion;
|
||||
private final String buildVersion;
|
||||
private final InputParamValidator inputParamValidator;
|
||||
private final GetAcceptHeaders<A> getAcceptHeaders;
|
||||
private final TypeToken<A> enclosingType;
|
||||
private final TypeToken<?> callerEnclosingType;
|
||||
private final GetAcceptHeaders getAcceptHeaders;
|
||||
private final Invocation caller;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
private RestAnnotationProcessor(Injector injector, @ApiVersion String apiVersion, @BuildVersion String buildVersion,
|
||||
HttpUtils utils, ContentMetadataCodec contentMetadataCodec, InputParamValidator inputParamValidator,
|
||||
GetAcceptHeaders<A> getAcceptHeaders, TypeLiteral<A> enclosingType,
|
||||
@Nullable @Named("caller") TypeToken<?> callerEnclosingType, @Nullable @Named("caller") Invocation caller) {
|
||||
GetAcceptHeaders getAcceptHeaders, @Nullable @Named("caller") Invocation caller) {
|
||||
this.injector = injector;
|
||||
this.utils = utils;
|
||||
this.contentMetadataCodec = contentMetadataCodec;
|
||||
|
@ -170,22 +163,20 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
this.buildVersion = buildVersion;
|
||||
this.inputParamValidator = inputParamValidator;
|
||||
this.getAcceptHeaders = getAcceptHeaders;
|
||||
this.enclosingType = (TypeToken<A>) TypeToken.of(enclosingType.getType());
|
||||
this.callerEnclosingType = callerEnclosingType;
|
||||
this.caller = caller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note this is dangerous as it cannot pass the inheriting class! Using this when subclassing interfaces may result
|
||||
* in lost data.
|
||||
* Note this is dangerous as it cannot pass the inheriting class! Using this
|
||||
* when subclassing interfaces may result in lost data.
|
||||
*/
|
||||
@Deprecated
|
||||
public GeneratedHttpRequest<A> createRequest(Invokable<?, ?> invokable, List<Object> args) {
|
||||
public GeneratedHttpRequest createRequest(Invokable<?, ?> invokable, List<Object> args) {
|
||||
return apply(Invocation.create(invokable, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratedHttpRequest<A> apply(Invocation invocation) {
|
||||
public GeneratedHttpRequest apply(Invocation invocation) {
|
||||
checkNotNull(invocation, "invocation");
|
||||
inputParamValidator.validateMethodParametersOrThrow(invocation);
|
||||
|
||||
|
@ -196,7 +187,7 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
if (endpoint.isPresent())
|
||||
logger.trace("using endpoint %s from invocation.getArgs() for %s", endpoint, invocation);
|
||||
} else if (caller != null) {
|
||||
endpoint = getEndpointFor(callerEnclosingType, caller);
|
||||
endpoint = getEndpointFor(caller);
|
||||
if (endpoint.isPresent())
|
||||
logger.trace("using endpoint %s from caller %s for %s", endpoint, caller, invocation);
|
||||
else
|
||||
|
@ -207,8 +198,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
if (!endpoint.isPresent())
|
||||
throw new NoSuchElementException(format("no endpoint found for %s", invocation));
|
||||
GeneratedHttpRequest.Builder<A> requestBuilder = GeneratedHttpRequest.builder(enclosingType)
|
||||
.invocation(invocation).callerEnclosingType(callerEnclosingType).caller(caller);
|
||||
GeneratedHttpRequest.Builder requestBuilder = GeneratedHttpRequest.builder().invocation(invocation)
|
||||
.caller(caller);
|
||||
if (r != null) {
|
||||
requestBuilder.fromHttpRequest(r);
|
||||
} else {
|
||||
|
@ -221,14 +212,14 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
tokenValues.put(Constants.PROPERTY_API_VERSION, apiVersion);
|
||||
tokenValues.put(Constants.PROPERTY_BUILD_VERSION, buildVersion);
|
||||
|
||||
UriBuilder uriBuilder = uriBuilder(endpoint.get().toString()); // URI template in rfc6570 form
|
||||
// URI template in rfc6570 form
|
||||
UriBuilder uriBuilder = uriBuilder(endpoint.get().toString());
|
||||
|
||||
overridePathEncoding(uriBuilder, invocation);
|
||||
|
||||
if (caller != null)
|
||||
tokenValues.putAll(addPathAndGetTokens(callerEnclosingType, caller, uriBuilder));
|
||||
tokenValues.putAll(addPathAndGetTokens(enclosingType, invocation, uriBuilder));
|
||||
tokenValues.putAll(addPathAndGetTokens(caller, uriBuilder));
|
||||
tokenValues.putAll(addPathAndGetTokens(invocation, uriBuilder));
|
||||
|
||||
Multimap<String, Object> formParams = addFormParams(tokenValues, invocation);
|
||||
Multimap<String, Object> queryParams = addQueryParams(tokenValues, invocation);
|
||||
|
@ -298,7 +289,7 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
if (payload != null) {
|
||||
requestBuilder.payload(payload);
|
||||
}
|
||||
GeneratedHttpRequest<A> request = requestBuilder.build();
|
||||
GeneratedHttpRequest request = requestBuilder.build();
|
||||
|
||||
org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(invocation);
|
||||
if (mapBinder != null) {
|
||||
|
@ -319,7 +310,7 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
return request;
|
||||
}
|
||||
|
||||
private static <A> A findOrNull(Iterable<Object> args, Class<A> clazz) {
|
||||
private static <T> T findOrNull(Iterable<Object> args, Class<T> clazz) {
|
||||
return clazz.cast(tryFind(args, instanceOf(clazz)).orNull());
|
||||
}
|
||||
|
||||
|
@ -332,9 +323,9 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
}
|
||||
|
||||
private void overridePathEncoding(UriBuilder uriBuilder, Invocation invocation) {
|
||||
if (enclosingType.getRawType().isAnnotationPresent(SkipEncoding.class)) {
|
||||
uriBuilder
|
||||
.skipPathEncoding(Chars.asList(enclosingType.getRawType().getAnnotation(SkipEncoding.class).value()));
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(SkipEncoding.class)) {
|
||||
uriBuilder.skipPathEncoding(Chars.asList(invocation.getInvokable().getOwnerType().getRawType()
|
||||
.getAnnotation(SkipEncoding.class).value()));
|
||||
}
|
||||
if (invocation.getInvokable().isAnnotationPresent(SkipEncoding.class)) {
|
||||
uriBuilder.skipPathEncoding(Chars.asList(invocation.getInvokable().getAnnotation(SkipEncoding.class).value()));
|
||||
|
@ -353,7 +344,7 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
}
|
||||
|
||||
protected Optional<URI> findEndpoint(Invocation invocation) {
|
||||
Optional<URI> endpoint = getEndpointFor(enclosingType, invocation);
|
||||
Optional<URI> endpoint = getEndpointFor(invocation);
|
||||
if (endpoint.isPresent())
|
||||
logger.trace("using endpoint %s for %s", endpoint, invocation);
|
||||
if (!endpoint.isPresent()) {
|
||||
|
@ -366,10 +357,9 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
return endpoint;
|
||||
}
|
||||
|
||||
private Multimap<String, Object> addPathAndGetTokens(TypeToken<?> enclosingType, Invocation invocation,
|
||||
UriBuilder uriBuilder) {
|
||||
if (enclosingType.getRawType().isAnnotationPresent(Path.class))
|
||||
uriBuilder.appendPath(enclosingType.getRawType().getAnnotation(Path.class).value());
|
||||
private Multimap<String, Object> addPathAndGetTokens(Invocation invocation, UriBuilder uriBuilder) {
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Path.class))
|
||||
uriBuilder.appendPath(invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Path.class).value());
|
||||
if (invocation.getInvokable().isAnnotationPresent(Path.class))
|
||||
uriBuilder.appendPath(invocation.getInvokable().getAnnotation(Path.class).value());
|
||||
return getPathParamKeyValues(invocation);
|
||||
|
@ -377,8 +367,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
private Multimap<String, Object> addFormParams(Multimap<String, ?> tokenValues, Invocation invocation) {
|
||||
Multimap<String, Object> formMap = LinkedListMultimap.create();
|
||||
if (enclosingType.getRawType().isAnnotationPresent(FormParams.class)) {
|
||||
FormParams form = enclosingType.getRawType().getAnnotation(FormParams.class);
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(FormParams.class)) {
|
||||
FormParams form = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(FormParams.class);
|
||||
addForm(formMap, form, tokenValues);
|
||||
}
|
||||
|
||||
|
@ -395,8 +385,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
private Multimap<String, Object> addQueryParams(Multimap<String, ?> tokenValues, Invocation invocation) {
|
||||
Multimap<String, Object> queryMap = LinkedListMultimap.create();
|
||||
if (enclosingType.getRawType().isAnnotationPresent(QueryParams.class)) {
|
||||
QueryParams query = enclosingType.getRawType().getAnnotation(QueryParams.class);
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(QueryParams.class)) {
|
||||
QueryParams query = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(QueryParams.class);
|
||||
addQuery(queryMap, query, tokenValues);
|
||||
}
|
||||
|
||||
|
@ -446,12 +436,13 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
private List<HttpRequestFilter> getFiltersIfAnnotated(Invocation invocation) {
|
||||
List<HttpRequestFilter> filters = newArrayList();
|
||||
if (enclosingType.getRawType().isAnnotationPresent(RequestFilters.class)) {
|
||||
for (Class<? extends HttpRequestFilter> clazz : enclosingType.getRawType().getAnnotation(RequestFilters.class)
|
||||
.value()) {
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(RequestFilters.class)) {
|
||||
for (Class<? extends HttpRequestFilter> clazz : invocation.getInvokable().getOwnerType().getRawType()
|
||||
.getAnnotation(RequestFilters.class).value()) {
|
||||
HttpRequestFilter instance = injector.getInstance(clazz);
|
||||
filters.add(instance);
|
||||
logger.trace("adding filter %s from annotation on %s", instance, enclosingType.getRawType().getName());
|
||||
logger.trace("adding filter %s from annotation on %s", instance, invocation.getInvokable().getOwnerType()
|
||||
.getRawType().getName());
|
||||
}
|
||||
}
|
||||
if (invocation.getInvokable().isAnnotationPresent(RequestFilters.class)) {
|
||||
|
@ -500,14 +491,14 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
private static final TypeLiteral<Supplier<URI>> uriSupplierLiteral = new TypeLiteral<Supplier<URI>>() {
|
||||
};
|
||||
|
||||
protected Optional<URI> getEndpointFor(TypeToken<?> enclosingType, Invocation invocation) {
|
||||
protected Optional<URI> getEndpointFor(Invocation invocation) {
|
||||
URI endpoint = getEndpointInParametersOrNull(invocation, injector);
|
||||
if (endpoint == null) {
|
||||
Endpoint annotation;
|
||||
if (invocation.getInvokable().isAnnotationPresent(Endpoint.class)) {
|
||||
annotation = invocation.getInvokable().getAnnotation(Endpoint.class);
|
||||
} else if (enclosingType.getRawType().isAnnotationPresent(Endpoint.class)) {
|
||||
annotation = enclosingType.getRawType().getAnnotation(Endpoint.class);
|
||||
} else if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Endpoint.class)) {
|
||||
annotation = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Endpoint.class);
|
||||
} else {
|
||||
logger.trace("no annotations on class or invocation.getInvoked(): %s", invocation.getInvokable());
|
||||
return Optional.absent();
|
||||
|
@ -567,11 +558,11 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
}
|
||||
|
||||
private boolean shouldAddHostHeader(Invocation invocation) {
|
||||
return (enclosingType.getRawType().isAnnotationPresent(VirtualHost.class) || invocation.getInvokable()
|
||||
.isAnnotationPresent(VirtualHost.class));
|
||||
return (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(VirtualHost.class) || invocation
|
||||
.getInvokable().isAnnotationPresent(VirtualHost.class));
|
||||
}
|
||||
|
||||
private GeneratedHttpRequest<A> decorateRequest(GeneratedHttpRequest<A> request) throws NegativeArraySizeException {
|
||||
private GeneratedHttpRequest decorateRequest(GeneratedHttpRequest request) throws NegativeArraySizeException {
|
||||
Invocation invocation = request.getInvocation();
|
||||
List<Object> args = request.getInvocation().getArgs();
|
||||
Set<Parameter> binderOrWrapWith = ImmutableSet.copyOf(concat(
|
||||
|
@ -590,14 +581,19 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
if (args.size() >= position + 1 && arg != null) {
|
||||
Class<?> parameterType = entry.getType().getRawType();
|
||||
Class<? extends Object> argType = arg.getClass();
|
||||
if (!argType.isArray() && parameterType.isArray()) {// TODO: && invocation.getInvokable().isVarArgs()) {
|
||||
if (!argType.isArray() && parameterType.isArray()) {// TODO: &&
|
||||
// invocation.getInvokable().isVarArgs())
|
||||
// {
|
||||
int arrayLength = args.size() - invocation.getInvokable().getParameters().size() + 1;
|
||||
if (arrayLength == 0)
|
||||
break OUTER;
|
||||
arg = (Object[]) Array.newInstance(arg.getClass(), arrayLength);
|
||||
System.arraycopy(args.toArray(), position, arg, 0, arrayLength);
|
||||
shouldBreak = true;
|
||||
} else if (argType.isArray() && parameterType.isArray()){// TODO: && invocation.getInvokable().isVarArgs()) {
|
||||
} else if (argType.isArray() && parameterType.isArray()) {// TODO:
|
||||
// &&
|
||||
// invocation.getInvokable().isVarArgs())
|
||||
// {
|
||||
} else {
|
||||
if (arg.getClass().isArray()) {
|
||||
Object[] payloadArray = (Object[]) arg;
|
||||
|
@ -610,7 +606,9 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
if (shouldBreak)
|
||||
break OUTER;
|
||||
} else {
|
||||
if (position + 1 == invocation.getInvokable().getParameters().size() && entry.getType().isArray())// TODO: && invocation.getInvokable().isVarArgs())
|
||||
if (position + 1 == invocation.getInvokable().getParameters().size() && entry.getType().isArray())// TODO:
|
||||
// &&
|
||||
// invocation.getInvokable().isVarArgs())
|
||||
continue OUTER;
|
||||
|
||||
if (entry.isAnnotationPresent(Nullable.class)) {
|
||||
|
@ -640,7 +638,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
private Set<HttpRequestOptions> findOptionsIn(Invocation invocation) {
|
||||
ImmutableSet.Builder<HttpRequestOptions> result = ImmutableSet.builder();
|
||||
for (int index : invokableToIndexesOfOptions.getUnchecked(invocation.getInvokable())) {
|
||||
if (invocation.getArgs().size() >= index + 1) {// accommodate varinvocation.getArgs()
|
||||
if (invocation.getArgs().size() >= index + 1) {// accommodate
|
||||
// varinvocation.getArgs()
|
||||
if (invocation.getArgs().get(index) instanceof Object[]) {
|
||||
for (Object option : (Object[]) invocation.getArgs().get(index)) {
|
||||
if (option instanceof HttpRequestOptions) {
|
||||
|
@ -680,8 +679,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
}
|
||||
|
||||
private void addProducesIfPresentOnTypeOrMethod(Multimap<String, String> headers, Invocation invocation) {
|
||||
if (enclosingType.getRawType().isAnnotationPresent(Produces.class)) {
|
||||
Produces header = enclosingType.getRawType().getAnnotation(Produces.class);
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Produces.class)) {
|
||||
Produces header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Produces.class);
|
||||
headers.replaceValues(CONTENT_TYPE, asList(header.value()));
|
||||
}
|
||||
if (invocation.getInvokable().isAnnotationPresent(Produces.class)) {
|
||||
|
@ -692,8 +691,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
private void addHeaderIfAnnotationPresentOnMethod(Multimap<String, String> headers, Invocation invocation,
|
||||
Multimap<String, ?> tokenValues) {
|
||||
if (enclosingType.getRawType().isAnnotationPresent(Headers.class)) {
|
||||
Headers header = enclosingType.getRawType().getAnnotation(Headers.class);
|
||||
if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Headers.class)) {
|
||||
Headers header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Headers.class);
|
||||
addHeader(headers, header, tokenValues);
|
||||
}
|
||||
if (invocation.getInvokable().isAnnotationPresent(Headers.class)) {
|
||||
|
@ -732,8 +731,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
for (Parameter param : parametersWithAnnotation(invocation.getInvokable(), PathParam.class)) {
|
||||
PathParam pathParam = param.getAnnotation(PathParam.class);
|
||||
String paramKey = pathParam.value();
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class),
|
||||
param.hashCode(), paramKey);
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class), param.hashCode(),
|
||||
paramKey);
|
||||
if (paramValue.isPresent())
|
||||
pathParamValues.put(paramKey, paramValue.get().toString());
|
||||
}
|
||||
|
@ -744,7 +743,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
String paramKey) {
|
||||
Object arg = invocation.getArgs().get(argIndex);
|
||||
if (extractor != null && checkPresentOrNullable(invocation, paramKey, argIndex, arg)) {
|
||||
arg = injector.getInstance(extractor.value()).apply(arg); // ParamParsers can deal with nullable parameters
|
||||
// ParamParsers can deal with nullable parameters
|
||||
arg = injector.getInstance(extractor.value()).apply(arg);
|
||||
}
|
||||
checkPresentOrNullable(invocation, paramKey, argIndex, arg);
|
||||
return Optional.fromNullable(arg);
|
||||
|
@ -752,8 +752,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
private boolean checkPresentOrNullable(Invocation invocation, String paramKey, int argIndex, Object arg) {
|
||||
if (arg == null && !invocation.getInvokable().getParameters().get(argIndex).isAnnotationPresent(Nullable.class))
|
||||
throw new NullPointerException(format("param{%s} for invocation %s.%s", paramKey, enclosingType.getRawType()
|
||||
.getSimpleName(), invocation.getInvokable().getName()));
|
||||
throw new NullPointerException(format("param{%s} for invocation %s.%s", paramKey, invocation.getInvokable()
|
||||
.getOwnerType().getRawType().getSimpleName(), invocation.getInvokable().getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -762,8 +762,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
for (Parameter param : parametersWithAnnotation(invocation.getInvokable(), FormParam.class)) {
|
||||
FormParam formParam = param.getAnnotation(FormParam.class);
|
||||
String paramKey = formParam.value();
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class),
|
||||
param.hashCode(), paramKey);
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class), param.hashCode(),
|
||||
paramKey);
|
||||
if (paramValue.isPresent())
|
||||
formParamValues.put(paramKey, paramValue.get().toString());
|
||||
}
|
||||
|
@ -775,8 +775,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
for (Parameter param : parametersWithAnnotation(invocation.getInvokable(), QueryParam.class)) {
|
||||
QueryParam queryParam = param.getAnnotation(QueryParam.class);
|
||||
String paramKey = queryParam.value();
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class),
|
||||
param.hashCode(), paramKey);
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class), param.hashCode(),
|
||||
paramKey);
|
||||
if (paramValue.isPresent())
|
||||
if (paramValue.get() instanceof Iterable) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -794,8 +794,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
for (Parameter param : parametersWithAnnotation(invocation.getInvokable(), PayloadParam.class)) {
|
||||
PayloadParam payloadParam = param.getAnnotation(PayloadParam.class);
|
||||
String paramKey = payloadParam.value();
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class),
|
||||
param.hashCode(), paramKey);
|
||||
Optional<?> paramValue = getParamValue(invocation, param.getAnnotation(ParamParser.class), param.hashCode(),
|
||||
paramKey);
|
||||
if (paramValue.isPresent())
|
||||
payloadParamValues.put(paramKey, paramValue.get());
|
||||
}
|
||||
|
@ -804,12 +804,8 @@ public class RestAnnotationProcessor<A> implements Function<Invocation, Generate
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
String callerString = null;
|
||||
if (callerEnclosingType != null) {
|
||||
callerString = String.format("%s.%s%s", callerEnclosingType.getRawType().getSimpleName(), caller
|
||||
.getInvokable().getName(), caller.getArgs());
|
||||
}
|
||||
return Objects.toStringHelper("").omitNullValues().add("caller", callerString)
|
||||
.add("enclosingType", enclosingType.getRawType().getSimpleName()).toString();
|
||||
String callerString = String.format("%s.%s%s", caller.getInvokable().getOwnerType().getRawType().getSimpleName(),
|
||||
caller.getInvokable().getName(), caller.getArgs());
|
||||
return Objects.toStringHelper("").omitNullValues().add("caller", callerString).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ import org.jclouds.http.functions.ReturnTrueIf2xx;
|
|||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.json.internal.GsonWrapper;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
|
@ -62,36 +61,32 @@ import org.jclouds.rest.annotations.XMLResponseParser;
|
|||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
public class TransformerForRequest<A> implements Function<GeneratedHttpRequest<A>, Function<HttpResponse, ?>> {
|
||||
public class TransformerForRequest implements Function<GeneratedHttpRequest, Function<HttpResponse, ?>> {
|
||||
private final ParseSax.Factory parserFactory;
|
||||
private final Injector injector;
|
||||
private final GetAcceptHeaders<A> getAcceptHeaders;
|
||||
private final Class<A> enclosingType;
|
||||
private final GetAcceptHeaders getAcceptHeaders;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
TransformerForRequest(Injector injector, Factory parserFactory, GetAcceptHeaders<A> getAcceptHeaders,
|
||||
TypeLiteral<A> enclosingType) {
|
||||
TransformerForRequest(Injector injector, Factory parserFactory, GetAcceptHeaders getAcceptHeaders) {
|
||||
this.injector = injector;
|
||||
this.parserFactory = parserFactory;
|
||||
this.getAcceptHeaders = getAcceptHeaders;
|
||||
this.enclosingType = (Class<A>) enclosingType.getRawType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Function<HttpResponse, ?> apply(GeneratedHttpRequest<A> request) {
|
||||
public Function<HttpResponse, ?> apply(GeneratedHttpRequest request) {
|
||||
Function<HttpResponse, ?> transformer;
|
||||
Class<? extends HandlerWithResult<?>> handler = TransformerForRequest.getSaxResponseParserClassOrNull(request
|
||||
.getInvocation().getInvokable());
|
||||
Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(request.getInvocation()
|
||||
.getInvokable());
|
||||
if (handler != null) {
|
||||
transformer = parserFactory.create(injector.getInstance(handler));
|
||||
} else {
|
||||
|
@ -228,9 +223,4 @@ public class TransformerForRequest<A> implements Function<GeneratedHttpRequest<A
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("").omitNullValues().add("enclosingType", enclosingType.getSimpleName()).toString();
|
||||
}
|
||||
}
|
|
@ -24,13 +24,12 @@ import java.util.List;
|
|||
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -61,7 +60,7 @@ public class BaseHandlerTest {
|
|||
} catch (NoSuchMethodException e) {
|
||||
throw propagate(e);
|
||||
}
|
||||
request = GeneratedHttpRequest.builder(TypeToken.of(String.class)).method("POST").endpoint("http://localhost/key").invocation(toString)
|
||||
request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key").invocation(toString)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -72,7 +71,7 @@ public class BaseHandlerTest {
|
|||
}
|
||||
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
return GeneratedHttpRequest.builder(TypeToken.of(String.class)).method("POST").endpoint("http://localhost/key")
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key")
|
||||
.invocation(Invocation.create(toString.getInvokable(), args)).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
@Test(groups = "unit", testName = "BackoffLimitedRetryHandlerTest")
|
||||
public class BackoffLimitedRetryHandlerTest {
|
||||
|
@ -123,8 +121,8 @@ public class BackoffLimitedRetryHandlerTest {
|
|||
assertEquals(response.getPayload().getInput().read(), -1);
|
||||
}
|
||||
|
||||
private final RestAnnotationProcessor<IntegrationTestAsyncClient> processor = BaseJettyTest.newBuilder(8100, new Properties()).buildInjector()
|
||||
.getInstance(Key.get(new TypeLiteral<RestAnnotationProcessor<IntegrationTestAsyncClient>>(){}));
|
||||
private final RestAnnotationProcessor processor = BaseJettyTest.newBuilder(8100, new Properties()).buildInjector()
|
||||
.getInstance(RestAnnotationProcessor.class);
|
||||
|
||||
private HttpCommand createCommand() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, Object> method = Invokable.from(IntegrationTestAsyncClient.class.getMethod("download", String.class));
|
||||
|
|
|
@ -33,18 +33,15 @@ import org.jclouds.io.Payload;
|
|||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.TransformerForRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.TypeParameter;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -61,17 +58,10 @@ public abstract class BaseParserTest<T, G> {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Function<HttpResponse, T> parser(Injector i) {
|
||||
TypeToken<TransformerForRequest<T>> token = new TypeToken<TransformerForRequest<T>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<T>() {
|
||||
}, new TypeToken<T>(getClass()) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
});
|
||||
Key<TransformerForRequest<T>> xform = (Key<TransformerForRequest<T>>) Key.get(token.getType());
|
||||
try {
|
||||
return (Function<HttpResponse, T>) i
|
||||
.createChildInjector(new SaxParserModule())
|
||||
.getInstance(xform)
|
||||
.getInstance(TransformerForRequest.class)
|
||||
.getTransformerForMethod(
|
||||
Invocation.create(Invokable.from(getClass().getMethod("expected")), ImmutableList.of()), i);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -36,8 +36,6 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
@Test(groups = "unit")
|
||||
public class InputParamValidatorTest {
|
||||
|
@ -106,7 +104,7 @@ public class InputParamValidatorTest {
|
|||
}
|
||||
|
||||
Injector injector;
|
||||
RestAnnotationProcessor<IntegrationTestAsyncClient> restAnnotationProcessor;
|
||||
RestAnnotationProcessor restAnnotationProcessor;
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
|
@ -114,7 +112,6 @@ public class InputParamValidatorTest {
|
|||
.newBuilder(
|
||||
AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(IntegrationTestClient.class, IntegrationTestAsyncClient.class,
|
||||
"http://localhost:9999")).buildInjector();
|
||||
restAnnotationProcessor = injector.getInstance(Key.get(new TypeLiteral<RestAnnotationProcessor<IntegrationTestAsyncClient>>(){}));
|
||||
restAnnotationProcessor = injector.getInstance(RestAnnotationProcessor.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,11 +57,11 @@ public class BindMapToStringPayloadTest {
|
|||
@Test
|
||||
public void testCorrect() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, Object> testPayload = Invokable.from(TestPayload.class.getMethod("testPayload", String.class));
|
||||
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.builder(TypeToken.of(TestPayload.class))
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(testPayload, ImmutableList.<Object> of("robot")))
|
||||
.method("POST").endpoint("http://localhost").build();
|
||||
|
||||
GeneratedHttpRequest<TestPayload> newRequest = binder().bindToRequest(request,
|
||||
GeneratedHttpRequest newRequest = binder().bindToRequest(request,
|
||||
ImmutableMap.<String, Object> of("fooble", "robot"));
|
||||
|
||||
assertEquals(newRequest.getRequestLine(), request.getRequestLine());
|
||||
|
@ -71,11 +71,11 @@ public class BindMapToStringPayloadTest {
|
|||
@Test
|
||||
public void testDecodes() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, Object> testPayload = Invokable.from(TestPayload.class.getMethod("changeAdminPass", String.class));
|
||||
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.builder(TypeToken.of(TestPayload.class))
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(testPayload, ImmutableList.<Object> of("foo")))
|
||||
.method("POST").endpoint("http://localhost").build();
|
||||
|
||||
GeneratedHttpRequest<TestPayload> newRequest = binder()
|
||||
GeneratedHttpRequest newRequest = binder()
|
||||
.bindToRequest(request, ImmutableMap.<String,Object>of("adminPass", "foo"));
|
||||
|
||||
assertEquals(newRequest.getRequestLine(), request.getRequestLine());
|
||||
|
@ -85,7 +85,7 @@ public class BindMapToStringPayloadTest {
|
|||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testMustHavePayloadAnnotation() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, Object> noPayload = Invokable.from(TestPayload.class.getMethod("noPayload", String.class));
|
||||
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.builder(TypeToken.of(TestPayload.class))
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(noPayload, ImmutableList.<Object> of("robot")))
|
||||
.method("POST").endpoint("http://localhost").build();
|
||||
binder().bindToRequest(request, ImmutableMap.<String,Object>of("fooble", "robot"));
|
||||
|
|
|
@ -33,10 +33,8 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
|
@ -46,7 +44,7 @@ import com.google.inject.Module;
|
|||
@Test(groups = "unit")
|
||||
public abstract class BaseAsyncApiTest<T> extends BaseRestApiTest {
|
||||
|
||||
protected RestAnnotationProcessor<T> processor;
|
||||
protected RestAnnotationProcessor processor;
|
||||
|
||||
protected abstract void checkFilters(HttpRequest request);
|
||||
|
||||
|
@ -65,16 +63,11 @@ public abstract class BaseAsyncApiTest<T> extends BaseRestApiTest {
|
|||
protected void setupFactory() throws IOException {
|
||||
injector = createInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
processor = injector.getInstance(rapKey);
|
||||
processor = injector.getInstance(RestAnnotationProcessor.class);
|
||||
}
|
||||
|
||||
protected String identity = "identity";
|
||||
protected String credential = "credential";
|
||||
@SuppressWarnings("unchecked")
|
||||
Key<RestAnnotationProcessor<T>> rapKey = (Key<RestAnnotationProcessor<T>>) Key
|
||||
.get(new TypeToken<RestAnnotationProcessor<T>>(getClass()) {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.getType());
|
||||
|
||||
/**
|
||||
* @see org.jclouds.providers.Providers#withId
|
||||
|
|
|
@ -50,12 +50,9 @@ import com.google.common.collect.Multimap;
|
|||
import com.google.common.collect.SortedSetMultimap;
|
||||
import com.google.common.collect.TreeMultimap;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeParameter;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.ListeningExecutorService;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -179,25 +176,6 @@ public abstract class BaseRestApiTest {
|
|||
|
||||
protected void assertResponseParserClassEquals(Invokable<?, ?> method, GeneratedHttpRequest request,
|
||||
@Nullable Class<?> parserClass) {
|
||||
assertEquals(transformer(method.getDeclaringClass()).apply(request).getClass(), parserClass);
|
||||
assertEquals(injector.getInstance(TransformerForRequest.class).apply(request).getClass(), parserClass);
|
||||
}
|
||||
|
||||
protected <T> RestAnnotationProcessor<T> processor(Class<T> type) {
|
||||
TypeToken<RestAnnotationProcessor<T>> token = new TypeToken<RestAnnotationProcessor<T>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<T>() {
|
||||
}, type);
|
||||
Key<RestAnnotationProcessor<T>> rapKey = (Key<RestAnnotationProcessor<T>>) Key.get(token.getType());
|
||||
return injector.getInstance(rapKey);
|
||||
}
|
||||
|
||||
protected <T> TransformerForRequest<T> transformer(Class<T> type) {
|
||||
TypeToken<TransformerForRequest<T>> token = new TypeToken<TransformerForRequest<T>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<T>() {
|
||||
}, type);
|
||||
Key<TransformerForRequest<T>> rapKey = (Key<TransformerForRequest<T>>) Key.get(token.getType());
|
||||
return injector.getInstance(rapKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,22 +82,21 @@ public class BlockOnFutureTest {
|
|||
}
|
||||
|
||||
public void testUnnamedMethodWithDefaultPropTimeout() throws Exception {
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L),
|
||||
enclosingType, get);
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L), get);
|
||||
assertEquals(withOverride.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
||||
public void testUnnamedMethodWithClassPropTimeout() throws Exception {
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 50L,
|
||||
"ThingApi", 250L), enclosingType, get);
|
||||
"ThingApi", 250L), get);
|
||||
assertEquals(withOverride.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
||||
public void testUnnamedMethodWithMethodPropTimeout() throws Exception {
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 50L,
|
||||
"ThingApi", 100L, "ThingApi.get", 250L), enclosingType, get);
|
||||
"ThingApi", 100L, "ThingApi.get", 250L), get);
|
||||
assertEquals(withOverride.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
@ -108,23 +107,21 @@ public class BlockOnFutureTest {
|
|||
expect(future.get()).andReturn("foo");
|
||||
replay(future);
|
||||
|
||||
Function<ListenableFuture<?>, Object> noOverrides = new BlockOnFuture(ImmutableMap.<String, Long> of(),
|
||||
enclosingType, get);
|
||||
Function<ListenableFuture<?>, Object> noOverrides = new BlockOnFuture(ImmutableMap.<String, Long> of(), get);
|
||||
|
||||
assertEquals(noOverrides.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
||||
public void testNamedMethodWithDefaultPropTimeout() throws Exception {
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L),
|
||||
enclosingType, namedGet);
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L), namedGet);
|
||||
assertEquals(withOverride.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
||||
public void testNamedMethodWithMethodPropTimeout() throws Exception {
|
||||
Function<ListenableFuture<?>, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 50L,
|
||||
"ThingApi", 100L, "ns:get", 250L), enclosingType, namedGet);
|
||||
"ThingApi", 100L, "ns:get", 250L), namedGet);
|
||||
assertEquals(withOverride.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
@ -135,11 +132,10 @@ public class BlockOnFutureTest {
|
|||
expect(future.get()).andReturn("foo");
|
||||
replay(future);
|
||||
|
||||
Function<ListenableFuture<?>, Object> noOverrides = new BlockOnFuture(ImmutableMap.<String, Long> of(),
|
||||
enclosingType, namedGet);
|
||||
Function<ListenableFuture<?>, Object> noOverrides = new BlockOnFuture(ImmutableMap.<String, Long> of(), namedGet);
|
||||
|
||||
assertEquals(noOverrides.apply(future), "foo");
|
||||
verify(future);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -143,7 +143,6 @@ import com.google.common.collect.Lists;
|
|||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -499,7 +498,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testQuery() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("foo"));
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&x-ms-rubbish=bin");
|
||||
|
@ -508,7 +507,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testQuery2() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("foo2"));
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=bar&fooble=baz");
|
||||
|
@ -517,7 +516,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testQuery3() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("foo3", String.class));
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("wonder"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
|
@ -528,12 +527,12 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{robbie\\} for invocation TestQuery.foo3")
|
||||
public void testNiceNPEQueryParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("foo3", String.class));
|
||||
processor(TestQuery.class).createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
processor.createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
}
|
||||
|
||||
public void testNoNPEOnQueryParamWithNullable() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("foo3Nullable", String.class));
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
Lists.<Object> newArrayList((String) null));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
|
@ -544,7 +543,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testQueryParamIterableOneString() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class));
|
||||
Set<String> bars = ImmutableSortedSet.<String> of("1");
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList.<Object> of(bars));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(bars));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=1");
|
||||
|
@ -554,7 +553,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testQueryParamIterableString() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class));
|
||||
Set<String> bars = ImmutableSortedSet.<String> of("1", "2", "3");
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList.<Object> of(bars));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(bars));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=1&foo=2&foo=3");
|
||||
|
@ -564,7 +563,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testQueryParamIterableInteger() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class));
|
||||
Set<Integer> bars = ImmutableSortedSet.<Integer> of(1, 2, 3);
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList.<Object> of(bars));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(bars));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17&foo=1&foo=2&foo=3");
|
||||
|
@ -574,7 +573,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testQueryParamIterableEmpty() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class));
|
||||
Set<String> bars = Collections.emptySet();
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList.<Object> of(bars));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(bars));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "x-ms-version=2009-07-17");
|
||||
|
@ -583,7 +582,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testQueryParamIterableNull() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQuery.class.getMethod("queryParamIterable", Iterable.class));
|
||||
GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
Lists.<Object> newArrayList((String) null));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
|
@ -612,7 +611,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testHttpRequestOptionsNoPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post"));
|
||||
GeneratedHttpRequest request = processor(TestPayloadParamVarargs.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "", "application/octet-stream", false);
|
||||
|
@ -637,7 +636,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testHttpRequestOptionsPayloadParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayloadParamVarargs.class.getMethod("post", Payload.class));
|
||||
GeneratedHttpRequest request = processor(TestPayloadParamVarargs.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(Payloads.newStringPayload("foo")));
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -647,7 +646,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testHttpRequestWithOnlyContentType() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable
|
||||
.from(TestPayloadParamVarargs.class.getMethod("post", HttpRequestOptions.class));
|
||||
GeneratedHttpRequest request = processor(TestPayloadParamVarargs.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(new TestHttpRequestOptions().payload("fooya")));
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -657,7 +656,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testHeaderAndQueryVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargs",
|
||||
HttpRequestOptions[].class));
|
||||
GeneratedHttpRequest request = processor(TestPayloadParamVarargs.class).createRequest(
|
||||
GeneratedHttpRequest request = processor.createRequest(
|
||||
method,
|
||||
ImmutableList.<Object> of(new TestHttpRequestOptions().payload("fooya"),
|
||||
new TestHttpRequestOptions().headerParams(ImmutableMultimap.of("X-header-1", "fooya")),
|
||||
|
@ -670,7 +669,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testHeaderAndQueryVarargsPlusReq() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargsWithReq", String.class,
|
||||
HttpRequestOptions[].class));
|
||||
GeneratedHttpRequest request = processor(TestPayloadParamVarargs.class).createRequest(
|
||||
GeneratedHttpRequest request = processor.createRequest(
|
||||
method,
|
||||
ImmutableList.<Object> of("required param", new TestHttpRequestOptions().payload("fooya"),
|
||||
new TestHttpRequestOptions().headerParams(ImmutableMultimap.of("X-header-1", "fooya")),
|
||||
|
@ -683,7 +682,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testDuplicateHeaderAndQueryVarargs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayloadParamVarargs.class.getMethod("varargs",
|
||||
HttpRequestOptions[].class));
|
||||
GeneratedHttpRequest request = processor(TestPayloadParamVarargs.class).createRequest(
|
||||
GeneratedHttpRequest request = processor.createRequest(
|
||||
method,
|
||||
ImmutableList.<Object> of(new TestHttpRequestOptions().queryParams(ImmutableMultimap.of("key", "value")),
|
||||
new TestHttpRequestOptions().payload("fooya"),
|
||||
|
@ -704,7 +703,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCustomMethod() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestCustomMethod.class.getMethod("foo"));
|
||||
GeneratedHttpRequest request = processor(TestCustomMethod.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "");
|
||||
assertEquals(request.getMethod(), "FOO");
|
||||
|
@ -722,7 +721,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testOverriddenMethod() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestOverridden.class.getMethod("foo"));
|
||||
GeneratedHttpRequest request = processor(TestOverridden.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "");
|
||||
assertEquals(request.getMethod(), "POST");
|
||||
|
@ -742,7 +741,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestOverriddenEndpoint.class.getMethod("foo"));
|
||||
GeneratedHttpRequest request = processor(TestOverriddenEndpoint.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPort(), 1111);
|
||||
assertEquals(request.getEndpoint().getPath(), "");
|
||||
|
@ -751,7 +750,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testOverriddenEndpointParameter() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestOverriddenEndpoint.class.getMethod("foo", URI.class));
|
||||
GeneratedHttpRequest request = processor(TestOverriddenEndpoint.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(URI.create("http://wowsa:8001")));
|
||||
assertEquals(request.getEndpoint().getHost(), "wowsa");
|
||||
assertEquals(request.getEndpoint().getPort(), 8001);
|
||||
|
@ -794,7 +793,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePostRequest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("post", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -803,7 +802,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePostRequestNullOk1() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("post", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -812,7 +811,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePostRequestNullOk2() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("post", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
Lists.<Object> newArrayList((String) null));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
|
@ -823,7 +822,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testCreatePostRequestNullNotOk1() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("postNonnull", String.class));
|
||||
try {
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
Assert.fail("call should have failed with illegal null parameter, not permitted " + request + " to be created");
|
||||
} catch (NullPointerException e) {
|
||||
Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0,
|
||||
|
@ -834,12 +833,12 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "postNonnull parameter 1")
|
||||
public void testCreatePostRequestNullNotOk2() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("postNonnull", String.class));
|
||||
processor(TestPost.class).createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
processor.createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
}
|
||||
|
||||
public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("postAsJson", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -848,7 +847,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("postWithPath", String.class, MapBinder.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("data", new org.jclouds.rest.MapBinder() {
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
|
||||
|
@ -867,7 +866,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("postWithMethodBinder", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -877,7 +876,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testCreatePostWithMethodBinderAndDefaults() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable
|
||||
.from(TestPost.class.getMethod("postWithMethodBinderAndDefaults", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -886,7 +885,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePostWithPayload() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPost.class.getMethod("testPayload", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPost.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -915,7 +914,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testMultipartWithStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestMultipartForm.class.getMethod("withStringPart", String.class));
|
||||
GeneratedHttpRequest httpRequest = processor(TestMultipartForm.class).createRequest(method,
|
||||
GeneratedHttpRequest httpRequest = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("foobledata"));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
|
@ -930,13 +929,13 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "fooble")
|
||||
public void testMultipartWithStringPartNullNotOkay() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestMultipartForm.class.getMethod("withStringPart", String.class));
|
||||
processor(TestMultipartForm.class).createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
processor.createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
}
|
||||
|
||||
public void testMultipartWithParamStringPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestMultipartForm.class.getMethod("withParamStringPart", String.class,
|
||||
String.class));
|
||||
GeneratedHttpRequest httpRequest = processor(TestMultipartForm.class).createRequest(method,
|
||||
GeneratedHttpRequest httpRequest = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("name", "foobledata"));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
|
@ -956,7 +955,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testMultipartWithParamStringPartNullNotOk() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestMultipartForm.class.getMethod("withParamStringPart", String.class,
|
||||
String.class));
|
||||
processor(TestMultipartForm.class).createRequest(method, Lists.<Object> newArrayList(null, "foobledata"));
|
||||
processor.createRequest(method, Lists.<Object> newArrayList(null, "foobledata"));
|
||||
}
|
||||
|
||||
public void testMultipartWithParamFilePart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
@ -966,7 +965,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Files.append("foobledata", file, UTF_8);
|
||||
file.deleteOnExit();
|
||||
|
||||
GeneratedHttpRequest httpRequest = processor(TestMultipartForm.class).createRequest(method,
|
||||
GeneratedHttpRequest httpRequest = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("name", file));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
|
@ -985,7 +984,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testMultipartWithParamByteArrayPart() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestMultipartForm.class.getMethod("withParamByteArrayBinaryPart",
|
||||
String.class, byte[].class));
|
||||
GeneratedHttpRequest httpRequest = processor(TestMultipartForm.class).createRequest(method,
|
||||
GeneratedHttpRequest httpRequest = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("name", "goo".getBytes()));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
|
@ -1009,7 +1008,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Files.write(new byte[] { 17, 26, 39, 40, 50 }, file);
|
||||
file.deleteOnExit();
|
||||
|
||||
GeneratedHttpRequest httpRequest = processor(TestMultipartForm.class).createRequest(method,
|
||||
GeneratedHttpRequest httpRequest = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("name", file));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
|
@ -1139,7 +1138,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testAlternateHttpMethod() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("rowdy", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "ROWDY http://localhost:9999/strings/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1148,7 +1147,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testAlternateHttpMethodSameArity() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("rowdy", int.class));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "ROWDY http://localhost:9999/ints/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1157,7 +1156,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("putWithMethodBinder", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1166,7 +1165,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePutWithMethodProduces() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("putWithMethodBinderProduces", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1176,14 +1175,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testCreatePutWithMethodConsumes() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("putWithMethodBinderConsumes", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.<Object> of("data"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("data"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||
assertPayloadEquals(request, "{\"fooble\":\"data\"}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseJson.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
View.class.cast(parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build())).foo,
|
||||
|
@ -1194,10 +1193,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testGeneric1() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testGeneric"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseJson.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build()),
|
||||
|
@ -1208,10 +1207,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testGeneric2() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testGeneric2"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseJson.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build()),
|
||||
|
@ -1222,10 +1221,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testGeneric3() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testGeneric3"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseJson.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build()),
|
||||
|
@ -1236,10 +1235,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testUnwrap1() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testUnwrap"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build()), "bar");
|
||||
|
@ -1249,10 +1248,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testUnwrapValueNamed() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testUnwrapValueNamed"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseFirstJsonValueNamed.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build()), "bar");
|
||||
|
@ -1261,17 +1260,17 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testWrapWith() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testWrapWith", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.<Object> of("bar"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("bar"));
|
||||
assertPayloadEquals(request, "{\"foo\":\"bar\"}", "application/json", false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testUnwrap2() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testUnwrap2"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload("{ foo:\"bar\"}").build()), "bar");
|
||||
|
@ -1281,10 +1280,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testUnwrap3() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testUnwrap3"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok")
|
||||
|
@ -1294,10 +1293,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testUnwrap4() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("testUnwrap4"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok")
|
||||
|
@ -1307,10 +1306,10 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void selectLong() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("selectLong"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseFirstJsonValueNamed.class);
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok")
|
||||
|
@ -1320,8 +1319,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@SuppressWarnings("unchecked")
|
||||
public void selectLongAddOne() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPut.class.getMethod("selectLongAddOne"));
|
||||
GeneratedHttpRequest request = processor(TestPut.class).createRequest(method, ImmutableList.of());
|
||||
Function<HttpResponse, ?> parser = transformer(TestPut.class).apply(request);
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
Function<HttpResponse, ?> parser = transformer.apply(request);
|
||||
|
||||
assertEquals(
|
||||
parser.apply(HttpResponse.builder().statusCode(200).message("ok")
|
||||
|
@ -1359,7 +1358,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testRequestFilter() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequestFilter.class.getMethod("get"));
|
||||
GeneratedHttpRequest request = processor(TestRequestFilter.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getFilters().size(), 2);
|
||||
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class);
|
||||
assertEquals(request.getFilters().get(1).getClass(), TestRequestFilter2.class);
|
||||
|
@ -1367,14 +1366,14 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testRequestFilterOverride() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequestFilter.class.getMethod("getOverride"));
|
||||
GeneratedHttpRequest request = processor(TestRequestFilter.class).createRequest(method, ImmutableList.of());
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of());
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter2.class);
|
||||
}
|
||||
|
||||
public void testRequestFilterOverrideOnRequest() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequestFilter.class.getMethod("getOverride", HttpRequest.class));
|
||||
GeneratedHttpRequest request = processor(TestRequestFilter.class).createRequest(
|
||||
GeneratedHttpRequest request = processor.createRequest(
|
||||
method,
|
||||
ImmutableList.<Object> of(HttpRequest.builder().method("GET").endpoint("http://localhost")
|
||||
.addHeader("foo", "bar").build()));
|
||||
|
@ -1393,7 +1392,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testSkipEncoding() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestEncoding.class.getMethod("twoPaths", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestEncoding.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", "localhost"));
|
||||
assertEquals(request.getEndpoint().getPath(), "/1/localhost");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
|
@ -1403,7 +1402,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testEncodingPath() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestEncoding.class.getMethod("twoPaths", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestEncoding.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("/", "localhost"));
|
||||
assertEquals(request.getEndpoint().getPath(), "///localhost");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
|
@ -1425,7 +1424,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testConstantPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestConstantPathParam.class.getMethod("twoPaths", String.class,
|
||||
String.class));
|
||||
GeneratedHttpRequest request = processor(TestConstantPathParam.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", "localhost"));
|
||||
assertRequestLineEquals(request, "GET http://localhost:9999/v1/ralphie/1/localhost HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1472,13 +1471,13 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{path\\} for invocation TestPath.onePath")
|
||||
public void testNiceNPEPathParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPath.class.getMethod("onePath", String.class));
|
||||
processor(TestPath.class).createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
processor.createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathParamExtractor() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPath.class.getMethod("onePathParamExtractor", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPath.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("localhost"));
|
||||
assertRequestLineEquals(request, "GET http://localhost:9999/l HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1488,7 +1487,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testQueryParamExtractor() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPath.class.getMethod("oneQueryParamExtractor", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPath.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("localhost"));
|
||||
assertRequestLineEquals(request, "GET http://localhost:9999/?one=l HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1498,7 +1497,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPath.class.getMethod("oneFormParamExtractor", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPath.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("localhost"));
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1508,7 +1507,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "param\\{one\\} for invocation TestPath.oneFormParamExtractor")
|
||||
public void testNiceNPEFormParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPath.class.getMethod("oneFormParamExtractor", String.class));
|
||||
processor(TestPath.class).createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
processor.createRequest(method, Lists.<Object> newArrayList((String) null));
|
||||
}
|
||||
|
||||
static class FirstCharacter implements Function<Object, String> {
|
||||
|
@ -1552,7 +1551,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildTwoHeader() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeader.class.getMethod("twoHeader", String.class));
|
||||
Multimap<String, String> headers = processor(TestHeader.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot")).getHeaders();
|
||||
assertEquals(headers.size(), 2);
|
||||
assertEquals(headers.get("slash"), ImmutableList.of("/robot"));
|
||||
|
@ -1570,7 +1569,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildOneClassHeader() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestClassHeader.class.getMethod("oneHeader", String.class));
|
||||
Multimap<String, String> headers = processor(TestClassHeader.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot")).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/robot"));
|
||||
|
@ -1579,7 +1578,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildOneHeader() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeader.class.getMethod("oneHeader", String.class));
|
||||
Multimap<String, String> headers = processor(TestHeader.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot")).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/robot"));
|
||||
|
@ -1588,7 +1587,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildTwoHeaders() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeader.class.getMethod("twoHeaders", String.class, String.class));
|
||||
Multimap<String, String> headers = processor(TestHeader.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot", "eggs")).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/robot/eggs"));
|
||||
|
@ -1598,7 +1597,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testBuildTwoHeadersOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeader.class.getMethod("twoHeadersOutOfOrder", String.class,
|
||||
String.class));
|
||||
Multimap<String, String> headers = processor(TestHeader.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot", "eggs")).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("x-amz-copy-source"), ImmutableList.of("/eggs/robot"));
|
||||
|
@ -1614,7 +1613,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testQueryInOptions() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQueryReplace.class.getMethod("queryInOptions", String.class,
|
||||
TestReplaceQueryOptions.class));
|
||||
String query = processor(TestQueryReplace.class)
|
||||
String query = processor
|
||||
.createRequest(method, ImmutableList.<Object> of("robot", new TestReplaceQueryOptions())).getEndpoint()
|
||||
.getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
|
@ -1655,7 +1654,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildTwoQuery() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQueryReplace.class.getMethod("twoQuery", String.class));
|
||||
String query = processor(TestQueryReplace.class).createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
String query = processor.createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
.getEndpoint().getQuery();
|
||||
assertEquals(query, "slash=/robot&hyphen=-robot");
|
||||
}
|
||||
|
@ -1671,7 +1670,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildOneClassQuery() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestClassQuery.class.getMethod("oneQuery", String.class));
|
||||
String query = processor(TestClassQuery.class).createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
String query = processor.createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
.getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
@ -1679,7 +1678,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildOneQuery() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQueryReplace.class.getMethod("oneQuery", String.class));
|
||||
String query = processor(TestQueryReplace.class).createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
String query = processor.createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
.getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
@ -1688,7 +1687,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testBuildTwoQuerys() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable
|
||||
.from(TestQueryReplace.class.getMethod("twoQuerys", String.class, String.class));
|
||||
String query = processor(TestQueryReplace.class)
|
||||
String query = processor
|
||||
.createRequest(method, ImmutableList.<Object> of("robot", "eggs")).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
@ -1697,7 +1696,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testBuildTwoQuerysOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestQueryReplace.class.getMethod("twoQuerysOutOfOrder", String.class,
|
||||
String.class));
|
||||
String query = processor(TestQueryReplace.class)
|
||||
String query = processor
|
||||
.createRequest(method, ImmutableList.<Object> of("robot", "eggs")).getEndpoint().getQuery();
|
||||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
@ -1733,7 +1732,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testPutPayloadEnclosing() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class));
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(new PayloadEnclosingImpl(newStringPayload("whoops"))));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1744,7 +1743,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", PayloadEnclosing.class));
|
||||
PayloadEnclosing payloadEnclosing = new PayloadEnclosingImpl(newStringPayload("whoops"));
|
||||
calculateMD5(payloadEnclosing);
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payloadEnclosing));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1759,7 +1758,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
newInputStreamPayload(Strings2.toInputStream("whoops")));
|
||||
|
||||
calculateMD5(payloadEnclosing);
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payloadEnclosing));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1769,7 +1768,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testPutPayloadChunkedNoContentLength() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("putXfer", Payload.class));
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(newStringPayload("whoops")));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Transfer-Encoding: chunked\n");
|
||||
|
@ -1778,7 +1777,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testPutPayload() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(newStringPayload("whoops")));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1789,7 +1788,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
Payload payload = newStringPayload("whoops");
|
||||
payload.getContentMetadata().setContentDisposition("attachment; filename=photo.jpg");
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payload));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1800,7 +1799,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
Payload payload = newStringPayload("whoops");
|
||||
payload.getContentMetadata().setContentEncoding("gzip");
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payload));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1811,7 +1810,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
Payload payload = newStringPayload("whoops");
|
||||
payload.getContentMetadata().setContentLanguage("en");
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payload));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1823,7 +1822,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Payload payload = newStringPayload("whoops");
|
||||
calculateMD5(payload);
|
||||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payload));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1834,7 +1833,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Payload payload = newInputStreamPayload(Strings2.toInputStream("whoops"));
|
||||
payload.getContentMetadata().setContentLength((long) "whoops".length());
|
||||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payload));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1846,7 +1845,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
Payload payload = newStringPayload("whoops");
|
||||
calculateMD5(payload);
|
||||
Invokable<?, ?> method = Invokable.from(TestTransformers.class.getMethod("put", Payload.class));
|
||||
GeneratedHttpRequest request = processor(TestTransformers.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(payload));
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -1861,7 +1860,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Class<? extends Function<HttpResponse, ?>> unwrap(Class<T> type, Invokable<?, ?> method) {
|
||||
return (Class<? extends Function<HttpResponse, ?>>) transformer(type)
|
||||
return (Class<? extends Function<HttpResponse, ?>>) transformer
|
||||
.getParserOrThrowException(Invocation.create(method, ImmutableList.of())).getTypeLiteral().getRawType();
|
||||
}
|
||||
|
||||
|
@ -1890,14 +1889,13 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
}
|
||||
|
||||
public void oneTransformerWithContext() throws SecurityException, NoSuchMethodException {
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest
|
||||
.builder(TypeToken.of(TestTransformers.class))
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint("http://localhost")
|
||||
.invocation(
|
||||
Invocation.create(Invokable.from(TestTransformers.class.getMethod("oneTransformerWithContext")),
|
||||
ImmutableList.of())).build();
|
||||
Function<HttpResponse, ?> transformer = transformer(TestTransformers.class).apply(request);
|
||||
Function<HttpResponse, ?> transformer = this.transformer.apply(request);
|
||||
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
|
||||
assertEquals(((ReturnStringIf200Context) transformer).request, request);
|
||||
}
|
||||
|
@ -1962,7 +1960,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("get", String.class,
|
||||
HttpRequestOptions[].class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", options));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
|
@ -1978,7 +1976,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class
|
||||
.getMethod("get", String.class, HttpRequestOptions.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", options));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
|
@ -2000,7 +1998,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
PrefixOptions options = new PrefixOptions().withPrefix("1");
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class
|
||||
.getMethod("get", String.class, HttpRequestOptions.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", options));
|
||||
assertRequestLineEquals(request, "GET http://localhost:9999/1?prefix=1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: localhost:9999\n");
|
||||
|
@ -2009,7 +2007,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreateGetQuery() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("getQuery", String.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method, ImmutableList.<Object> of("1"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("1"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
assertEquals(request.getEndpoint().getQuery(), "max-keys=0");
|
||||
|
@ -2019,7 +2017,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("getQueryNull", String.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method, ImmutableList.<Object> of("1"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("1"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
assertEquals(request.getEndpoint().getQuery(), "acl");
|
||||
|
@ -2029,7 +2027,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreateGetQueryEmpty() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("getQueryEmpty", String.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method, ImmutableList.<Object> of("1"));
|
||||
GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("1"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
assertEquals(request.getEndpoint().getQuery(), "acl=");
|
||||
|
@ -2048,7 +2046,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
PayloadOptions options = new PayloadOptions();
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("putOptions", String.class,
|
||||
HttpRequestOptions.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", options));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/1 HTTP/1.1");
|
||||
|
@ -2065,7 +2063,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
|
||||
UnsupportedEncodingException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("get", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(key, "localhost"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
|
||||
|
@ -2078,7 +2076,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePutRequest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("put", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("111", "data"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/1 HTTP/1.1");
|
||||
|
@ -2088,7 +2086,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
public void testCreatePutHeader() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestRequest.class.getMethod("putHeader", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestRequest.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", "data"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/1 HTTP/1.1");
|
||||
|
@ -2108,7 +2106,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestVirtualHostMethod.class.getMethod("get", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestVirtualHostMethod.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", "localhost"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
|
@ -2132,7 +2130,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testVirtualHost() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestVirtualHost.class.getMethod("get", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestVirtualHost.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", "localhost"));
|
||||
assertEquals(request.getEndpoint().getHost(), "localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
|
@ -2144,7 +2142,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testHostPrefix() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestVirtualHost.class.getMethod("getPrefix", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestVirtualHost.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("1", "holy"));
|
||||
assertEquals(request.getEndpoint().getHost(), "holy.localhost");
|
||||
assertEquals(request.getEndpoint().getPath(), "/1");
|
||||
|
@ -2155,7 +2153,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testHostPrefixEmpty() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestVirtualHost.class.getMethod("getPrefix", String.class, String.class));
|
||||
processor(TestVirtualHost.class).createRequest(method, ImmutableList.<Object> of("1", ""));
|
||||
processor.createRequest(method, ImmutableList.<Object> of("1", ""));
|
||||
}
|
||||
|
||||
public interface TestHeaders {
|
||||
|
@ -2175,7 +2173,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testOneHeader() throws SecurityException, NoSuchMethodException, ExecutionException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeaders.class.getMethod("oneHeader", String.class));
|
||||
Multimap<String, String> headers = processor(TestHeaders.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot")).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("header"), ImmutableList.of("robot"));
|
||||
|
@ -2184,7 +2182,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testOneIntHeader() throws SecurityException, NoSuchMethodException, ExecutionException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeaders.class.getMethod("oneIntHeader", int.class));
|
||||
Multimap<String, String> headers = processor(TestHeaders.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of(1)).getHeaders();
|
||||
assertEquals(headers.size(), 1);
|
||||
assertEquals(headers.get("header"), ImmutableList.of("1"));
|
||||
|
@ -2194,7 +2192,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testTwoDifferentHeaders() throws SecurityException, NoSuchMethodException, ExecutionException {
|
||||
Invokable<?, ?> method = Invokable.from(TestHeaders.class.getMethod("twoDifferentHeaders", String.class,
|
||||
String.class));
|
||||
Multimap<String, String> headers = processor(TestHeaders.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot", "egg")).getHeaders();
|
||||
assertEquals(headers.size(), 2);
|
||||
assertEquals(headers.get("header1"), ImmutableList.of("robot"));
|
||||
|
@ -2205,7 +2203,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testTwoSameHeaders() throws SecurityException, NoSuchMethodException, ExecutionException {
|
||||
Invokable<?, ?> method = Invokable
|
||||
.from(TestHeaders.class.getMethod("twoSameHeaders", String.class, String.class));
|
||||
Multimap<String, String> headers = processor(TestHeaders.class).createRequest(method,
|
||||
Multimap<String, String> headers = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("robot", "egg")).getHeaders();
|
||||
assertEquals(headers.size(), 2);
|
||||
Collection<String> values = headers.get("header");
|
||||
|
@ -2278,7 +2276,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testPut() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayload.class.getMethod("put", String.class));
|
||||
GeneratedHttpRequest request = processor(TestPayload.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("test"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999 HTTP/1.1");
|
||||
|
@ -2289,7 +2287,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void putWithPath() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Invokable<?, ?> method = Invokable.from(TestPayload.class.getMethod("putWithPath", String.class, String.class));
|
||||
GeneratedHttpRequest request = processor(TestPayload.class).createRequest(method,
|
||||
GeneratedHttpRequest request = processor.createRequest(method,
|
||||
ImmutableList.<Object> of("rabble", "test"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT http://localhost:9999/rabble HTTP/1.1");
|
||||
|
@ -2338,7 +2336,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildTwoForm() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestFormReplace.class.getMethod("twoForm", String.class));
|
||||
Object form = processor(TestFormReplace.class).createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
Object form = processor.createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
.getPayload().getRawContent();
|
||||
assertEquals(form, "slash=/robot&hyphen=-robot");
|
||||
}
|
||||
|
@ -2394,7 +2392,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestClassForm.class.getMethod("oneForm", String.class));
|
||||
Object form = processor(TestClassForm.class).createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
Object form = processor.createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
.getPayload().getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
@ -2402,7 +2400,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildOneForm() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestFormReplace.class.getMethod("oneForm", String.class));
|
||||
Object form = processor(TestFormReplace.class).createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
Object form = processor.createRequest(method, ImmutableList.<Object> of("robot"))
|
||||
.getPayload().getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/robot");
|
||||
}
|
||||
|
@ -2410,7 +2408,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
@Test
|
||||
public void testBuildTwoForms() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestFormReplace.class.getMethod("twoForms", String.class, String.class));
|
||||
Object form = processor(TestFormReplace.class).createRequest(method, ImmutableList.<Object> of("robot", "eggs"))
|
||||
Object form = processor.createRequest(method, ImmutableList.<Object> of("robot", "eggs"))
|
||||
.getPayload().getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
@ -2419,7 +2417,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void testBuildTwoFormsOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> method = Invokable.from(TestFormReplace.class.getMethod("twoFormsOutOfOrder", String.class,
|
||||
String.class));
|
||||
Object form = processor(TestFormReplace.class).createRequest(method, ImmutableList.<Object> of("robot", "eggs"))
|
||||
Object form = processor.createRequest(method, ImmutableList.<Object> of("robot", "eggs"))
|
||||
.getPayload().getRawContent();
|
||||
assertEquals(form, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
@ -2454,6 +2452,8 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
}
|
||||
|
||||
DateService dateService = new SimpleDateFormatDateService();
|
||||
RestAnnotationProcessor processor;
|
||||
TransformerForRequest transformer;
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
|
@ -2488,5 +2488,7 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
|
||||
})).buildInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
processor = injector.getInstance(RestAnnotationProcessor.class);
|
||||
transformer = injector.getInstance(TransformerForRequest.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class BindToPathTest {
|
|||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testInvalidNullInput() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> withEndpointLink = Invokable.from(TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestEndpointLink.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(new TestDto())))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -73,7 +73,7 @@ public class BindToPathTest {
|
|||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalidInputType() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> withEndpointLink = Invokable.from(TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestEndpointLink.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(new TestDto())))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -86,7 +86,7 @@ public class BindToPathTest {
|
|||
public void testAnnotationNotPresent() throws SecurityException, NoSuchMethodException {
|
||||
TestDto dto = new TestDto();
|
||||
Invokable<?, ?> withoutEndpointLink = Invokable.from(TestEndpointLink.class.getMethod("withoutEndpointLink", TestDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestEndpointLink.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withoutEndpointLink, ImmutableList.<Object> of(dto)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -99,7 +99,7 @@ public class BindToPathTest {
|
|||
public void testLinkNotPresent() throws SecurityException, NoSuchMethodException {
|
||||
TestDto dto = new TestDto();
|
||||
Invokable<?, ?> withUnexistingLink = Invokable.from(TestEndpointLink.class.getMethod("withUnexistingLink", TestDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestEndpointLink.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withUnexistingLink, ImmutableList.<Object> of(dto)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -111,7 +111,7 @@ public class BindToPathTest {
|
|||
public void testBindWithoutParameters() throws SecurityException, NoSuchMethodException {
|
||||
TestDto dto = new TestDto();
|
||||
Invokable<?, ?> withEndpointLink = Invokable.from(TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestEndpointLink.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(dto)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -124,7 +124,7 @@ public class BindToPathTest {
|
|||
public void testBindWithQueryParameters() throws SecurityException, NoSuchMethodException {
|
||||
TestDto dto = new TestDto();
|
||||
Invokable<?, ?> withEndpointLink = Invokable.from(TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestEndpointLink.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(dto)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost?param=value")).build();
|
||||
|
|
|
@ -64,7 +64,7 @@ public class BindMoveVolumeToPathTest {
|
|||
private static GeneratedHttpRequest generatedHttpRequest() throws SecurityException, NoSuchMethodException {
|
||||
Invokable<?, ?> withEndpointLink = Invokable.from(CloudAsyncApi.class.getMethod("moveVolume", VolumeManagementDto.class,
|
||||
VirtualDatacenterDto.class));
|
||||
return GeneratedHttpRequest.builder(CloudAsyncApi.class)
|
||||
return GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(CloudResources.volumePut(), CloudResources.virtualDatacenterPut())))
|
||||
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class BindNetworkConfigurationRefToPayloadTest {
|
|||
|
||||
Invokable<?, ?> method = Invokable.from(TestNetworkConfig.class.getMethod("withAll", VirtualMachineDto.class,
|
||||
VLANNetworkDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestNetworkConfig.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(method, Lists.<Object> newArrayList(vm, null)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -86,7 +86,7 @@ public class BindNetworkConfigurationRefToPayloadTest {
|
|||
|
||||
Invokable<?, ?> method = Invokable.from(TestNetworkConfig.class.getMethod("withAll", VirtualMachineDto.class,
|
||||
VLANNetworkDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestNetworkConfig.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(method, ImmutableList.<Object> of(vm, network)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -101,7 +101,7 @@ public class BindNetworkConfigurationRefToPayloadTest {
|
|||
|
||||
Invokable<?, ?> method = Invokable.from(TestNetworkConfig.class.getMethod("withoutVirtualMachine",
|
||||
VLANNetworkDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestNetworkConfig.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(method, ImmutableList.<Object> of(network)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
@ -116,7 +116,7 @@ public class BindNetworkConfigurationRefToPayloadTest {
|
|||
|
||||
Invokable<?, ?> method = Invokable.from(TestNetworkConfig.class.getMethod("withAll", VirtualMachineDto.class,
|
||||
VLANNetworkDto.class));
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(TestNetworkConfig.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(method, ImmutableList.<Object> of(vm, network)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost")).build();
|
||||
|
|
|
@ -63,7 +63,7 @@ public class BindSupportedDevicesLinkToPathTest {
|
|||
Invokable<?, ?> withEndpointLink = Invokable.from(InfrastructureAsyncApi.class.getMethod(
|
||||
"listSupportedStorageDevices", DatacenterDto.class));
|
||||
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(InfrastructureAsyncApi.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(datacenter)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://foo/bar")).build();
|
||||
|
@ -80,7 +80,7 @@ public class BindSupportedDevicesLinkToPathTest {
|
|||
Invokable<?, ?> withEndpointLink = Invokable.from(InfrastructureAsyncApi.class.getMethod(
|
||||
"listSupportedStorageDevices", DatacenterDto.class));
|
||||
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder(InfrastructureAsyncApi.class)
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder()
|
||||
.invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(datacenter)))
|
||||
.method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://foo/bar")).build();
|
||||
|
|
|
@ -45,7 +45,7 @@ public class OAuthModuleWithoutTypeAdapters extends OAuthModule {
|
|||
protected void configure() {
|
||||
bind(new TypeLiteral<Function<byte[], byte[]>>() {}).to(SignOrProduceMacForToken.class);
|
||||
bind(new TypeLiteral<Supplier<OAuthCredentials>>() {}).to(OAuthCredentialsSupplier.class);
|
||||
bind(new TypeLiteral<Function<GeneratedHttpRequest<?>, TokenRequest>>() {}).to(BuildTokenRequest.class);
|
||||
bind(new TypeLiteral<Function<GeneratedHttpRequest, TokenRequest>>() {}).to(BuildTokenRequest.class);
|
||||
bind(new TypeLiteral<Function<TokenRequest, Token>>() {}).to(FetchToken.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ import static com.google.common.collect.Iterables.tryFind;
|
|||
public abstract class BaseToPagedIterable<T, I extends BaseToPagedIterable<T, I>> implements
|
||||
Function<ListPage<T>, PagedIterable<T>>, InvocationContext<I> {
|
||||
|
||||
private GeneratedHttpRequest<?> request;
|
||||
private GeneratedHttpRequest request;
|
||||
|
||||
@Override
|
||||
public PagedIterable<T> apply(ListPage<T> input) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class OAuthModule extends AbstractModule {
|
|||
Header.class, new HeaderTypeAdapter(),
|
||||
ClaimSet.class, new ClaimSetTypeAdapter()));
|
||||
bind(new TypeLiteral<Supplier<OAuthCredentials>>() {}).to(OAuthCredentialsSupplier.class);
|
||||
bind(new TypeLiteral<Function<GeneratedHttpRequest<?>, TokenRequest>>() {}).to(BuildTokenRequest.class);
|
||||
bind(new TypeLiteral<Function<GeneratedHttpRequest, TokenRequest>>() {}).to(BuildTokenRequest.class);
|
||||
bind(new TypeLiteral<Function<TokenRequest, Token>>() {}).to(FetchToken.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
@Singleton
|
||||
public class OAuthAuthenticator implements HttpRequestFilter {
|
||||
|
||||
private Function<GeneratedHttpRequest<?>, TokenRequest> tokenRequestBuilder;
|
||||
private Function<GeneratedHttpRequest, TokenRequest> tokenRequestBuilder;
|
||||
private Function<TokenRequest, Token> tokenFetcher;
|
||||
|
||||
@Inject
|
||||
OAuthAuthenticator(Function<GeneratedHttpRequest<?>, TokenRequest> tokenRequestBuilder, LoadingCache<TokenRequest,
|
||||
OAuthAuthenticator(Function<GeneratedHttpRequest, TokenRequest> tokenRequestBuilder, LoadingCache<TokenRequest,
|
||||
Token> tokenFetcher) {
|
||||
this.tokenRequestBuilder = tokenRequestBuilder;
|
||||
this.tokenFetcher = tokenFetcher;
|
||||
|
@ -55,7 +55,7 @@ public class OAuthAuthenticator implements HttpRequestFilter {
|
|||
@Override
|
||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
||||
checkState(request instanceof GeneratedHttpRequest, "request must be an instance of GeneratedHttpRequest");
|
||||
GeneratedHttpRequest<?> generatedHttpRequest = GeneratedHttpRequest.class.cast(request);
|
||||
GeneratedHttpRequest generatedHttpRequest = GeneratedHttpRequest.class.cast(request);
|
||||
TokenRequest tokenRequest = tokenRequestBuilder.apply(generatedHttpRequest);
|
||||
Token token = tokenFetcher.apply(tokenRequest);
|
||||
return request.toBuilder().addHeader("Authorization", String.format("%s %s",
|
||||
|
|
|
@ -57,7 +57,7 @@ import com.google.inject.name.Named;
|
|||
* @author David Alves
|
||||
*/
|
||||
@Singleton
|
||||
public class BuildTokenRequest implements Function<GeneratedHttpRequest<?>, TokenRequest> {
|
||||
public class BuildTokenRequest implements Function<GeneratedHttpRequest, TokenRequest> {
|
||||
|
||||
private final String assertionTargetDescription;
|
||||
private final String signatureAlgorithm;
|
||||
|
@ -90,7 +90,7 @@ public class BuildTokenRequest implements Function<GeneratedHttpRequest<?>, Toke
|
|||
}
|
||||
|
||||
@Override
|
||||
public TokenRequest apply(GeneratedHttpRequest<?> request) {
|
||||
public TokenRequest apply(GeneratedHttpRequest request) {
|
||||
long now = TimeUnit.SECONDS.convert(ticker.read(), TimeUnit.NANOSECONDS);
|
||||
|
||||
// fetch the token
|
||||
|
@ -114,10 +114,10 @@ public class BuildTokenRequest implements Function<GeneratedHttpRequest<?>, Toke
|
|||
.build();
|
||||
}
|
||||
|
||||
protected String getOAuthScopes(GeneratedHttpRequest<?> request) {
|
||||
protected String getOAuthScopes(GeneratedHttpRequest request) {
|
||||
Invokable<?, ?> invokable = request.getInvocation().getInvokable();
|
||||
|
||||
OAuthScopes classScopes = request.getEnclosingType().getRawType().getAnnotation(OAuthScopes.class);
|
||||
OAuthScopes classScopes = invokable.getOwnerType().getRawType().getAnnotation(OAuthScopes.class);
|
||||
OAuthScopes methodScopes = invokable.getAnnotation(OAuthScopes.class);
|
||||
|
||||
// if no annotations are present the rely on globally set scopes
|
||||
|
@ -125,7 +125,7 @@ public class BuildTokenRequest implements Function<GeneratedHttpRequest<?>, Toke
|
|||
checkState(globalScopes != null, String.format("REST class or method should be annotated " +
|
||||
"with OAuthScopes specifying required permissions. Alternatively a global property " +
|
||||
"\"oauth.scopes\" may be set to define scopes globally. REST Class: %s, Method: %s",
|
||||
request.getEnclosingType(),
|
||||
invokable.getOwnerType(),
|
||||
invokable.getName()));
|
||||
return globalScopes;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ import com.google.common.reflect.Invokable;
|
|||
*/
|
||||
@Singleton
|
||||
public class AzureBlobRequestSigner implements BlobRequestSigner {
|
||||
private final RestAnnotationProcessor<AzureBlobAsyncClient> processor;
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final BlobToAzureBlob blobToBlob;
|
||||
private final BlobToHttpGetOptions blob2HttpGetOptions;
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class AzureBlobRequestSigner implements BlobRequestSigner {
|
|||
private final Invokable<?, ?> createMethod;
|
||||
|
||||
@Inject
|
||||
public AzureBlobRequestSigner(RestAnnotationProcessor<AzureBlobAsyncClient> processor, BlobToAzureBlob blobToBlob,
|
||||
public AzureBlobRequestSigner(RestAnnotationProcessor processor, BlobToAzureBlob blobToBlob,
|
||||
BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.blobToBlob = checkNotNull(blobToBlob, "blobToBlob");
|
||||
|
|
|
@ -58,6 +58,7 @@ import com.google.common.base.Throwables;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.io.ByteProcessor;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
|
@ -68,7 +69,7 @@ import com.google.inject.Provider;
|
|||
@Singleton
|
||||
public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner {
|
||||
|
||||
private final RestAnnotationProcessor<HPCloudObjectStorageAsyncApi> processor;
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final Crypto crypto;
|
||||
|
||||
private final Provider<Long> unixEpochTimestampProvider;
|
||||
|
@ -83,7 +84,7 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner
|
|||
private final Invokable<?, ?> createMethod;
|
||||
|
||||
@Inject
|
||||
public HPCloudObjectStorageBlobRequestSigner(RestAnnotationProcessor<HPCloudObjectStorageAsyncApi> processor,
|
||||
public HPCloudObjectStorageBlobRequestSigner(RestAnnotationProcessor processor,
|
||||
BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto,
|
||||
@TimeStamp Provider<Long> unixEpochTimestampProvider, Supplier<Access> access,
|
||||
@org.jclouds.location.Provider final Supplier<Credentials> creds) throws SecurityException,
|
||||
|
@ -98,12 +99,13 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner
|
|||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
|
||||
|
||||
this.getMethod = Invokable.from(HPCloudObjectStorageAsyncApi.class.getMethod("getObject", String.class,
|
||||
String.class, GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(HPCloudObjectStorageAsyncApi.class.getMethod("removeObject", String.class,
|
||||
String.class));
|
||||
this.createMethod = Invokable.from(HPCloudObjectStorageAsyncApi.class.getMethod("putObject", String.class,
|
||||
SwiftObject.class));
|
||||
Class<?> interfaceClass = HPCloudObjectStorageAsyncApi.class;
|
||||
TypeToken<?> interfaceType = TypeToken.of(HPCloudObjectStorageAsyncApi.class);
|
||||
|
||||
this.getMethod = interfaceType.method(interfaceClass.getMethod("getObject", String.class, String.class,
|
||||
GetOptions[].class));
|
||||
this.deleteMethod = interfaceType.method(interfaceClass.getMethod("removeObject", String.class, String.class));
|
||||
this.createMethod = interfaceType.method(interfaceClass.getMethod("putObject", String.class, SwiftObject.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,7 +119,7 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner
|
|||
public HttpRequest signGetBlob(String container, String name, long timeInSeconds) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
GeneratedHttpRequest<HPCloudObjectStorageAsyncApi> request = processor.apply(Invocation.create(getMethod,
|
||||
GeneratedHttpRequest request = processor.apply(Invocation.create(getMethod,
|
||||
ImmutableList.<Object> of(container, name)));
|
||||
return cleanRequest(signForTemporaryAccess(request, timeInSeconds));
|
||||
}
|
||||
|
@ -142,7 +144,7 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner
|
|||
public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(blob, "blob");
|
||||
GeneratedHttpRequest<HPCloudObjectStorageAsyncApi> request = processor.apply(Invocation.create(createMethod,
|
||||
GeneratedHttpRequest request = processor.apply(Invocation.create(createMethod,
|
||||
ImmutableList.<Object> of(container, blobToObject.apply(blob))));
|
||||
return cleanRequest(signForTemporaryAccess(request, timeInSeconds));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue