From 04fe89b75a90ae197fca1a5128c52986e5beb100 Mon Sep 17 00:00:00 2001 From: adriancole Date: Fri, 18 Jan 2013 16:02:25 -0800 Subject: [PATCH] update to guava 14.0-rc2 --- .../blobstore/AtmosBlobRequestSigner.java | 4 +- ...loneDriveOptionsToPlainTextStringTest.java | 2 +- .../s3/blobstore/S3BlobRequestSigner.java | 14 +- ...rOperationAbortedWhenBucketExistsTest.java | 4 +- .../swift/blobstore/SwiftBlobSigner.java | 21 +- .../swift/internal/BasePayloadTest.java | 4 +- .../vcloud/internal/BasePayloadTest.java | 4 +- .../blobstore/util/BlobStoreUtilsTest.java | 8 +- .../vcloud_0_8/internal/BasePayloadTest.java | 4 +- core/pom.xml | 2 +- .../internal/CallerArg0ToPagedIterable.java | 2 +- .../org/jclouds/http/functions/ParseSax.java | 4 +- .../jclouds/reflect/FunctionalReflection.java | 3 +- .../rest/binders/BindMapToStringPayload.java | 2 +- .../rest/config/AsyncHttpApiProvider.java | 4 +- .../rest/config/CallGetOnFuturesProvider.java | 4 +- .../jclouds/rest/config/HttpApiProvider.java | 5 +- .../org/jclouds/rest/config/RestModule.java | 2 +- .../org/jclouds/rest/config/SetCaller.java | 19 +- .../jclouds/rest/internal/BlockOnFuture.java | 10 +- .../DelegatesToInvocationFunction.java | 9 +- .../rest/internal/GeneratedHttpRequest.java | 78 ++---- .../rest/internal/GetAcceptHeaders.java | 13 +- .../rest/internal/InvokeHttpMethod.java | 23 +- .../internal/RestAnnotationProcessor.java | 148 +++++----- .../rest/internal/TransformerForRequest.java | 24 +- .../http/functions/BaseHandlerTest.java | 7 +- .../BackoffLimitedRetryHandlerTest.java | 6 +- .../java/org/jclouds/json/BaseParserTest.java | 14 +- .../jclouds/rest/InputParamValidatorTest.java | 7 +- .../binders/BindMapToStringPayloadTest.java | 10 +- .../rest/internal/BaseAsyncApiTest.java | 11 +- .../rest/internal/BaseRestApiTest.java | 24 +- .../rest/internal/BlockOnFutureTest.java | 20 +- .../internal/RestAnnotationProcessorTest.java | 256 +++++++++--------- .../abiquo/binders/BindToPathTest.java | 12 +- .../cloud/BindMoveVolumeToPathTest.java | 2 +- ...dNetworkConfigurationRefToPayloadTest.java | 8 +- .../BindSupportedDevicesLinkToPathTest.java | 4 +- .../OAuthModuleWithoutTypeAdapters.java | 2 +- .../internal/BaseToPagedIterable.java | 2 +- .../jclouds/oauth/v2/config/OAuthModule.java | 2 +- .../oauth/v2/filters/OAuthAuthenticator.java | 6 +- .../oauth/v2/functions/BuildTokenRequest.java | 10 +- .../blobstore/AzureBlobRequestSigner.java | 4 +- ...HPCloudObjectStorageBlobRequestSigner.java | 22 +- 46 files changed, 357 insertions(+), 489 deletions(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java index 829e2ad488..057957d8e6 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java @@ -45,7 +45,7 @@ import com.google.common.reflect.Invokable; */ @Singleton public class AtmosBlobRequestSigner implements BlobRequestSigner { - private final RestAnnotationProcessor 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 processor, BlobToObject blobToObject, + public AtmosBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, BlobToHttpGetOptions blob2ObjectGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java index 9ffb0f0556..e0e3c9aec3 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java @@ -65,7 +65,7 @@ public class BindCloneDriveOptionsToPlainTextStringTest { protected GeneratedHttpRequest requestForArgs(List 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); diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java index 926880a861..0b12c18c29 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java @@ -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 implements BlobRequestSigner { - private final RestAnnotationProcessor processor; + private final RestAnnotationProcessor processor; private final BlobToObject blobToObject; private final BlobToHttpGetOptions blob2HttpGetOptions; @@ -54,16 +55,17 @@ public class S3BlobRequestSigner implements BlobRequest private final Invokable createMethod; @Inject - public S3BlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, - BlobToHttpGetOptions blob2HttpGetOptions, Class interfaceType) throws SecurityException, + public S3BlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, + BlobToHttpGetOptions blob2HttpGetOptions, Class 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 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)); } diff --git a/apis/s3/src/test/java/org/jclouds/s3/fallbacks/FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest.java b/apis/s3/src/test/java/org/jclouds/s3/fallbacks/FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest.java index 8199810664..1885e738af 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/fallbacks/FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/fallbacks/FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest.java @@ -43,11 +43,11 @@ import com.google.common.reflect.Invokable; @Test(testName = "FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest") public class FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest { - GeneratedHttpRequest 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( diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java index 6bbba08148..e01a1fdb67 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobSigner.java @@ -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 implements BlobRequestSigner { - private final RestAnnotationProcessor processor; + private final RestAnnotationProcessor processor; private final Crypto crypto; private final Provider unixEpochTimestampProvider; @@ -85,8 +87,8 @@ public class SwiftBlobSigner implements BlobRe @Inject protected SwiftBlobSigner(BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, @TimeStamp Provider unixEpochTimestampProvider, - @TemporaryUrlKey Supplier temporaryUrlKeySupplier, RestAnnotationProcessor processor, - Class interfaceType) throws SecurityException, NoSuchMethodException { + @TemporaryUrlKey Supplier temporaryUrlKeySupplier, RestAnnotationProcessor processor, + TypeLiteral interfaceType) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.crypto = checkNotNull(crypto, "crypto"); @@ -96,10 +98,13 @@ public class SwiftBlobSigner 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 implements BlobRe public HttpRequest signGetBlob(String container, String name, long timeInSeconds) { checkNotNull(container, "container"); checkNotNull(name, "name"); - GeneratedHttpRequest request = processor.apply(Invocation.create(getMethod, + GeneratedHttpRequest request = processor.apply(Invocation.create(getMethod, ImmutableList. of(container, name))); return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); } @@ -138,7 +143,7 @@ public class SwiftBlobSigner implements BlobRe public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) { checkNotNull(container, "container"); checkNotNull(blob, "blob"); - GeneratedHttpRequest request = processor.apply(Invocation.create(createMethod, + GeneratedHttpRequest request = processor.apply(Invocation.create(createMethod, ImmutableList. of(container, blobToObject.apply(blob)))); return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); } diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BasePayloadTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BasePayloadTest.java index 6b75041476..9503cbac6b 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BasePayloadTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BasePayloadTest.java @@ -43,10 +43,10 @@ public class BasePayloadTest { } }), new GsonModule()); - protected GeneratedHttpRequest requestForArgs(List args) { + protected GeneratedHttpRequest requestForArgs(List 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); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BasePayloadTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BasePayloadTest.java index b01d52e4e6..cdde41b161 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BasePayloadTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/internal/BasePayloadTest.java @@ -40,10 +40,10 @@ public class BasePayloadTest { } })); - protected GeneratedHttpRequest requestForArgs(List args) { + protected GeneratedHttpRequest requestForArgs(List 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); diff --git a/blobstore/src/test/java/org/jclouds/blobstore/util/BlobStoreUtilsTest.java b/blobstore/src/test/java/org/jclouds/blobstore/util/BlobStoreUtilsTest.java index 4fcf3d2212..666c7c5d69 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/util/BlobStoreUtilsTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/util/BlobStoreUtilsTest.java @@ -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. 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. of("adriancole-blobstore0/four")); assertEquals(getNameFor(request), "four"); } - GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List args) { + GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List 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); diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BasePayloadTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BasePayloadTest.java index 31b94d779f..82708e4cbe 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BasePayloadTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BasePayloadTest.java @@ -29,10 +29,10 @@ import com.google.common.reflect.Invokable; public class BasePayloadTest { - protected GeneratedHttpRequest requestForArgs(List args) { + protected GeneratedHttpRequest requestForArgs(List 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); diff --git a/core/pom.xml b/core/pom.xml index 89a0dc3750..bb98c3320c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -91,7 +91,7 @@ com.google.guava guava - 14.0-rc1 + 14.0-rc2 org.osgi diff --git a/core/src/main/java/org/jclouds/collect/internal/CallerArg0ToPagedIterable.java b/core/src/main/java/org/jclouds/collect/internal/CallerArg0ToPagedIterable.java index d1da558336..51f4603f5b 100644 --- a/core/src/main/java/org/jclouds/collect/internal/CallerArg0ToPagedIterable.java +++ b/core/src/main/java/org/jclouds/collect/internal/CallerArg0ToPagedIterable.java @@ -55,7 +55,7 @@ import com.google.common.base.Optional; public abstract class CallerArg0ToPagedIterable> implements Function, PagedIterable>, InvocationContext { - private GeneratedHttpRequest request; + private GeneratedHttpRequest request; @Override public PagedIterable apply(IterableWithMarker input) { diff --git a/core/src/main/java/org/jclouds/http/functions/ParseSax.java b/core/src/main/java/org/jclouds/http/functions/ParseSax.java index 1d03452a3e..0f8796555f 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseSax.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseSax.java @@ -214,8 +214,8 @@ public class ParseSax implements Function, InvocationContext } @Override - protected GeneratedHttpRequest getRequest() { - return (GeneratedHttpRequest) super.getRequest(); + protected GeneratedHttpRequest getRequest() { + return (GeneratedHttpRequest) super.getRequest(); } } diff --git a/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java b/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java index 42a20dd55b..d7a8c36678 100644 --- a/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java +++ b/core/src/main/java/org/jclouds/reflect/FunctionalReflection.java @@ -112,8 +112,7 @@ public final class FunctionalReflection { args = ImmutableList.copyOf(args); else args = Collections.unmodifiableList(args); - Invokable invokable = Invokable.from(invoked); - // not yet support the proxy arg + Invokable invokable = enclosingType.method(invoked); Invocation invocation = Invocation.create(invokable, args); try { return invocationFunction.apply(invocation); diff --git a/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java b/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java index 95c63847c9..cc3332db2d 100644 --- a/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java +++ b/core/src/main/java/org/jclouds/rest/binders/BindMapToStringPayload.java @@ -45,7 +45,7 @@ public class BindMapToStringPayload implements MapBinder { @Override public R bindToRequest(R request, Map 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); diff --git a/core/src/main/java/org/jclouds/rest/config/AsyncHttpApiProvider.java b/core/src/main/java/org/jclouds/rest/config/AsyncHttpApiProvider.java index 5f5037d15a..84fc4d94cb 100644 --- a/core/src/main/java/org/jclouds/rest/config/AsyncHttpApiProvider.java +++ b/core/src/main/java/org/jclouds/rest/config/AsyncHttpApiProvider.java @@ -36,10 +36,10 @@ import com.google.inject.TypeLiteral; @Singleton public class AsyncHttpApiProvider implements Provider { private final Class asyncApiType; - private final DelegatesToInvocationFunction> httpInvoker; + private final DelegatesToInvocationFunction httpInvoker; @Inject - private AsyncHttpApiProvider(DelegatesToInvocationFunction> httpInvoker, + private AsyncHttpApiProvider(DelegatesToInvocationFunction httpInvoker, TypeLiteral asyncApiType) { this.httpInvoker = httpInvoker; this.asyncApiType = asyncApiType.getRawType(); diff --git a/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java b/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java index d926c9ba9f..a0bcab88f3 100644 --- a/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java +++ b/core/src/main/java/org/jclouds/rest/config/CallGetOnFuturesProvider.java @@ -38,11 +38,11 @@ import com.google.inject.Provider; public class CallGetOnFuturesProvider implements Provider { private final Class apiType; - private final DelegatesToInvocationFunction> syncInvoker; + private final DelegatesToInvocationFunction> syncInvoker; @Inject private CallGetOnFuturesProvider(Cache, Invokable> invokables, - DelegatesToInvocationFunction> syncInvoker, Class apiType, + DelegatesToInvocationFunction> syncInvoker, Class apiType, Class asyncApiType) { this.syncInvoker = syncInvoker; this.apiType = apiType; diff --git a/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java b/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java index 85730d86c8..c7622c81d2 100644 --- a/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java +++ b/core/src/main/java/org/jclouds/rest/config/HttpApiProvider.java @@ -38,11 +38,11 @@ import com.google.inject.Provider; @Singleton public class HttpApiProvider implements Provider { private final Class apiType; - private final DelegatesToInvocationFunction> httpInvoker; + private final DelegatesToInvocationFunction httpInvoker; @Inject private HttpApiProvider(Cache, Invokable> invokables, - DelegatesToInvocationFunction> httpInvoker, Class apiType, Class asyncApiType) { + DelegatesToInvocationFunction httpInvoker, Class apiType, Class asyncApiType) { this.httpInvoker = httpInvoker; this.apiType = apiType; RestModule.putInvokables(TypeToken.of(apiType), TypeToken.of(asyncApiType), invokables); @@ -54,5 +54,4 @@ public class HttpApiProvider implements Provider { public S get() { return (S) Proxy.newProxyInstance(apiType.getClassLoader(), new Class[] { apiType }, httpInvoker); } - } diff --git a/core/src/main/java/org/jclouds/rest/config/RestModule.java b/core/src/main/java/org/jclouds/rest/config/RestModule.java index 47999c0dad..df3a75d2e1 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestModule.java @@ -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) { diff --git a/core/src/main/java/org/jclouds/rest/config/SetCaller.java b/core/src/main/java/org/jclouds/rest/config/SetCaller.java index 06b1bd868a..65acb46789 100644 --- a/core/src/main/java/org/jclouds/rest/config/SetCaller.java +++ b/core/src/main/java/org/jclouds/rest/config/SetCaller.java @@ -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> callerEnclosingType = new ThreadLocal>(); private final ThreadLocal caller = new ThreadLocal(); - 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> CALLER_ENCLOSING_TYPE = Key.get(new TypeLiteral>() { - }, Names.named("caller")); - private static final Key CALLER_INVOCATION = Key.get(new TypeLiteral() { }, Names.named("caller")); - class CallerEnclosingTypeProvider implements Provider> { - @Override - public TypeToken get() { - return callerEnclosingType.get(); - } - } - class CallerInvocationProvider implements Provider { @Override public Invocation get() { diff --git a/core/src/main/java/org/jclouds/rest/internal/BlockOnFuture.java b/core/src/main/java/org/jclouds/rest/internal/BlockOnFuture.java index c500d189f8..668b439a57 100644 --- a/core/src/main/java/org/jclouds/rest/internal/BlockOnFuture.java +++ b/core/src/main/java/org/jclouds/rest/internal/BlockOnFuture.java @@ -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, 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 timeouts; - private final TypeToken enclosingType; private final Invocation invocation; @Inject @VisibleForTesting - BlockOnFuture(@Named("TIMEOUTS") Map timeouts, @Assisted TypeToken enclosingType, - @Assisted Invocation invocation) { + BlockOnFuture(@Named("TIMEOUTS") Map timeouts, @Assisted Invocation invocation) { this.timeouts = timeouts; - this.enclosingType = enclosingType; this.invocation = invocation; } @@ -124,7 +120,7 @@ public class BlockOnFuture implements Function, 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); diff --git a/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java b/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java index 23b41a62d3..2e6f604315 100644 --- a/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java +++ b/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java @@ -72,13 +72,11 @@ import com.google.inject.util.Types; /** * @param * The enclosing type of the interface that a dynamic proxy like this implements - * @param - * The enclosing type that is processed by this proxy * @param * The function that implements this dynamic proxy */ @Beta -public final class DelegatesToInvocationFunction> implements +public final class DelegatesToInvocationFunction> implements InvocationHandler { private static final Object[] NO_ARGS = {}; @@ -120,8 +118,7 @@ public final class DelegatesToInvocationFunction invokable = Invokable.from(invoked); - // not yet support the proxy arg + Invokable invokable = enclosingType.method(invoked); Invocation invocation = Invocation.create(invokable, args); try { return handle(invocation); @@ -161,7 +158,7 @@ public final class DelegatesToInvocationFunction returnType = unwrapIfOptional(caller.getInvokable().getReturnType()); Function delegate; - setCaller.enter(enclosingType, caller); + setCaller.enter(caller); try { @SuppressWarnings("unchecked") Key> delegateType = (Key>) methodInvokerFor(returnType); diff --git a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java index 268a6c5edd..60c2394394 100644 --- a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java +++ b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java @@ -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 - * enclosing type of the interface parsed to generate this request. + * @author Adrian Cole */ -public final class GeneratedHttpRequest extends HttpRequest { - public static Builder builder(Class enclosingType) { - return new Builder(TypeToken.of(enclosingType)); +public final class GeneratedHttpRequest extends HttpRequest { + + public static Builder builder() { + return new Builder(); } - public static Builder builder(TypeToken enclosingType) { - return new Builder(enclosingType); + public Builder toBuilder() { + return new Builder().fromGeneratedHttpRequest(this); } - public Builder toBuilder() { - return new Builder(enclosingType).fromGeneratedHttpRequest(this); - } - - public final static class Builder extends HttpRequest.Builder> { - private final TypeToken enclosingType; - - private Builder(TypeToken enclosingType) { - this.enclosingType = checkNotNull(enclosingType, "enclosingType"); - } - + public final static class Builder extends HttpRequest.Builder { private Invocation invocation; - private Optional> callerEnclosingType = Optional.absent(); private Optional caller = Optional.absent(); /** * @see GeneratedHttpRequest#getInvocation() */ - public Builder invocation(Invocation invocation) { + public Builder invocation(Invocation invocation) { this.invocation = checkNotNull(invocation, "invocation"); return this; } - /** - * @see GeneratedHttpRequest#getCallerEnclosingType() - */ - public Builder callerEnclosingType(@Nullable TypeToken callerEnclosingType) { - this.callerEnclosingType = Optional.> fromNullable(callerEnclosingType); - return this; - } - /** * @see GeneratedHttpRequest#getCaller() */ - public Builder caller(@Nullable Invocation caller) { + public Builder caller(@Nullable Invocation caller) { this.caller = Optional.fromNullable(caller); return this; } - public GeneratedHttpRequest build() { - return new GeneratedHttpRequest(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 fromGeneratedHttpRequest(GeneratedHttpRequest 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 self() { + protected Builder self() { return this; } } - private final TypeToken enclosingType; private final Invocation invocation; - private final Optional> callerEnclosingType; private final Optional caller; protected GeneratedHttpRequest(String method, URI endpoint, Multimap headers, - @Nullable Payload payload, Iterable filters, TypeToken enclosingType, - Invocation invocation, Optional> callerEnclosingType, Optional caller) { + @Nullable Payload payload, Iterable filters, Invocation invocation, + Optional 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 extends HttpRequest { return invocation; } - /** - * different than {@link #getDeclaringClass()} when {@link #getCaller()} is a member of a class it was not declared - * in. - */ - public Optional> getCallerEnclosingType() { - return callerEnclosingType; - } - public Optional getCaller() { return caller; } diff --git a/core/src/main/java/org/jclouds/rest/internal/GetAcceptHeaders.java b/core/src/main/java/org/jclouds/rest/internal/GetAcceptHeaders.java index 33195df9f7..b1ef21977c 100644 --- a/core/src/main/java/org/jclouds/rest/internal/GetAcceptHeaders.java +++ b/core/src/main/java/org/jclouds/rest/internal/GetAcceptHeaders.java @@ -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 implements Function> { - private Class enclosingType; - - @SuppressWarnings("unchecked") - @Inject - GetAcceptHeaders(TypeLiteral enclosingType) { - this.enclosingType = (Class) enclosingType.getRawType(); - } +class GetAcceptHeaders implements Function> { @Override public Set apply(Invocation invocation) { Optional 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. of(); } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/internal/InvokeHttpMethod.java b/core/src/main/java/org/jclouds/rest/internal/InvokeHttpMethod.java index 540f8f0750..01640f1dbb 100644 --- a/core/src/main/java/org/jclouds/rest/internal/InvokeHttpMethod.java +++ b/core/src/main/java/org/jclouds/rest/internal/InvokeHttpMethod.java @@ -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 implements Function { +public class InvokeHttpMethod implements Function { @Resource private Logger logger = Logger.NULL; private final Injector injector; - private final TypeToken enclosingType; private final Cache, Invokable> sync2AsyncInvokables; - private final RestAnnotationProcessor annotationProcessor; + private final RestAnnotationProcessor annotationProcessor; private final HttpCommandExecutorService http; - private final TransformerForRequest transformerForRequest; + private final TransformerForRequest transformerForRequest; private final ListeningExecutorService userExecutor; private final BlockOnFuture.Factory blocker; - @SuppressWarnings("unchecked") @Inject - private InvokeHttpMethod(Injector injector, TypeLiteral enclosingType, - Cache, Invokable> sync2AsyncInvokables, RestAnnotationProcessor annotationProcessor, - HttpCommandExecutorService http, TransformerForRequest transformerForRequest, + private InvokeHttpMethod(Injector injector, Cache, Invokable> sync2AsyncInvokables, + RestAnnotationProcessor annotationProcessor, HttpCommandExecutorService http, + TransformerForRequest transformerForRequest, @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, BlockOnFuture.Factory blocker) { this.injector = injector; - this.enclosingType = (TypeToken) TypeToken.of(enclosingType.getType()); this.sync2AsyncInvokables = sync2AsyncInvokables; this.annotationProcessor = annotationProcessor; this.http = http; @@ -105,7 +100,7 @@ public class InvokeHttpMethod implements Function { 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 implements Function { public ListenableFuture createFuture(Invocation invocation) { String name = invocation.getInvokable().toString(); logger.trace(">> converting %s", name); - GeneratedHttpRequest request = annotationProcessor.apply(invocation); + GeneratedHttpRequest request = annotationProcessor.apply(invocation); logger.trace("<< converted %s to %s", name, request.getRequestLine()); Function transformer = transformerForRequest.apply(request); @@ -138,7 +133,7 @@ public class InvokeHttpMethod implements Function { 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); } diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index e1c2cdecca..d4101ce74c 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -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 + * @author Adrian Cole */ -public class RestAnnotationProcessor implements Function> { +public class RestAnnotationProcessor implements Function { @Resource protected Logger logger = Logger.NULL; @@ -152,17 +149,13 @@ public class RestAnnotationProcessor implements Function getAcceptHeaders; - private final TypeToken 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 getAcceptHeaders, TypeLiteral 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 implements Function) 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 createRequest(Invokable invokable, List args) { + public GeneratedHttpRequest createRequest(Invokable invokable, List args) { return apply(Invocation.create(invokable, args)); } @Override - public GeneratedHttpRequest apply(Invocation invocation) { + public GeneratedHttpRequest apply(Invocation invocation) { checkNotNull(invocation, "invocation"); inputParamValidator.validateMethodParametersOrThrow(invocation); @@ -196,7 +187,7 @@ public class RestAnnotationProcessor implements Function implements Function 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 implements Function formParams = addFormParams(tokenValues, invocation); Multimap queryParams = addQueryParams(tokenValues, invocation); @@ -298,7 +289,7 @@ public class RestAnnotationProcessor implements Function request = requestBuilder.build(); + GeneratedHttpRequest request = requestBuilder.build(); org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(invocation); if (mapBinder != null) { @@ -319,7 +310,7 @@ public class RestAnnotationProcessor implements Function A findOrNull(Iterable args, Class clazz) { + private static T findOrNull(Iterable args, Class clazz) { return clazz.cast(tryFind(args, instanceOf(clazz)).orNull()); } @@ -332,9 +323,9 @@ public class RestAnnotationProcessor implements Function implements Function findEndpoint(Invocation invocation) { - Optional endpoint = getEndpointFor(enclosingType, invocation); + Optional 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 implements Function addPathAndGetTokens(TypeToken enclosingType, Invocation invocation, - UriBuilder uriBuilder) { - if (enclosingType.getRawType().isAnnotationPresent(Path.class)) - uriBuilder.appendPath(enclosingType.getRawType().getAnnotation(Path.class).value()); + private Multimap 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 implements Function addFormParams(Multimap tokenValues, Invocation invocation) { Multimap 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 implements Function addQueryParams(Multimap tokenValues, Invocation invocation) { Multimap 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 implements Function getFiltersIfAnnotated(Invocation invocation) { List filters = newArrayList(); - if (enclosingType.getRawType().isAnnotationPresent(RequestFilters.class)) { - for (Class clazz : enclosingType.getRawType().getAnnotation(RequestFilters.class) - .value()) { + if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(RequestFilters.class)) { + for (Class 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 implements Function> uriSupplierLiteral = new TypeLiteral>() { }; - protected Optional getEndpointFor(TypeToken enclosingType, Invocation invocation) { + protected Optional 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 implements Function decorateRequest(GeneratedHttpRequest request) throws NegativeArraySizeException { + private GeneratedHttpRequest decorateRequest(GeneratedHttpRequest request) throws NegativeArraySizeException { Invocation invocation = request.getInvocation(); List args = request.getInvocation().getArgs(); Set binderOrWrapWith = ImmutableSet.copyOf(concat( @@ -590,14 +581,19 @@ public class RestAnnotationProcessor implements Function= position + 1 && arg != null) { Class parameterType = entry.getType().getRawType(); Class 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 implements Function implements Function findOptionsIn(Invocation invocation) { ImmutableSet.Builder 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 implements Function 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 implements Function headers, Invocation invocation, Multimap 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 implements Function 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 implements Function implements Function implements Function 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 implements Function 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 implements Function 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 implements Function implements Function, Function> { +public class TransformerForRequest implements Function> { private final ParseSax.Factory parserFactory; private final Injector injector; - private final GetAcceptHeaders getAcceptHeaders; - private final Class enclosingType; + private final GetAcceptHeaders getAcceptHeaders; - @SuppressWarnings("unchecked") @Inject - TransformerForRequest(Injector injector, Factory parserFactory, GetAcceptHeaders getAcceptHeaders, - TypeLiteral enclosingType) { + TransformerForRequest(Injector injector, Factory parserFactory, GetAcceptHeaders getAcceptHeaders) { this.injector = injector; this.parserFactory = parserFactory; this.getAcceptHeaders = getAcceptHeaders; - this.enclosingType = (Class) enclosingType.getRawType(); } @SuppressWarnings("unchecked") @Override - public Function apply(GeneratedHttpRequest request) { + public Function apply(GeneratedHttpRequest request) { Function transformer; - Class> handler = TransformerForRequest.getSaxResponseParserClassOrNull(request - .getInvocation().getInvokable()); + Class> handler = getSaxResponseParserClassOrNull(request.getInvocation() + .getInvokable()); if (handler != null) { transformer = parserFactory.create(injector.getInstance(handler)); } else { @@ -228,9 +223,4 @@ public class TransformerForRequest implements Function 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(); } } diff --git a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java index b380fcd69b..8896a0f7be 100644 --- a/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java +++ b/core/src/test/java/org/jclouds/http/handlers/BackoffLimitedRetryHandlerTest.java @@ -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 processor = BaseJettyTest.newBuilder(8100, new Properties()).buildInjector() - .getInstance(Key.get(new TypeLiteral>(){})); + private final RestAnnotationProcessor processor = BaseJettyTest.newBuilder(8100, new Properties()).buildInjector() + .getInstance(RestAnnotationProcessor.class); private HttpCommand createCommand() throws SecurityException, NoSuchMethodException { Invokable method = Invokable.from(IntegrationTestAsyncClient.class.getMethod("download", String.class)); diff --git a/core/src/test/java/org/jclouds/json/BaseParserTest.java b/core/src/test/java/org/jclouds/json/BaseParserTest.java index 8139275e96..d3143826fd 100644 --- a/core/src/test/java/org/jclouds/json/BaseParserTest.java +++ b/core/src/test/java/org/jclouds/json/BaseParserTest.java @@ -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 { @SuppressWarnings("unchecked") protected Function parser(Injector i) { - TypeToken> token = new TypeToken>() { - private static final long serialVersionUID = 1L; - }.where(new TypeParameter() { - }, new TypeToken(getClass()) { - private static final long serialVersionUID = 1L; - }); - Key> xform = (Key>) Key.get(token.getType()); try { return (Function) i .createChildInjector(new SaxParserModule()) - .getInstance(xform) + .getInstance(TransformerForRequest.class) .getTransformerForMethod( Invocation.create(Invokable.from(getClass().getMethod("expected")), ImmutableList.of()), i); } catch (Exception e) { diff --git a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java index b1936fdc25..f7a1c5c492 100644 --- a/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java +++ b/core/src/test/java/org/jclouds/rest/InputParamValidatorTest.java @@ -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 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 = injector.getInstance(RestAnnotationProcessor.class); } - } diff --git a/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java b/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java index 4182edb6c1..a99a8a3af3 100644 --- a/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java +++ b/core/src/test/java/org/jclouds/rest/binders/BindMapToStringPayloadTest.java @@ -57,11 +57,11 @@ public class BindMapToStringPayloadTest { @Test public void testCorrect() throws SecurityException, NoSuchMethodException { Invokable testPayload = Invokable.from(TestPayload.class.getMethod("testPayload", String.class)); - GeneratedHttpRequest request = GeneratedHttpRequest.builder(TypeToken.of(TestPayload.class)) + GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList. of("robot"))) .method("POST").endpoint("http://localhost").build(); - GeneratedHttpRequest newRequest = binder().bindToRequest(request, + GeneratedHttpRequest newRequest = binder().bindToRequest(request, ImmutableMap. of("fooble", "robot")); assertEquals(newRequest.getRequestLine(), request.getRequestLine()); @@ -71,11 +71,11 @@ public class BindMapToStringPayloadTest { @Test public void testDecodes() throws SecurityException, NoSuchMethodException { Invokable testPayload = Invokable.from(TestPayload.class.getMethod("changeAdminPass", String.class)); - GeneratedHttpRequest request = GeneratedHttpRequest.builder(TypeToken.of(TestPayload.class)) + GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(testPayload, ImmutableList. of("foo"))) .method("POST").endpoint("http://localhost").build(); - GeneratedHttpRequest newRequest = binder() + GeneratedHttpRequest newRequest = binder() .bindToRequest(request, ImmutableMap.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 noPayload = Invokable.from(TestPayload.class.getMethod("noPayload", String.class)); - GeneratedHttpRequest request = GeneratedHttpRequest.builder(TypeToken.of(TestPayload.class)) + GeneratedHttpRequest request = GeneratedHttpRequest.builder() .invocation(Invocation.create(noPayload, ImmutableList. of("robot"))) .method("POST").endpoint("http://localhost").build(); binder().bindToRequest(request, ImmutableMap.of("fooble", "robot")); diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseAsyncApiTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseAsyncApiTest.java index 8737aca4a1..0b4e53d9da 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BaseAsyncApiTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseAsyncApiTest.java @@ -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 extends BaseRestApiTest { - protected RestAnnotationProcessor processor; + protected RestAnnotationProcessor processor; protected abstract void checkFilters(HttpRequest request); @@ -65,16 +63,11 @@ public abstract class BaseAsyncApiTest 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> rapKey = (Key>) Key - .get(new TypeToken>(getClass()) { - private static final long serialVersionUID = 1L; - }.getType()); /** * @see org.jclouds.providers.Providers#withId diff --git a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java index 56da7994fd..687b8f2e9c 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BaseRestApiTest.java @@ -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 RestAnnotationProcessor processor(Class type) { - TypeToken> token = new TypeToken>() { - private static final long serialVersionUID = 1L; - }.where(new TypeParameter() { - }, type); - Key> rapKey = (Key>) Key.get(token.getType()); - return injector.getInstance(rapKey); - } - - protected TransformerForRequest transformer(Class type) { - TypeToken> token = new TypeToken>() { - private static final long serialVersionUID = 1L; - }.where(new TypeParameter() { - }, type); - Key> rapKey = (Key>) Key.get(token.getType()); - return injector.getInstance(rapKey); - } - } diff --git a/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java b/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java index 0a4d566623..3c64aa4aea 100644 --- a/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/BlockOnFutureTest.java @@ -82,22 +82,21 @@ public class BlockOnFutureTest { } public void testUnnamedMethodWithDefaultPropTimeout() throws Exception { - Function, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L), - enclosingType, get); + Function, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L), get); assertEquals(withOverride.apply(future), "foo"); verify(future); } public void testUnnamedMethodWithClassPropTimeout() throws Exception { Function, 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, 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, Object> noOverrides = new BlockOnFuture(ImmutableMap. of(), - enclosingType, get); + Function, Object> noOverrides = new BlockOnFuture(ImmutableMap. of(), get); assertEquals(noOverrides.apply(future), "foo"); verify(future); } public void testNamedMethodWithDefaultPropTimeout() throws Exception { - Function, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L), - enclosingType, namedGet); + Function, Object> withOverride = new BlockOnFuture(ImmutableMap.of("default", 250L), namedGet); assertEquals(withOverride.apply(future), "foo"); verify(future); } public void testNamedMethodWithMethodPropTimeout() throws Exception { Function, 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, Object> noOverrides = new BlockOnFuture(ImmutableMap. of(), - enclosingType, namedGet); + Function, Object> noOverrides = new BlockOnFuture(ImmutableMap. of(), namedGet); assertEquals(noOverrides.apply(future), "foo"); verify(future); } - + } diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 70a501ccb6..58510157fd 100644 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -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. 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. newArrayList((String) null)); + processor.createRequest(method, Lists. 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. 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 bars = ImmutableSortedSet. of("1"); - GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList. of(bars)); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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 bars = ImmutableSortedSet. of("1", "2", "3"); - GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList. of(bars)); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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 bars = ImmutableSortedSet. of(1, 2, 3); - GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList. of(bars)); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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 bars = Collections.emptySet(); - GeneratedHttpRequest request = processor(TestQuery.class).createRequest(method, ImmutableList. of(bars)); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. 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. 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. 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. 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. 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. 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. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. 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. newArrayList((String) null)); + processor.createRequest(method, Lists. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data", new org.jclouds.rest.MapBinder() { @Override public R bindToRequest(R request, Map 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. 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. newArrayList((String) null)); + processor.createRequest(method, Lists. 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. 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. newArrayList(null, "foobledata")); + processor.createRequest(method, Lists. 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. 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. 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. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("data")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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. of("bar")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + Function 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 parser = transformer(TestPut.class).apply(request); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); + Function 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. 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. 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. 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. 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. newArrayList((String) null)); + processor.createRequest(method, Lists. 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. 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. 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. 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. newArrayList((String) null)); + processor.createRequest(method, Lists. newArrayList((String) null)); } static class FirstCharacter implements Function { @@ -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 headers = processor(TestHeader.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestClassHeader.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeader.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeader.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeader.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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. 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. of("robot")) + String query = processor.createRequest(method, ImmutableList. 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. of("robot")) + String query = processor.createRequest(method, ImmutableList. 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. of("robot")) + String query = processor.createRequest(method, ImmutableList. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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 Class> unwrap(Class type, Invokable method) { - return (Class>) transformer(type) + return (Class>) 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 transformer = transformer(TestTransformers.class).apply(request); + Function 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. 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. 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. 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. of("1")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("1")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. of("1")); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList. 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. 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. 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. 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. 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. 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. 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. 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. of("1", "")); + processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeaders.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeaders.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeaders.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. 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 headers = processor(TestHeaders.class).createRequest(method, + Multimap headers = processor.createRequest(method, ImmutableList. of("robot", "egg")).getHeaders(); assertEquals(headers.size(), 2); Collection 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. 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. 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. of("robot")) + Object form = processor.createRequest(method, ImmutableList. 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. of("robot")) + Object form = processor.createRequest(method, ImmutableList. 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. of("robot")) + Object form = processor.createRequest(method, ImmutableList. 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. of("robot", "eggs")) + Object form = processor.createRequest(method, ImmutableList. 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. of("robot", "eggs")) + Object form = processor.createRequest(method, ImmutableList. 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); } } diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java index 4c0877550f..fd0c20a3d3 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/BindToPathTest.java @@ -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. 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. 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. 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. 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. 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. of(dto))) .method(HttpMethod.GET) .endpoint(URI.create("http://localhost?param=value")).build(); diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java index 75f5375abc..ee0231d19a 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindMoveVolumeToPathTest.java @@ -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. of(CloudResources.volumePut(), CloudResources.virtualDatacenterPut()))) .method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build(); } diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java index a0d452378f..49b41d7d00 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindNetworkConfigurationRefToPayloadTest.java @@ -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. 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. 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. 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. of(vm, network))) .method(HttpMethod.GET) .endpoint(URI.create("http://localhost")).build(); diff --git a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java index 77873a0fb5..e7cd227b2d 100644 --- a/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java +++ b/labs/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java @@ -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. 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. of(datacenter))) .method(HttpMethod.GET) .endpoint(URI.create("http://foo/bar")).build(); diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/OAuthModuleWithoutTypeAdapters.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/OAuthModuleWithoutTypeAdapters.java index 3c680221b8..c611e35b18 100644 --- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/OAuthModuleWithoutTypeAdapters.java +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/config/OAuthModuleWithoutTypeAdapters.java @@ -45,7 +45,7 @@ public class OAuthModuleWithoutTypeAdapters extends OAuthModule { protected void configure() { bind(new TypeLiteral>() {}).to(SignOrProduceMacForToken.class); bind(new TypeLiteral>() {}).to(OAuthCredentialsSupplier.class); - bind(new TypeLiteral, TokenRequest>>() {}).to(BuildTokenRequest.class); + bind(new TypeLiteral>() {}).to(BuildTokenRequest.class); bind(new TypeLiteral>() {}).to(FetchToken.class); } } diff --git a/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/BaseToPagedIterable.java b/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/BaseToPagedIterable.java index 2e8beb5232..d151ab2580 100644 --- a/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/BaseToPagedIterable.java +++ b/labs/google-compute/src/main/java/org/jclouds/googlecompute/functions/internal/BaseToPagedIterable.java @@ -41,7 +41,7 @@ import static com.google.common.collect.Iterables.tryFind; public abstract class BaseToPagedIterable> implements Function, PagedIterable>, InvocationContext { - private GeneratedHttpRequest request; + private GeneratedHttpRequest request; @Override public PagedIterable apply(ListPage input) { diff --git a/labs/oauth/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java b/labs/oauth/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java index cec728b26a..fc55a87da8 100644 --- a/labs/oauth/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java +++ b/labs/oauth/src/main/java/org/jclouds/oauth/v2/config/OAuthModule.java @@ -63,7 +63,7 @@ public class OAuthModule extends AbstractModule { Header.class, new HeaderTypeAdapter(), ClaimSet.class, new ClaimSetTypeAdapter())); bind(new TypeLiteral>() {}).to(OAuthCredentialsSupplier.class); - bind(new TypeLiteral, TokenRequest>>() {}).to(BuildTokenRequest.class); + bind(new TypeLiteral>() {}).to(BuildTokenRequest.class); bind(new TypeLiteral>() {}).to(FetchToken.class); } diff --git a/labs/oauth/src/main/java/org/jclouds/oauth/v2/filters/OAuthAuthenticator.java b/labs/oauth/src/main/java/org/jclouds/oauth/v2/filters/OAuthAuthenticator.java index cb51291d51..ccfd2a5ad4 100644 --- a/labs/oauth/src/main/java/org/jclouds/oauth/v2/filters/OAuthAuthenticator.java +++ b/labs/oauth/src/main/java/org/jclouds/oauth/v2/filters/OAuthAuthenticator.java @@ -42,11 +42,11 @@ import static com.google.common.base.Preconditions.checkState; @Singleton public class OAuthAuthenticator implements HttpRequestFilter { - private Function, TokenRequest> tokenRequestBuilder; + private Function tokenRequestBuilder; private Function tokenFetcher; @Inject - OAuthAuthenticator(Function, TokenRequest> tokenRequestBuilder, LoadingCache tokenRequestBuilder, LoadingCache 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", diff --git a/labs/oauth/src/main/java/org/jclouds/oauth/v2/functions/BuildTokenRequest.java b/labs/oauth/src/main/java/org/jclouds/oauth/v2/functions/BuildTokenRequest.java index 37827a5a57..8faa22d342 100644 --- a/labs/oauth/src/main/java/org/jclouds/oauth/v2/functions/BuildTokenRequest.java +++ b/labs/oauth/src/main/java/org/jclouds/oauth/v2/functions/BuildTokenRequest.java @@ -57,7 +57,7 @@ import com.google.inject.name.Named; * @author David Alves */ @Singleton -public class BuildTokenRequest implements Function, TokenRequest> { +public class BuildTokenRequest implements Function { private final String assertionTargetDescription; private final String signatureAlgorithm; @@ -90,7 +90,7 @@ public class BuildTokenRequest implements Function, 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, 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, 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; } diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java index dd6ea0430b..934f7a8e44 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java @@ -44,7 +44,7 @@ import com.google.common.reflect.Invokable; */ @Singleton public class AzureBlobRequestSigner implements BlobRequestSigner { - private final RestAnnotationProcessor 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 processor, BlobToAzureBlob blobToBlob, + public AzureBlobRequestSigner(RestAnnotationProcessor processor, BlobToAzureBlob blobToBlob, BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToBlob = checkNotNull(blobToBlob, "blobToBlob"); diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java index 8167e84853..a54ab60813 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/HPCloudObjectStorageBlobRequestSigner.java @@ -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 processor; + private final RestAnnotationProcessor processor; private final Crypto crypto; private final Provider unixEpochTimestampProvider; @@ -83,7 +84,7 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner private final Invokable createMethod; @Inject - public HPCloudObjectStorageBlobRequestSigner(RestAnnotationProcessor processor, + public HPCloudObjectStorageBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto, @TimeStamp Provider unixEpochTimestampProvider, Supplier access, @org.jclouds.location.Provider final Supplier 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 request = processor.apply(Invocation.create(getMethod, + GeneratedHttpRequest request = processor.apply(Invocation.create(getMethod, ImmutableList. 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 request = processor.apply(Invocation.create(createMethod, + GeneratedHttpRequest request = processor.apply(Invocation.create(createMethod, ImmutableList. of(container, blobToObject.apply(blob)))); return cleanRequest(signForTemporaryAccess(request, timeInSeconds)); }