mirror of https://github.com/apache/jclouds.git
commit
403bfee841
|
@ -37,9 +37,7 @@ import org.jclouds.reflect.Invocation;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,7 +45,7 @@ import org.jclouds.reflect.Invokable;
|
|||
*/
|
||||
@Singleton
|
||||
public class AtmosBlobRequestSigner implements BlobRequestSigner {
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final RestAnnotationProcessor<AtmosAsyncClient> processor;
|
||||
private final BlobToObject blobToObject;
|
||||
private final BlobToHttpGetOptions blob2ObjectGetOptions;
|
||||
|
||||
|
@ -56,17 +54,15 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner {
|
|||
private final Invokable<?, ?> createMethod;
|
||||
|
||||
@Inject
|
||||
public AtmosBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject,
|
||||
public AtmosBlobRequestSigner(RestAnnotationProcessor<AtmosAsyncClient> processor, BlobToObject blobToObject,
|
||||
BlobToHttpGetOptions blob2ObjectGetOptions) throws SecurityException, NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
|
||||
this.getMethod = Invokable.from(TypeToken.of(AtmosAsyncClient.class),
|
||||
AtmosAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(TypeToken.of(AtmosAsyncClient.class),
|
||||
AtmosAsyncClient.class.getMethod("deletePath", String.class));
|
||||
this.createMethod = Invokable.from(TypeToken.of(AtmosAsyncClient.class),
|
||||
AtmosAsyncClient.class.getMethod("createFile", String.class, AtmosObject.class, PutOptions[].class));
|
||||
this.getMethod = Invokable.from(AtmosAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(AtmosAsyncClient.class.getMethod("deletePath", String.class));
|
||||
this.createMethod = Invokable.from(AtmosAsyncClient.class.getMethod("createFile", String.class,
|
||||
AtmosObject.class, PutOptions[].class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
|
|
@ -62,7 +62,7 @@ import org.jclouds.openstack.filters.AuthenticateRequest;
|
|||
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule.GetAuth;
|
||||
import org.jclouds.openstack.keystone.v1_1.domain.Auth;
|
||||
import org.jclouds.openstack.keystone.v1_1.parse.ParseAuthTest;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.Map;
|
|||
|
||||
import org.jclouds.cloudsigma.options.CloneDriveOptions;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class BindCloneDriveOptionsToPlainTextStringTest {
|
|||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.cloudstack.config;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -209,9 +209,9 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
});
|
||||
bind(CredentialType.class).toProvider(CredentialTypeFromPropertyOrDefault.class);
|
||||
// session client is used directly for filters and retry handlers, so let's bind it explicitly
|
||||
bindClientAndAsyncClient(binder(), SessionClient.class, SessionAsyncClient.class);
|
||||
bindClientAndAsyncClient(binder(), CloudStackDomainClient.class, CloudStackDomainAsyncClient.class);
|
||||
bindClientAndAsyncClient(binder(), CloudStackGlobalClient.class, CloudStackGlobalAsyncClient.class);
|
||||
bindHttpApi(binder(), SessionClient.class, SessionAsyncClient.class);
|
||||
bindHttpApi(binder(), CloudStackDomainClient.class, CloudStackDomainAsyncClient.class);
|
||||
bindHttpApi(binder(), CloudStackGlobalClient.class, CloudStackGlobalAsyncClient.class);
|
||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class);
|
||||
|
||||
super.configure();
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
|||
import org.jclouds.cloudstack.options.ListAccountsOptions;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.functions.IdentityFunction;
|
|||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.cloudstack.functions.ParseAsyncJobFromHttpResponse;
|
|||
import org.jclouds.cloudstack.functions.ParseAsyncJobsFromHttpResponse;
|
||||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListAsyncJobsOptions;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.io.IOException;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.cloudstack.domain.ResourceLimit.ResourceType;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.cloudstack.functions.ParseEventTypesFromHttpResponse;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListEventsOptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
|||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.cloudstack.options.UpdateAccountOptions;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListAlertsOptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.cloudstack.domain.Capacity;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListCapacityOptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListHostsOptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
|||
import org.jclouds.cloudstack.options.ListStoragePoolsOptions;
|
||||
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.cloudstack.options.GenerateUsageRecordsOptions;
|
|||
import org.jclouds.cloudstack.options.ListUsageRecordsOptions;
|
||||
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.cloudstack.options.UpdateUserOptions;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
|||
import org.jclouds.cloudstack.options.ListOSTypesOptions;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.io.IOException;
|
|||
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
||||
import org.jclouds.cloudstack.functions.ParseNamesFromHttpResponse;
|
||||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListResourceLimitsOptions;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions;
|
|||
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
|||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
|||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
|||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.functions.IdentityFunction;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
|||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.functions.IdentityFunction;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
|||
import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.options.ListVolumesOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
|
|||
import org.jclouds.cloudstack.options.ListZonesOptions;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.jclouds.ec2.xml.PermissionHandler;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.ec2.options.DescribeRegionsOptions;
|
|||
import org.jclouds.ec2.xml.DescribeAvailabilityZonesResponseHandler;
|
||||
import org.jclouds.ec2.xml.DescribeRegionsResponseHandler;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.jclouds.ec2.xml.SnapshotHandler;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.ec2.xml.DescribeAddressesResponseHandler;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.jclouds.ec2.xml.UnencodeStringValueHandler;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
|||
import org.jclouds.ec2.xml.DescribeKeyPairsResponseHandler;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.jclouds.ec2.xml.DescribeSecurityGroupsResponseHandler;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.ec2.xml.BundleTaskHandler;
|
|||
import org.jclouds.ec2.xml.DescribeBundleTasksResponseHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.jclouds.http.filters.BasicAuthentication;
|
|||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.filesystem.config;
|
||||
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindBlockingApi;
|
||||
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
|
@ -50,7 +50,7 @@ public class FilesystemBlobStoreContextModule extends AbstractModule {
|
|||
protected void configure() {
|
||||
bind(AsyncBlobStore.class).to(LocalAsyncBlobStore.class).asEagerSingleton();
|
||||
// forward all requests from TransientBlobStore to TransientAsyncBlobStore. needs above binding as cannot proxy a class
|
||||
bindClient(binder(), LocalBlobStore.class, AsyncBlobStore.class);
|
||||
bindBlockingApi(binder(), LocalBlobStore.class, AsyncBlobStore.class);
|
||||
bind(BlobStore.class).to(LocalBlobStore.class);
|
||||
|
||||
install(new BlobStoreObjectModule());
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.openstack.keystone.v2_0.config;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -144,7 +144,7 @@ public class KeystoneAuthenticationModule extends AbstractModule {
|
|||
|
||||
protected void bindAuthenticationApi() {
|
||||
// AuthenticationApi is used directly for filters and retry handlers, so let's bind it explicitly
|
||||
bindClientAndAsyncClient(binder(), AuthenticationApi.class, AuthenticationAsyncApi.class);
|
||||
bindHttpApi(binder(), AuthenticationApi.class, AuthenticationAsyncApi.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Provides;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.rackspace.cloudidentity.v2_0.config;
|
||||
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class CloudIdentityAuthenticationModule extends KeystoneAuthenticationMod
|
|||
@Override
|
||||
protected void bindAuthenticationApi() {
|
||||
// AuthenticationApi is used directly for filters and retry handlers, so let's bind it explicitly
|
||||
bindClientAndAsyncClient(binder(), CloudIdentityAuthenticationApi.class,
|
||||
bindHttpApi(binder(), CloudIdentityAuthenticationApi.class,
|
||||
CloudIdentityAuthenticationAsyncApi.class);
|
||||
bind(AuthenticationApi.class).to(CloudIdentityAuthenticationApi.class).in(Scopes.SINGLETON);
|
||||
bind(AuthenticationAsyncApi.class).to(CloudIdentityAuthenticationAsyncApi.class).in(Scopes.SINGLETON);
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.s3.S3AsyncClient;
|
||||
import org.jclouds.s3.blobstore.functions.BlobToObject;
|
||||
|
@ -38,7 +37,7 @@ import org.jclouds.s3.domain.S3Object;
|
|||
import org.jclouds.s3.options.PutObjectOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -46,7 +45,7 @@ import com.google.common.reflect.TypeToken;
|
|||
*/
|
||||
@Singleton
|
||||
public class S3BlobRequestSigner<T extends S3AsyncClient> implements BlobRequestSigner {
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final RestAnnotationProcessor<T> processor;
|
||||
private final BlobToObject blobToObject;
|
||||
private final BlobToHttpGetOptions blob2HttpGetOptions;
|
||||
|
||||
|
@ -55,26 +54,24 @@ public class S3BlobRequestSigner<T extends S3AsyncClient> implements BlobRequest
|
|||
private final Invokable<?, ?> createMethod;
|
||||
|
||||
@Inject
|
||||
public S3BlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject,
|
||||
public S3BlobRequestSigner(RestAnnotationProcessor<T> processor, BlobToObject blobToObject,
|
||||
BlobToHttpGetOptions blob2HttpGetOptions, Class<T> interfaceType) throws SecurityException,
|
||||
NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
|
||||
this.getMethod = Invokable.from(TypeToken.of(interfaceType),
|
||||
interfaceType.getMethod("getObject", String.class, String.class, GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(TypeToken.of(interfaceType),
|
||||
interfaceType.getMethod("deleteObject", String.class, String.class));
|
||||
this.createMethod = Invokable.from(TypeToken.of(interfaceType),
|
||||
interfaceType.getMethod("putObject", String.class, S3Object.class, PutObjectOptions[].class));
|
||||
this.getMethod = Invokable.from(interfaceType.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,
|
||||
PutObjectOptions[].class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRequest signGetBlob(String container, String name) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
return cleanRequest(processor.apply(Invocation.create( getMethod,
|
||||
ImmutableList.<Object> of(container, name))));
|
||||
return cleanRequest(processor.apply(Invocation.create(getMethod, ImmutableList.<Object> of(container, name))));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,7 +83,7 @@ public class S3BlobRequestSigner<T extends S3AsyncClient> implements BlobRequest
|
|||
public HttpRequest signPutBlob(String container, Blob blob) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(blob, "blob");
|
||||
return cleanRequest(processor.apply(Invocation.create( createMethod,
|
||||
return cleanRequest(processor.apply(Invocation.create(createMethod,
|
||||
ImmutableList.<Object> of(container, blobToObject.apply(blob)))));
|
||||
}
|
||||
|
||||
|
@ -99,15 +96,14 @@ public class S3BlobRequestSigner<T extends S3AsyncClient> implements BlobRequest
|
|||
public HttpRequest signRemoveBlob(String container, String name) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
return cleanRequest(processor.apply(Invocation.create( deleteMethod,
|
||||
ImmutableList.<Object> of(container, name))));
|
||||
return cleanRequest(processor.apply(Invocation.create(deleteMethod, ImmutableList.<Object> of(container, name))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
return cleanRequest(processor.apply(Invocation.create( getMethod,
|
||||
return cleanRequest(processor.apply(Invocation.create(getMethod,
|
||||
ImmutableList.of(container, name, blob2HttpGetOptions.apply(checkNotNull(options, "options"))))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ import org.jclouds.http.functions.ParseSax;
|
|||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.s3.S3Fallbacks.TrueOn404OrNotFoundFalseOnIllegalState;
|
||||
|
@ -80,7 +80,7 @@ import com.google.inject.Module;
|
|||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "S3AsyncClientTest")
|
||||
public class S3AsyncClientTest<T extends S3AsyncClient> extends BaseS3AsyncClientTest<T> {
|
||||
public abstract class S3AsyncClientTest<T extends S3AsyncClient> extends BaseS3AsyncClientTest<T> {
|
||||
|
||||
protected String url = "s3.amazonaws.com";
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.jclouds.s3.internal.BaseS3AsyncClientTest;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindAsHostPrefixIfConfigured}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.testng.annotations.DataProvider;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindAsHostPrefixIfConfigured}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.testng.annotations.BeforeClass;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -43,11 +43,11 @@ import org.jclouds.reflect.Invokable;
|
|||
@Test(testName = "FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest")
|
||||
public class FalseIfBucketAlreadyOwnedByYouOrOperationAbortedWhenBucketExistsTest {
|
||||
|
||||
GeneratedHttpRequest putBucket;
|
||||
GeneratedHttpRequest<S3Client> putBucket;
|
||||
|
||||
@BeforeClass
|
||||
void setUp() throws SecurityException, NoSuchMethodException {
|
||||
putBucket = GeneratedHttpRequest.builder()
|
||||
putBucket = GeneratedHttpRequest.builder(S3Client.class)
|
||||
.method("PUT")
|
||||
.endpoint("https://adriancole-blobstore113.s3.amazonaws.com/")
|
||||
.invocation(
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.SortedSetMultimap;
|
||||
import com.google.common.collect.TreeMultimap;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code RequestAuthorizeSignature}
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.jclouds.openstack.swift.TemporaryUrlKey;
|
|||
import org.jclouds.openstack.swift.blobstore.functions.BlobToObject;
|
||||
import org.jclouds.openstack.swift.domain.SwiftObject;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
|
||||
|
@ -55,7 +54,7 @@ import com.google.common.base.Throwables;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.ByteProcessor;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
|
@ -64,7 +63,7 @@ import com.google.inject.Provider;
|
|||
@Singleton
|
||||
public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRequestSigner {
|
||||
|
||||
private final RestAnnotationProcessor processor;
|
||||
private final RestAnnotationProcessor<T> processor;
|
||||
private final Crypto crypto;
|
||||
|
||||
private final Provider<Long> unixEpochTimestampProvider;
|
||||
|
@ -86,7 +85,7 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
@Inject
|
||||
protected SwiftBlobSigner(BlobToObject blobToObject, BlobToHttpGetOptions blob2HttpGetOptions, Crypto crypto,
|
||||
@TimeStamp Provider<Long> unixEpochTimestampProvider,
|
||||
@TemporaryUrlKey Supplier<String> temporaryUrlKeySupplier, RestAnnotationProcessor processor,
|
||||
@TemporaryUrlKey Supplier<String> temporaryUrlKeySupplier, RestAnnotationProcessor<T> processor,
|
||||
Class<T> interfaceType) throws SecurityException, NoSuchMethodException {
|
||||
this.processor = checkNotNull(processor, "processor");
|
||||
this.crypto = checkNotNull(crypto, "crypto");
|
||||
|
@ -97,27 +96,24 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
this.blobToObject = checkNotNull(blobToObject, "blobToObject");
|
||||
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
|
||||
|
||||
this.getMethod = Invokable.from(TypeToken.of(interfaceType),
|
||||
interfaceType.getMethod("getObject", String.class, String.class, GetOptions[].class));
|
||||
this.deleteMethod = Invokable.from(TypeToken.of(interfaceType),
|
||||
interfaceType.getMethod("removeObject", String.class, String.class));
|
||||
this.createMethod = Invokable.from(TypeToken.of(interfaceType),
|
||||
interfaceType.getMethod("putObject", String.class, SwiftObject.class));
|
||||
this.getMethod = Invokable.from(interfaceType.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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRequest signGetBlob(String container, String name) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
return cleanRequest(processor.apply(Invocation.create(getMethod,
|
||||
ImmutableList.<Object> of(container, name))));
|
||||
return cleanRequest(processor.apply(Invocation.create(getMethod, ImmutableList.<Object> of(container, name))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpRequest signGetBlob(String container, String name, long timeInSeconds) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
GeneratedHttpRequest request = processor.apply(Invocation.create(getMethod,
|
||||
GeneratedHttpRequest<T> request = processor.apply(Invocation.create(getMethod,
|
||||
ImmutableList.<Object> of(container, name)));
|
||||
return cleanRequest(signForTemporaryAccess(request, timeInSeconds));
|
||||
}
|
||||
|
@ -142,7 +138,7 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
public HttpRequest signPutBlob(String container, Blob blob, long timeInSeconds) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(blob, "blob");
|
||||
GeneratedHttpRequest request = processor.apply(Invocation.create(createMethod,
|
||||
GeneratedHttpRequest<T> request = processor.apply(Invocation.create(createMethod,
|
||||
ImmutableList.<Object> of(container, blobToObject.apply(blob))));
|
||||
return cleanRequest(signForTemporaryAccess(request, timeInSeconds));
|
||||
}
|
||||
|
@ -151,8 +147,7 @@ public class SwiftBlobSigner<T extends CommonSwiftAsyncClient> implements BlobRe
|
|||
public HttpRequest signRemoveBlob(String container, String name) {
|
||||
checkNotNull(container, "container");
|
||||
checkNotNull(name, "name");
|
||||
return cleanRequest(processor.apply(Invocation.create(deleteMethod,
|
||||
ImmutableList.<Object> of(container, name))));
|
||||
return cleanRequest(processor.apply(Invocation.create(deleteMethod, ImmutableList.<Object> of(container, name))));
|
||||
}
|
||||
|
||||
private HttpRequest signForTemporaryAccess(HttpRequest request, long timeInSeconds) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.openstack.swift.blobstore.config;
|
||||
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
|
@ -63,7 +63,7 @@ public abstract class TemporaryUrlExtensionModule<A extends CommonSwiftAsyncClie
|
|||
TemporaryUrlExtensionModule<SwiftKeystoneAsyncClient> {
|
||||
|
||||
protected void bindTemporaryUrlKeyApi() {
|
||||
bindClientAndAsyncClient(binder(), TemporaryUrlKeyApi.class, KeystoneTemporaryUrlKeyAsyncApi.class);
|
||||
bindHttpApi(binder(), TemporaryUrlKeyApi.class, KeystoneTemporaryUrlKeyAsyncApi.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,7 +91,7 @@ public abstract class TemporaryUrlExtensionModule<A extends CommonSwiftAsyncClie
|
|||
protected abstract void bindRequestSigner();
|
||||
|
||||
protected void bindTemporaryUrlKeyApi() {
|
||||
bindClientAndAsyncClient(binder(), TemporaryUrlKeyApi.class, TemporaryUrlKeyAsyncApi.class);
|
||||
bindHttpApi(binder(), TemporaryUrlKeyApi.class, TemporaryUrlKeyAsyncApi.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.nnsoft.guice.rocoto.Rocoto;
|
|||
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -43,10 +43,10 @@ public class BasePayloadTest {
|
|||
}
|
||||
}), new GsonModule());
|
||||
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
protected GeneratedHttpRequest<?> requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -28,7 +28,7 @@ import static com.google.common.collect.Iterables.transform;
|
|||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
|
||||
|
@ -206,8 +206,8 @@ public class VCloudRestClientModule extends RestClientModule<VCloudClient, VClou
|
|||
bind(new TypeLiteral<Function<VAppTemplate, Envelope>>() {
|
||||
}).to(new TypeLiteral<ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException>() {
|
||||
});
|
||||
bindClientAndAsyncClient(binder(), VCloudVersionsClient.class, VCloudVersionsAsyncClient.class);
|
||||
bindClientAndAsyncClient(binder(), VCloudLoginClient.class, VCloudLoginAsyncClient.class);
|
||||
bindHttpApi(binder(), VCloudVersionsClient.class, VCloudVersionsAsyncClient.class);
|
||||
bindHttpApi(binder(), VCloudLoginClient.class, VCloudLoginAsyncClient.class);
|
||||
}
|
||||
|
||||
protected void bindCacheLoaders() {
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.providers.AnonymousProviderMetadata;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.net.URI;
|
|||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest;
|
||||
import org.jclouds.vcloud.options.CatalogItemOptions;
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.net.URI;
|
|||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest;
|
||||
import org.jclouds.vcloud.xml.OrgNetworkHandler;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.net.URI;
|
|||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest;
|
||||
import org.jclouds.vcloud.xml.OrgHandler;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.net.URI;
|
|||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
|||
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest;
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.net.URI;
|
|||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.ovf.xml.EnvelopeHandler;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.domain.network.FenceMode;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.NoSuchElementException;
|
|||
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.internal.BaseVCloudAsyncClientTest;
|
||||
import org.jclouds.vcloud.xml.VDCHandler;
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
|||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnInputStream;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.domain.GuestCustomizationSection;
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.nnsoft.guice.rocoto.Rocoto;
|
|||
import org.nnsoft.guice.rocoto.configuration.ConfigurationModule;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -40,10 +40,10 @@ public class BasePayloadTest {
|
|||
}
|
||||
}));
|
||||
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
protected GeneratedHttpRequest<?> requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.http.filters.BasicAuthentication;
|
|||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.providers.AnonymousProviderMetadata;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.endpoints.VCloudLogin;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.blobstore.config;
|
||||
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindBlockingApi;
|
||||
|
||||
import org.jclouds.blobstore.AsyncBlobStore;
|
||||
import org.jclouds.blobstore.BlobRequestSigner;
|
||||
|
@ -41,7 +41,7 @@ public class TransientBlobStoreContextModule extends AbstractModule {
|
|||
protected void configure() {
|
||||
bind(AsyncBlobStore.class).to(LocalAsyncBlobStore.class).asEagerSingleton();
|
||||
// forward all requests from TransientBlobStore to TransientAsyncBlobStore. needs above binding as cannot proxy a class
|
||||
bindClient(binder(), LocalBlobStore.class, AsyncBlobStore.class);
|
||||
bindBlockingApi(binder(), LocalBlobStore.class, AsyncBlobStore.class);
|
||||
install(new BlobStoreObjectModule());
|
||||
install(new BlobStoreMapModule());
|
||||
bind(BlobStore.class).to(LocalBlobStore.class);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.blobstore.AsyncBlobStore;
|
|||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.Providers;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -40,7 +41,6 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BlobStoreUtils}
|
||||
|
@ -125,23 +125,23 @@ public class BlobStoreUtilsTest {
|
|||
}
|
||||
|
||||
public void testGetKeyForAzureS3AndRackspace() {
|
||||
GeneratedHttpRequest request = requestForEndpointAndArgs(
|
||||
GeneratedHttpRequest<?> request = requestForEndpointAndArgs(
|
||||
"https://jclouds.blob.core.windows.net/adriancole-blobstore0/five",
|
||||
ImmutableList.<Object> of("adriancole-blobstore0", "five"));
|
||||
assertEquals(getNameFor(request), "five");
|
||||
}
|
||||
|
||||
public void testGetKeyForAtmos() {
|
||||
GeneratedHttpRequest request = requestForEndpointAndArgs(
|
||||
GeneratedHttpRequest<?> request = requestForEndpointAndArgs(
|
||||
"https://storage4.clouddrive.com/v1/MossoCloudFS_dc1f419c-5059-4c87-a389-3f2e33a77b22/adriancole-blobstore0/four",
|
||||
ImmutableList.<Object> of("adriancole-blobstore0/four"));
|
||||
assertEquals(getNameFor(request), "four");
|
||||
}
|
||||
|
||||
GeneratedHttpRequest requestForEndpointAndArgs(String endpoint, List<Object> args) {
|
||||
GeneratedHttpRequest<?> requestForEndpointAndArgs(String endpoint, List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create(endpoint)).invocation(invocation)
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create(endpoint)).invocation(invocation)
|
||||
.build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.openstack.config;
|
||||
|
||||
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -59,7 +59,7 @@ public class OpenStackAuthenticationModule extends AbstractModule {
|
|||
@Override
|
||||
protected void configure() {
|
||||
// OpenStackAuthClient is used directly for filters and retry handlers, so let's bind it explicitly
|
||||
bindClientAndAsyncClient(binder(), OpenStackAuthClient.class, OpenStackAuthAsyncClient.class);
|
||||
bindHttpApi(binder(), OpenStackAuthClient.class, OpenStackAuthAsyncClient.class);
|
||||
install(new FactoryModuleBuilder().build(URIFromAuthenticationResponseForService.Factory.class));
|
||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(RetryOnRenew.class);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.openstack.keystone.v1_1.config;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -59,7 +59,7 @@ public class AuthenticationServiceModule extends AbstractModule {
|
|||
@Override
|
||||
protected void configure() {
|
||||
// ServiceClient is used directly for filters and retry handlers, so let's bind it explicitly
|
||||
bindClientAndAsyncClient(binder(), AuthenticationClient.class, AuthenticationAsyncClient.class);
|
||||
bindHttpApi(binder(), AuthenticationClient.class, AuthenticationAsyncClient.class);
|
||||
install(new FactoryModuleBuilder().implement(RegionIdToURISupplier.class,
|
||||
RegionIdToURIFromAuthForServiceSupplier.class).build(RegionIdToURISupplier.Factory.class));
|
||||
install(new FactoryModuleBuilder().implement(ImplicitRegionIdSupplier.class, V1DefaultRegionIdSupplier.class)
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.IntegrationTestAsyncClient;
|
||||
import org.jclouds.http.IntegrationTestClient;
|
||||
import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.AnonymousRestApiMetadata;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
|
|
@ -26,7 +26,7 @@ import static com.google.common.collect.Iterables.transform;
|
|||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.collect.Maps.uniqueIndex;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -134,8 +134,8 @@ public class TerremarkVCloudRestClientModule<S, A> extends RestClientModule<S, A
|
|||
bind(new TypeLiteral<Function<org.jclouds.trmk.vcloud_0_8.domain.Org, Iterable<? extends CatalogItem>>>() {
|
||||
}).to(new TypeLiteral<AllCatalogItemsInOrg>() {
|
||||
});
|
||||
bindClientAndAsyncClient(binder(), TerremarkVCloudVersionsClient.class, TerremarkVCloudVersionsAsyncClient.class);
|
||||
bindClientAndAsyncClient(binder(), TerremarkVCloudLoginClient.class, TerremarkVCloudLoginAsyncClient.class);
|
||||
bindHttpApi(binder(), TerremarkVCloudVersionsClient.class, TerremarkVCloudVersionsAsyncClient.class);
|
||||
bindHttpApi(binder(), TerremarkVCloudLoginClient.class, TerremarkVCloudLoginAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -25,14 +25,14 @@ import org.jclouds.reflect.Invocation;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
public class BasePayloadTest {
|
||||
|
||||
protected GeneratedHttpRequest requestForArgs(List<Object> args) {
|
||||
protected GeneratedHttpRequest<?> requestForArgs(List<Object> args) {
|
||||
try {
|
||||
Invocation invocation = Invocation.create(Invokable.from(String.class.getDeclaredMethod("toString")), args);
|
||||
return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
return GeneratedHttpRequest.builder(String.class).method("POST").endpoint(URI.create("http://localhost/key"))
|
||||
.invocation(invocation).build();
|
||||
} catch (SecurityException e) {
|
||||
throw Throwables.propagate(e);
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.jclouds.http.filters.BasicAuthentication;
|
|||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.providers.AnonymousProviderMetadata;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.trmk.vcloud_0_8.endpoints.VCloudLogin;
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.providers.AnonymousProviderMetadata;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.BaseAsyncClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.trmk.vcloud_0_8.xml.SupportedVersionsHandler;
|
||||
|
|
|
@ -55,7 +55,7 @@ import com.google.common.base.Optional;
|
|||
public abstract class CallerArg0ToPagedIterable<T, I extends CallerArg0ToPagedIterable<T, I>> implements
|
||||
Function<IterableWithMarker<T>, PagedIterable<T>>, InvocationContext<I> {
|
||||
|
||||
private GeneratedHttpRequest request;
|
||||
private GeneratedHttpRequest<?> request;
|
||||
|
||||
@Override
|
||||
public PagedIterable<T> apply(IterableWithMarker<T> input) {
|
||||
|
|
|
@ -66,7 +66,7 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,180 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.reflect;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.reflect.Invokable;
|
||||
|
||||
/**
|
||||
*
|
||||
* based on the {@link com.google.reflect.AccessibleObject} copied in as {@link com.google.reflect.Invokable} is package
|
||||
* private.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @since 1.6
|
||||
*/
|
||||
class Element extends AccessibleObject implements Member {
|
||||
|
||||
private final AccessibleObject accessibleObject;
|
||||
protected final Member member;
|
||||
|
||||
<M extends AccessibleObject & Member> Element( M member) {
|
||||
this.member = checkNotNull(member, "member");
|
||||
this.accessibleObject = member;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
|
||||
return accessibleObject.isAnnotationPresent(annotationClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
|
||||
return accessibleObject.getAnnotation(annotationClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Annotation[] getAnnotations() {
|
||||
return accessibleObject.getAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Annotation[] getDeclaredAnnotations() {
|
||||
return accessibleObject.getDeclaredAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setAccessible(boolean flag) throws SecurityException {
|
||||
accessibleObject.setAccessible(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isAccessible() {
|
||||
return accessibleObject.isAccessible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getDeclaringClass() {
|
||||
return member.getDeclaringClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getName() {
|
||||
return member.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getModifiers() {
|
||||
return member.getModifiers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isSynthetic() {
|
||||
return member.isSynthetic();
|
||||
}
|
||||
|
||||
/** Returns true if the element is public. */
|
||||
public final boolean isPublic() {
|
||||
return Modifier.isPublic(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the element is protected. */
|
||||
public final boolean isProtected() {
|
||||
return Modifier.isProtected(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the element is package-private. */
|
||||
public final boolean isPackagePrivate() {
|
||||
return !isPrivate() && !isPublic() && !isProtected();
|
||||
}
|
||||
|
||||
/** Returns true if the element is private. */
|
||||
public final boolean isPrivate() {
|
||||
return Modifier.isPrivate(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the element is static. */
|
||||
public final boolean isStatic() {
|
||||
return Modifier.isStatic(getModifiers());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this method is final, per {@code Modifier.isFinal(getModifiers())}.
|
||||
*
|
||||
* <p>
|
||||
* Note that a method may still be effectively "final", or non-overridable when it has no {@code final} keyword. For
|
||||
* example, it could be private, or it could be declared by a final class. To tell whether a method is overridable,
|
||||
* use {@link Invokable#isOverridable}.
|
||||
*/
|
||||
public final boolean isFinal() {
|
||||
return Modifier.isFinal(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the method is abstract. */
|
||||
public final boolean isAbstract() {
|
||||
return Modifier.isAbstract(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the element is native. */
|
||||
public final boolean isNative() {
|
||||
return Modifier.isNative(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the method is synchronized. */
|
||||
public final boolean isSynchronized() {
|
||||
return Modifier.isSynchronized(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the field is volatile. */
|
||||
final boolean isVolatile() {
|
||||
return Modifier.isVolatile(getModifiers());
|
||||
}
|
||||
|
||||
/** Returns true if the field is transient. */
|
||||
final boolean isTransient() {
|
||||
return Modifier.isTransient(getModifiers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof Element) {
|
||||
Element that = (Element) obj;
|
||||
return member.equals(that.member);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return member.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return member.toString();
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@ import com.google.common.annotations.Beta;
|
|||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
|
@ -113,7 +114,7 @@ public final class FunctionalReflection {
|
|||
args = ImmutableList.copyOf(args);
|
||||
else
|
||||
args = Collections.unmodifiableList(args);
|
||||
Invokable<T, ?> invokable = Invokable.from(enclosingType, invoked);
|
||||
Invokable<?, Object> invokable = Invokable.from(invoked);
|
||||
// not yet support the proxy arg
|
||||
Invocation invocation = Invocation.create(invokable, args);
|
||||
Result result;
|
||||
|
|
|
@ -28,9 +28,10 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
* Context needed to call {@link org.jclouds.reflect.Invokable#invoke(Object, Object...)}
|
||||
* Context needed to call {@link com.google.common.reflect.Invokable#invoke(Object, Object...)}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.google.common.base.Objects.ToStringHelper;
|
|||
import com.google.common.base.Optional;
|
||||
|
||||
/**
|
||||
* Holds the context of a successful call to {@link org.jclouds.reflect.Invokable#invoke(Object, Object...)}
|
||||
* Holds the context of a successful call to {@link com.google.common.reflect.Invokable#invoke(Object, Object...)}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
|
|
@ -1,347 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.reflect;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* based on the {@link com.google.reflect.AccessibleObject} copied in as {@link com.google.reflect.Invokable} is package
|
||||
* private. This adds access to {#link {@link #getEnclosingType()} and folds in ability to lookup methods and
|
||||
* constructors by name.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @since 1.6
|
||||
*/
|
||||
@Beta
|
||||
public abstract class Invokable<T, R> extends Element implements GenericDeclaration {
|
||||
protected final TypeToken<?> enclosingType;
|
||||
|
||||
<M extends AccessibleObject & Member> Invokable(TypeToken<?> enclosingType, M member) {
|
||||
super(member);
|
||||
this.enclosingType = checkNotNull(enclosingType, "enclosingType");
|
||||
}
|
||||
|
||||
/** Returns {@link Invokable} of {@code method}. */
|
||||
public static Invokable<?, Object> from(Method method) {
|
||||
return from(TypeToken.of(method.getDeclaringClass()), method);
|
||||
}
|
||||
|
||||
/** Returns {@link Invokable} of {@code constructor}. */
|
||||
public static <T> Invokable<T, T> from(Constructor<T> constructor) {
|
||||
return from(TypeToken.of(constructor.getDeclaringClass()), constructor);
|
||||
}
|
||||
|
||||
/** Returns {@link Invokable} of {@code method}. */
|
||||
public static <T> Invokable<T, Object> from(TypeToken<T> enclosingType, Method method) {
|
||||
return new MethodInvokable<T>(enclosingType, method);
|
||||
}
|
||||
|
||||
/** Returns {@link Invokable} of {@code constructor}. */
|
||||
public static <T> Invokable<T, T> from(TypeToken<T> enclosingType, Constructor<T> constructor) {
|
||||
return new ConstructorInvokable<T>(enclosingType, constructor);
|
||||
}
|
||||
|
||||
/**
|
||||
* different than {@link #getDeclaringClass()} when this is a member of a class it was not declared in.
|
||||
*/
|
||||
public TypeToken<?> getEnclosingType() {
|
||||
return enclosingType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this is an overridable method. Constructors, private, static or final methods, or methods
|
||||
* declared by final classes are not overridable.
|
||||
*/
|
||||
public abstract boolean isOverridable();
|
||||
|
||||
/** Returns {@code true} if this was declared to take a variable number of arguments. */
|
||||
public abstract boolean isVarArgs();
|
||||
|
||||
/**
|
||||
* Invokes with {@code receiver} as 'this' and {@code args} passed to the underlying method and returns the return
|
||||
* value; or calls the underlying constructor with {@code args} and returns the constructed instance.
|
||||
*
|
||||
* @throws IllegalAccessException
|
||||
* if this {@code Constructor} object enforces Java language access control and the underlying method or
|
||||
* constructor is inaccessible.
|
||||
* @throws IllegalArgumentException
|
||||
* if the number of actual and formal parameters differ; if an unwrapping conversion for primitive
|
||||
* arguments fails; or if, after possible unwrapping, a parameter value cannot be converted to the
|
||||
* corresponding formal parameter type by a method invocation conversion.
|
||||
* @throws InvocationTargetException
|
||||
* if the underlying method or constructor throws an exception.
|
||||
*/
|
||||
// All subclasses are owned by us and we'll make sure to get the R type right.
|
||||
@SuppressWarnings("unchecked")
|
||||
public final R invoke(@Nullable T receiver, Object... args) throws InvocationTargetException, IllegalAccessException {
|
||||
return (R) invokeInternal(receiver, checkNotNull(args, "args"));
|
||||
}
|
||||
|
||||
/** Returns the return type of this {@code Invokable}. */
|
||||
// All subclasses are owned by us and we'll make sure to get the R type right.
|
||||
@SuppressWarnings("unchecked")
|
||||
public final TypeToken<? extends R> getReturnType() {
|
||||
return (TypeToken<? extends R>) TypeToken.of(getGenericReturnType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all declared parameters of this {@code Invokable}. Note that if this is a constructor of a non-static
|
||||
* inner class, unlike {@link Constructor#getParameterTypes}, the hidden {@code this} parameter of the enclosing
|
||||
* class is excluded from the returned parameters.
|
||||
*/
|
||||
public final ImmutableList<Parameter> getParameters() {
|
||||
Type[] parameterTypes = getGenericParameterTypes();
|
||||
Annotation[][] annotations = getParameterAnnotations();
|
||||
ImmutableList.Builder<Parameter> builder = ImmutableList.builder();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
builder.add(new Parameter(this, i, TypeToken.of(parameterTypes[i]), annotations[i]));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/** Returns all declared exception types of this {@code Invokable}. */
|
||||
public final ImmutableList<TypeToken<? extends Throwable>> getExceptionTypes() {
|
||||
ImmutableList.Builder<TypeToken<? extends Throwable>> builder = ImmutableList.builder();
|
||||
for (Type type : getGenericExceptionTypes()) {
|
||||
// getGenericExceptionTypes() will never return a type that's not exception
|
||||
@SuppressWarnings("unchecked")
|
||||
TypeToken<? extends Throwable> exceptionType = (TypeToken<? extends Throwable>) TypeToken.of(type);
|
||||
builder.add(exceptionType);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly specifies the return type of this {@code Invokable}. For example:
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* @code
|
||||
* Method factoryMethod = Person.class.getMethod("create");
|
||||
* Invokable<?, Person> factory = Invokable.of(getNameMethod).returning(Person.class);
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public final <R1 extends R> Invokable<T, R1> returning(Class<R1> returnType) {
|
||||
return returning(TypeToken.of(returnType));
|
||||
}
|
||||
|
||||
/** Explicitly specifies the return type of this {@code Invokable}. */
|
||||
public final <R1 extends R> Invokable<T, R1> returning(TypeToken<R1> returnType) {
|
||||
if (!returnType.isAssignableFrom(getReturnType())) {
|
||||
throw new IllegalArgumentException("Invokable is known to return " + getReturnType() + ", not " + returnType);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
// guarded by previous check
|
||||
Invokable<T, R1> specialized = (Invokable<T, R1>) this;
|
||||
return specialized;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// The declaring class is T's raw class, or one of its supertypes.
|
||||
@Override
|
||||
public final Class<? super T> getDeclaringClass() {
|
||||
return (Class<? super T>) super.getDeclaringClass();
|
||||
}
|
||||
|
||||
abstract Object invokeInternal(@Nullable Object receiver, Object[] args) throws InvocationTargetException,
|
||||
IllegalAccessException;
|
||||
|
||||
abstract Type[] getGenericParameterTypes();
|
||||
|
||||
/** This should never return a type that's not a subtype of Throwable. */
|
||||
abstract Type[] getGenericExceptionTypes();
|
||||
|
||||
abstract Annotation[][] getParameterAnnotations();
|
||||
|
||||
abstract Type getGenericReturnType();
|
||||
|
||||
static class MethodInvokable<T> extends Invokable<T, Object> {
|
||||
|
||||
private final Method method;
|
||||
|
||||
MethodInvokable(TypeToken<?> enclosingType, Method method) {
|
||||
super(enclosingType, method);
|
||||
this.method = method;
|
||||
checkArgument(TypeToken.of(method.getDeclaringClass()).isAssignableFrom(enclosingType),
|
||||
"%s not declared by %s", method, enclosingType);
|
||||
}
|
||||
|
||||
@Override
|
||||
final Object invokeInternal(@Nullable Object receiver, Object[] args) throws InvocationTargetException,
|
||||
IllegalAccessException {
|
||||
return method.invoke(receiver, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
Type getGenericReturnType() {
|
||||
return resolveType(method.getGenericReturnType()).getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
Type[] getGenericParameterTypes() {
|
||||
return resolveInPlace(method.getGenericParameterTypes());
|
||||
}
|
||||
|
||||
@Override
|
||||
Type[] getGenericExceptionTypes() {
|
||||
return resolveInPlace(method.getGenericExceptionTypes());
|
||||
}
|
||||
|
||||
@Override
|
||||
final Annotation[][] getParameterAnnotations() {
|
||||
return method.getParameterAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TypeVariable<?>[] getTypeParameters() {
|
||||
return method.getTypeParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isOverridable() {
|
||||
return !(isFinal() || isPrivate() || isStatic() || Modifier.isFinal(getDeclaringClass().getModifiers()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isVarArgs() {
|
||||
return method.isVarArgs();
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeToken<?> resolveType(Type type) {
|
||||
return enclosingType.resolveType(type);
|
||||
}
|
||||
|
||||
protected Type[] resolveInPlace(Type[] types) {
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
types[i] = resolveType(types[i]).getType();
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
static class ConstructorInvokable<T> extends Invokable<T, T> {
|
||||
|
||||
private final Constructor<?> constructor;
|
||||
|
||||
ConstructorInvokable(TypeToken<?> enclosingType, Constructor<?> constructor) {
|
||||
super(enclosingType, constructor);
|
||||
this.constructor = constructor;
|
||||
checkArgument(constructor.getDeclaringClass() == enclosingType.getRawType(), "%s not declared by %s",
|
||||
constructor, enclosingType.getRawType());
|
||||
}
|
||||
|
||||
@Override
|
||||
final Object invokeInternal(@Nullable Object receiver, Object[] args) throws InvocationTargetException,
|
||||
IllegalAccessException {
|
||||
try {
|
||||
return constructor.newInstance(args);
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(constructor + " failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Type getGenericReturnType() {
|
||||
return resolveType(constructor.getDeclaringClass()).getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
Type[] getGenericParameterTypes() {
|
||||
Type[] types = constructor.getGenericParameterTypes();
|
||||
Class<?> declaringClass = constructor.getDeclaringClass();
|
||||
if (!Modifier.isStatic(declaringClass.getModifiers()) && declaringClass.getEnclosingClass() != null) {
|
||||
if (types.length == constructor.getParameterTypes().length) {
|
||||
// first parameter is the hidden 'this'
|
||||
return Arrays.copyOfRange(types, 1, types.length);
|
||||
}
|
||||
}
|
||||
return resolveInPlace(types);
|
||||
}
|
||||
|
||||
@Override
|
||||
Type[] getGenericExceptionTypes() {
|
||||
return resolveInPlace(constructor.getGenericExceptionTypes());
|
||||
}
|
||||
|
||||
@Override
|
||||
final Annotation[][] getParameterAnnotations() {
|
||||
return constructor.getParameterAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TypeVariable<?>[] getTypeParameters() {
|
||||
return constructor.getTypeParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isOverridable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isVarArgs() {
|
||||
return constructor.isVarArgs();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Invokable<?, ?> that = Invokable.class.cast(o);
|
||||
return equal(this.enclosingType, that.enclosingType) && super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(enclosingType, super.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
int parametersTypeHashCode = 0;
|
||||
for (Parameter param : getParameters())
|
||||
parametersTypeHashCode += param.getType().hashCode();
|
||||
return String.format("%s.%s[%s]", enclosingType.getRawType().getSimpleName(), getName(), parametersTypeHashCode);
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.reflect;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
*
|
||||
* based on the {@link com.google.reflect.AccessibleObject} copied in as {@link com.google.reflect.Parameter} is package
|
||||
* private and decided not to add {@link #getPosition}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @since 1.6
|
||||
*/
|
||||
@Beta
|
||||
public final class Parameter implements AnnotatedElement {
|
||||
|
||||
private final Invokable<?, ?> declaration;
|
||||
private final int position;
|
||||
private final TypeToken<?> type;
|
||||
private final ImmutableList<Annotation> annotations;
|
||||
|
||||
Parameter(Invokable<?, ?> declaration, int position, TypeToken<?> type, Annotation[] annotations) {
|
||||
this.declaration = declaration;
|
||||
this.position = position;
|
||||
this.type = type;
|
||||
this.annotations = ImmutableList.copyOf(annotations);
|
||||
}
|
||||
|
||||
/** Returns the position of the parameter. */
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/** Returns the type of the parameter. */
|
||||
public TypeToken<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/** Returns the {@link Invokable} that declares this parameter. */
|
||||
public Invokable<?, ?> getDeclaringInvokable() {
|
||||
return declaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||
return getAnnotation(annotationType) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
|
||||
checkNotNull(annotationType);
|
||||
for (Annotation annotation : annotations) {
|
||||
if (annotationType.isInstance(annotation)) {
|
||||
return annotationType.cast(annotation);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Annotation[] getAnnotations() {
|
||||
return getDeclaredAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Annotation[] getDeclaredAnnotations() {
|
||||
return annotations.toArray(new Annotation[annotations.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof Parameter) {
|
||||
Parameter that = (Parameter) obj;
|
||||
return position == that.position && declaration.equals(that.declaration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type + " arg" + position;
|
||||
}
|
||||
}
|
|
@ -27,12 +27,12 @@ import javax.inject.Inject;
|
|||
|
||||
import org.jclouds.predicates.Validator;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Parameter;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.reflect.Parameter;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.rest.MapBinder;
|
|||
import org.jclouds.rest.annotations.Payload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import com.google.common.reflect.Invokable;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -22,7 +22,8 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.reflect.FunctionalReflection;
|
||||
import org.jclouds.rest.internal.InvokeAsyncApi;
|
||||
import org.jclouds.rest.internal.DelegatingInvocationFunction;
|
||||
import org.jclouds.rest.internal.InvokeHttpMethod;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -32,21 +33,21 @@ import com.google.inject.TypeLiteral;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class AsyncClientProvider<A> implements Provider<A> {
|
||||
private final Class<? super A> asyncClientType;
|
||||
private final InvokeAsyncApi proxy;
|
||||
public class AsyncHttpApiProvider<A> implements Provider<A> {
|
||||
private final Class<? super A> asyncApiType;
|
||||
private final DelegatingInvocationFunction<A, A, InvokeHttpMethod<A, A>> httpInvoker;
|
||||
|
||||
@Inject
|
||||
private AsyncClientProvider(InvokeAsyncApi proxy, TypeLiteral<A> asyncClientType) {
|
||||
this.proxy = proxy;
|
||||
this.asyncClientType = asyncClientType.getRawType();
|
||||
private AsyncHttpApiProvider(DelegatingInvocationFunction<A, A, InvokeHttpMethod<A, A>> httpInvoker,
|
||||
TypeLiteral<A> asyncApiType) {
|
||||
this.httpInvoker = httpInvoker;
|
||||
this.asyncApiType = asyncApiType.getRawType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Singleton
|
||||
public A get() {
|
||||
return (A) FunctionalReflection.newProxy(asyncClientType, proxy);
|
||||
return (A) FunctionalReflection.newProxy(asyncApiType, httpInvoker);
|
||||
}
|
||||
|
||||
}
|
|
@ -45,13 +45,31 @@ public class BinderUtils {
|
|||
* @param async
|
||||
* type type that returns {@link ListenableFuture}
|
||||
*/
|
||||
public static <S, A> void bindClientAndAsyncClient(Binder binder, Class<S> sync, Class<A> async) {
|
||||
public static <S, A> void bindHttpApi(Binder binder, Class<S> sync, Class<A> async) {
|
||||
bindClass(binder, sync);
|
||||
bindClass(binder, async);
|
||||
bindAsyncClientProvider(binder, async);
|
||||
bindClientProvider(binder, sync, async);
|
||||
bindAsyncHttpApiProvider(binder, async);
|
||||
bindHttpApiProvider(binder, sync, async);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> void bindAsyncHttpApiProvider(Binder binder, Class<T> async) {
|
||||
TypeToken<AsyncHttpApiProvider<T>> token = new TypeToken<AsyncHttpApiProvider<T>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<T>() {
|
||||
}, async);
|
||||
binder.bind(async).toProvider(TypeLiteral.class.cast(TypeLiteral.get(token.getType())));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <S, A> void bindHttpApiProvider(Binder binder, Class<S> sync, Class<A> async) {
|
||||
TypeToken<HttpApiProvider<S, A>> token = new TypeToken<HttpApiProvider<S, A>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<S>() {
|
||||
}, sync).where(new TypeParameter<A>() {
|
||||
}, async);
|
||||
binder.bind(sync).toProvider(TypeLiteral.class.cast(TypeLiteral.get(token.getType())));
|
||||
}
|
||||
|
||||
/**
|
||||
* adds an explicit binding for an interface which synchronously blocks on similar calls to an {@code async} type.
|
||||
*
|
||||
|
@ -66,15 +84,15 @@ public class BinderUtils {
|
|||
* @param async
|
||||
* type type that returns {@link ListenableFuture}
|
||||
*/
|
||||
public static <S, A> void bindClient(Binder binder, Class<S> sync, Class<A> async) {
|
||||
public static <S, A> void bindBlockingApi(Binder binder, Class<S> sync, Class<A> async) {
|
||||
bindClass(binder, sync);
|
||||
bindClass(binder, async);
|
||||
bindClientProvider(binder, sync, async);
|
||||
bindCallGetOnFutures(binder, sync, async);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <S, A> void bindClientProvider(Binder binder, Class<S> sync, Class<A> async) {
|
||||
TypeToken<ClientProvider<S, A>> token = new TypeToken<ClientProvider<S, A>>() {
|
||||
private static <S, A> void bindCallGetOnFutures(Binder binder, Class<S> sync, Class<A> async) {
|
||||
TypeToken<CallGetOnFuturesProvider<S, A>> token = new TypeToken<CallGetOnFuturesProvider<S, A>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<S>() {
|
||||
}, sync).where(new TypeParameter<A>() {
|
||||
|
@ -89,19 +107,4 @@ public class BinderUtils {
|
|||
}.where(new TypeParameter<K>() {
|
||||
}, sync).getType()))).toInstance(sync);
|
||||
}
|
||||
|
||||
public static <T> void bindAsyncClient(Binder binder, Class<T> async) {
|
||||
bindClass(binder, async);
|
||||
bindAsyncClientProvider(binder, async);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> void bindAsyncClientProvider(Binder binder, Class<T> async) {
|
||||
TypeToken<AsyncClientProvider<T>> token = new TypeToken<AsyncClientProvider<T>>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}.where(new TypeParameter<T>() {
|
||||
}, async);
|
||||
binder.bind(async).toProvider(TypeLiteral.class.cast(TypeLiteral.get(token.getType())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.rest.config;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.reflect.FunctionalReflection;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.DelegatingInvocationFunction;
|
||||
import org.jclouds.rest.internal.InvokeAndCallGetOnFutures;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class CallGetOnFuturesProvider<S, A> implements Provider<S> {
|
||||
|
||||
private final Class<? super S> apiType;
|
||||
private final DelegatingInvocationFunction<S, A, InvokeAndCallGetOnFutures<A>> syncInvoker;
|
||||
|
||||
@Inject
|
||||
private CallGetOnFuturesProvider(Cache<Invokable<?, ?>, Invokable<?, ?>> invokables,
|
||||
DelegatingInvocationFunction<S, A, InvokeAndCallGetOnFutures<A>> syncInvoker, Class<S> apiType,
|
||||
Class<A> asyncApiType) {
|
||||
this.syncInvoker = syncInvoker;
|
||||
this.apiType = apiType;
|
||||
RestModule.putInvokables(TypeToken.of(apiType), TypeToken.of(asyncApiType), invokables);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Singleton
|
||||
public S get() {
|
||||
return (S) FunctionalReflection.newProxy(apiType, syncInvoker);
|
||||
}
|
||||
}
|
|
@ -22,38 +22,36 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.reflect.FunctionalReflection;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.InvokeSyncApi;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.internal.DelegatingInvocationFunction;
|
||||
import org.jclouds.rest.internal.InvokeHttpMethod;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
/**
|
||||
* ClientProvider makes the primary interface for the provider context. ex.
|
||||
* {@code context.getProviderSpecificContext().getApi()} is created by ClientProvider, which is a singleton
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ClientProvider<S, A> implements Provider<S> {
|
||||
|
||||
private final InvokeSyncApi.Factory factory;
|
||||
private final Class<S> syncClientType;
|
||||
private final A asyncClient;
|
||||
public class HttpApiProvider<S, A> implements Provider<S> {
|
||||
private final Class<? super S> apiType;
|
||||
private final DelegatingInvocationFunction<S, A, InvokeHttpMethod<S, A>> httpInvoker;
|
||||
|
||||
@Inject
|
||||
private ClientProvider(Cache<Invokable<?, ?>, Invokable<?, ?>> invokables, InvokeSyncApi.Factory factory,
|
||||
Class<S> syncClientType, Class<A> asyncClientType, A asyncClient) {
|
||||
this.factory = factory;
|
||||
this.asyncClient = asyncClient;
|
||||
this.syncClientType = syncClientType;
|
||||
RestModule.putInvokables(TypeToken.of(syncClientType), TypeToken.of(asyncClientType), invokables);
|
||||
private HttpApiProvider(Cache<Invokable<?, ?>, Invokable<?, ?>> invokables,
|
||||
DelegatingInvocationFunction<S, A, InvokeHttpMethod<S, A>> httpInvoker, Class<S> apiType, Class<A> asyncApiType) {
|
||||
this.httpInvoker = httpInvoker;
|
||||
this.apiType = apiType;
|
||||
RestModule.putInvokables(TypeToken.of(apiType), TypeToken.of(asyncApiType), invokables);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Singleton
|
||||
public S get() {
|
||||
return FunctionalReflection.newProxy(syncClientType, factory.create(asyncClient));
|
||||
return (S) FunctionalReflection.newProxy(apiType, httpInvoker);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
package org.jclouds.rest.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Map;
|
||||
|
@ -87,7 +87,7 @@ public class RestClientModule<S, A> extends RestModule {
|
|||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bindClientAndAsyncClient(binder(), syncClientType.getRawType(), asyncClientType.getRawType());
|
||||
bindHttpApi(binder(), syncClientType.getRawType(), asyncClientType.getRawType());
|
||||
bindErrorHandlers();
|
||||
bindRetryHandlers();
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@ package org.jclouds.rest.config;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Maps.transformValues;
|
||||
import static com.google.common.util.concurrent.Atomics.newReference;
|
||||
import static org.jclouds.Constants.PROPERTY_TIMEOUTS_PREFIX;
|
||||
import static org.jclouds.http.HttpUtils.tryFindHttpMethod;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindClientAndAsyncClient;
|
||||
import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
|
||||
import static org.jclouds.util.Maps2.transformKeys;
|
||||
import static org.jclouds.util.Predicates2.startsWith;
|
||||
|
||||
|
@ -38,40 +36,27 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.internal.FilterStringsBoundToInjectorByName;
|
||||
import org.jclouds.json.config.GsonModule;
|
||||
import org.jclouds.location.config.LocationModule;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import org.jclouds.reflect.Parameter;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.HttpAsyncClient;
|
||||
import org.jclouds.rest.HttpClient;
|
||||
import org.jclouds.rest.binders.BindToJsonPayloadWrappedWith;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.InvokeAsyncApi;
|
||||
import org.jclouds.rest.internal.InvokeFutureAndBlock;
|
||||
import org.jclouds.rest.internal.InvokeListenableFutureViaHttp;
|
||||
import org.jclouds.rest.internal.InvokeSyncApi;
|
||||
import org.jclouds.rest.internal.TransformerForRequest;
|
||||
import org.jclouds.rest.internal.BlockOnFuture;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -94,42 +79,7 @@ public class RestModule extends AbstractModule {
|
|||
public RestModule(Map<Class<?>, Class<?>> sync2Async) {
|
||||
this.sync2Async = sync2Async;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<Invokable<?, ?>> mapsToAsyncHttpRequest(final Cache<Invokable<?, ?>, Invokable<?, ?>> backing) {
|
||||
return new Predicate<Invokable<?, ?>>() {
|
||||
public boolean apply(Invokable<?, ?> in) { // TODO: this is dynamic, but perhaps needs to be cached
|
||||
return FluentIterable.from(backing.asMap().values()).anyMatch(mapsToAsyncHttpRequest(in));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Predicate<Invokable<?, ?>> mapsToAsyncHttpRequest(Invokable<?, ?> toTest) {
|
||||
final int soughtHash = hashEnclosingTypeNameAndParameters(toTest);
|
||||
return new Predicate<Invokable<?, ?>>() {
|
||||
public boolean apply(Invokable<?, ?> in) {
|
||||
return in.isAnnotationPresent(Path.class) || tryFindHttpMethod(in).isPresent()
|
||||
|| any(in.getParameters(), new Predicate<Parameter>() {
|
||||
public boolean apply(Parameter in) {
|
||||
return in.getType().getRawType().isAssignableFrom(HttpRequest.class);
|
||||
}
|
||||
}) && in.getReturnType().getRawType().isAssignableFrom(ListenableFuture.class)
|
||||
&& soughtHash == hashEnclosingTypeNameAndParameters(in);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* when looking for a match, we ignore the return type
|
||||
*/
|
||||
public static int hashEnclosingTypeNameAndParameters(Invokable<?, ?> in) {
|
||||
int parametersTypeHashCode = 0;
|
||||
for (Parameter param : in.getParameters())
|
||||
parametersTypeHashCode += param.getType().hashCode();
|
||||
return Objects.hashCode(in.getEnclosingType(), in.getName(), parametersTypeHashCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* seeds well-known invokables.
|
||||
*/
|
||||
|
@ -150,11 +100,11 @@ public class RestModule extends AbstractModule {
|
|||
if (!objectMethods.contains(invoked)) {
|
||||
try {
|
||||
Method delegatedMethod = async.getRawType().getMethod(invoked.getName(), invoked.getParameterTypes());
|
||||
checkArgument(Arrays.equals(delegatedMethod.getExceptionTypes(), invoked.getExceptionTypes()), "invoked %s has different typed exceptions than delegated invoked %s", invoked,
|
||||
delegatedMethod);
|
||||
checkArgument(Arrays.equals(delegatedMethod.getExceptionTypes(), invoked.getExceptionTypes()),
|
||||
"invoked %s has different typed exceptions than delegated invoked %s", invoked, delegatedMethod);
|
||||
invoked.setAccessible(true);
|
||||
delegatedMethod.setAccessible(true);
|
||||
cache.put(Invokable.from(sync, invoked), Invokable.from(async, delegatedMethod));
|
||||
cache.put(Invokable.from(invoked), Invokable.from(delegatedMethod));
|
||||
} catch (SecurityException e) {
|
||||
throw propagate(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
@ -174,13 +124,11 @@ public class RestModule extends AbstractModule {
|
|||
}).toInstance(sync2Async);
|
||||
install(new SaxParserModule());
|
||||
install(new GsonModule());
|
||||
install(new SetCaller.Module());
|
||||
install(new FactoryModuleBuilder().build(BindToJsonPayloadWrappedWith.Factory.class));
|
||||
install(new FactoryModuleBuilder().build(InvokeAsyncApi.Delegate.Factory.class));
|
||||
install(new FactoryModuleBuilder().build(InvokeFutureAndBlock.Factory.class));
|
||||
install(new FactoryModuleBuilder().build(InvokeListenableFutureViaHttp.Caller.Factory.class));
|
||||
install(new FactoryModuleBuilder().build(BlockOnFuture.Factory.class));
|
||||
bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE);
|
||||
install(new FactoryModuleBuilder().build(InvokeSyncApi.Factory.class));
|
||||
bindClientAndAsyncClient(binder(), HttpClient.class, HttpAsyncClient.class);
|
||||
bindHttpApi(binder(), HttpClient.class, HttpAsyncClient.class);
|
||||
// this will help short circuit scenarios that can otherwise lock out users
|
||||
bind(new TypeLiteral<AtomicReference<AuthorizationException>>() {
|
||||
}).toInstance(authException);
|
||||
|
@ -188,10 +136,6 @@ public class RestModule extends AbstractModule {
|
|||
}).to(FilterStringsBoundToInjectorByName.class);
|
||||
bind(new TypeLiteral<Function<Predicate<String>, Map<String, String>>>() {
|
||||
}).to(FilterStringsBoundToInjectorByName.class);
|
||||
bind(new TypeLiteral<Function<Invocation, ListenableFuture<?>>>() {
|
||||
}).to(InvokeListenableFutureViaHttp.class);
|
||||
bind(new TypeLiteral<Function<GeneratedHttpRequest, Function<HttpResponse, ?>>>() {
|
||||
}).to(TransformerForRequest.class);
|
||||
installLocations();
|
||||
}
|
||||
|
||||
|
@ -199,7 +143,8 @@ public class RestModule extends AbstractModule {
|
|||
@Singleton
|
||||
@Named("TIMEOUTS")
|
||||
protected Map<String, Long> timeouts(Function<Predicate<String>, Map<String, String>> filterStringsBoundByName) {
|
||||
Map<String, String> stringBoundWithTimeoutPrefix = filterStringsBoundByName.apply(startsWith(PROPERTY_TIMEOUTS_PREFIX));
|
||||
Map<String, String> stringBoundWithTimeoutPrefix = filterStringsBoundByName
|
||||
.apply(startsWith(PROPERTY_TIMEOUTS_PREFIX));
|
||||
Map<String, Long> longsByName = transformValues(stringBoundWithTimeoutPrefix, new Function<String, Long>() {
|
||||
public Long apply(String input) {
|
||||
return Long.valueOf(String.valueOf(input));
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.rest.config;
|
||||
|
||||
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;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
/**
|
||||
* Allows the provider to supply a value set in a threadlocal.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class SetCaller {
|
||||
|
||||
private final ThreadLocal<TypeToken<?>> callerEnclosingType = new ThreadLocal<TypeToken<?>>();
|
||||
private final ThreadLocal<Invocation> caller = new ThreadLocal<Invocation>();
|
||||
|
||||
public void enter(TypeToken<?> callerEnclosingType, Invocation caller) {
|
||||
checkState(this.callerEnclosingType.get() == null, "A scoping block is already in progress");
|
||||
this.callerEnclosingType.set(callerEnclosingType);
|
||||
this.caller.set(caller);
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
checkState(caller.get() != null, "No scoping block in progress");
|
||||
callerEnclosingType.remove();
|
||||
caller.remove();
|
||||
}
|
||||
|
||||
public static class Module extends AbstractModule {
|
||||
public void configure() {
|
||||
SetCaller delegateScope = new SetCaller();
|
||||
bind(CALLER_ENCLOSING_TYPE).toProvider(delegateScope.new CallerEnclosingTypeProvider());
|
||||
bind(CALLER_INVOCATION).toProvider(delegateScope.new CallerInvocationProvider());
|
||||
bind(SetCaller.class).toInstance(delegateScope);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Key<TypeToken<?>> CALLER_ENCLOSING_TYPE = Key.get(new TypeLiteral<TypeToken<?>>() {
|
||||
}, Names.named("caller"));
|
||||
|
||||
private static final Key<Invocation> CALLER_INVOCATION = Key.get(new TypeLiteral<Invocation>() {
|
||||
}, Names.named("caller"));
|
||||
|
||||
class CallerEnclosingTypeProvider implements Provider<TypeToken<?>> {
|
||||
@Override
|
||||
public TypeToken<?> get() {
|
||||
return callerEnclosingType.get();
|
||||
}
|
||||
}
|
||||
|
||||
class CallerInvocationProvider implements Provider<Invocation> {
|
||||
@Override
|
||||
public Invocation get() {
|
||||
return caller.get();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
package org.jclouds.rest.internal;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.inject.util.Types.newParameterizedType;
|
||||
import static org.jclouds.util.Optionals2.isReturnTypeOptional;
|
||||
import static org.jclouds.util.Optionals2.unwrapIfOptional;
|
||||
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
import org.jclouds.reflect.FunctionalReflection;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Invocation.Result;
|
||||
import org.jclouds.reflect.InvocationSuccess;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Binding;
|
||||
import com.google.inject.ConfigurationException;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.ProvisionException;
|
||||
|
||||
@Beta
|
||||
abstract class BaseInvocationFunction implements Function<Invocation, Result> {
|
||||
protected final Injector injector;
|
||||
protected final Function<InvocationSuccess, Optional<Object>> optionalConverter;
|
||||
|
||||
protected BaseInvocationFunction(Injector injector, Function<InvocationSuccess, Optional<Object>> optionalConverter) {
|
||||
this.injector = injector;
|
||||
this.optionalConverter = optionalConverter;
|
||||
}
|
||||
|
||||
protected abstract Result invoke(Invocation in);
|
||||
|
||||
protected abstract Function<Invocation, Result> forwardInvocations(Invocation invocation, Class<?> returnType);
|
||||
|
||||
@Override
|
||||
public Result apply(Invocation invocation) {
|
||||
if (invocation.getInvokable().isAnnotationPresent(Provides.class))
|
||||
return Result.success(lookupValueFromGuice(invocation.getInvokable()));
|
||||
else if (invocation.getInvokable().isAnnotationPresent(Delegate.class))
|
||||
return Result.success(propagateContextToDelegate(invocation));
|
||||
return invoke(invocation);
|
||||
}
|
||||
|
||||
private Object propagateContextToDelegate(Invocation invocation) {
|
||||
Class<?> returnType = unwrapIfOptional(invocation.getInvokable().getReturnType());
|
||||
Object result = FunctionalReflection.newProxy(returnType, forwardInvocations(invocation, returnType));
|
||||
if (isReturnTypeOptional(invocation.getInvokable())) {
|
||||
result = optionalConverter.apply(InvocationSuccess.create(invocation, result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static final Predicate<Annotation> isQualifierPresent = new Predicate<Annotation>() {
|
||||
public boolean apply(Annotation input) {
|
||||
return input.annotationType().isAnnotationPresent(Qualifier.class);
|
||||
}
|
||||
};
|
||||
|
||||
private Object lookupValueFromGuice(Invokable<?, ?> invoked) {
|
||||
try {
|
||||
Type genericReturnType = invoked.getReturnType().getType();
|
||||
try {
|
||||
Annotation qualifier = find(ImmutableList.copyOf(invoked.getAnnotations()), isQualifierPresent);
|
||||
return getInstanceOfTypeWithQualifier(genericReturnType, qualifier);
|
||||
} catch (ProvisionException e) {
|
||||
throw propagate(e.getCause());
|
||||
} catch (RuntimeException e) {
|
||||
return instanceOfTypeOrPropagate(genericReturnType, e);
|
||||
}
|
||||
} catch (ProvisionException e) {
|
||||
AuthorizationException aex = getFirstThrowableOfType(e, AuthorizationException.class);
|
||||
if (aex != null)
|
||||
throw aex;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Object instanceOfTypeOrPropagate(Type genericReturnType, RuntimeException e) {
|
||||
try {
|
||||
// look for an existing binding
|
||||
Binding<?> binding = injector.getExistingBinding(Key.get(genericReturnType));
|
||||
if (binding != null)
|
||||
return binding.getProvider().get();
|
||||
|
||||
// then, try looking via supplier
|
||||
binding = injector.getExistingBinding(Key.get(newParameterizedType(Supplier.class, genericReturnType)));
|
||||
if (binding != null)
|
||||
return Supplier.class.cast(binding.getProvider().get()).get();
|
||||
|
||||
// else try to create an instance
|
||||
return injector.getInstance(Key.get(genericReturnType));
|
||||
} catch (ConfigurationException ce) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Object getInstanceOfTypeWithQualifier(Type genericReturnType, Annotation qualifier) {
|
||||
// look for an existing binding
|
||||
Binding<?> binding = injector.getExistingBinding(Key.get(genericReturnType, qualifier));
|
||||
if (binding != null)
|
||||
return binding.getProvider().get();
|
||||
|
||||
// then, try looking via supplier
|
||||
binding = injector
|
||||
.getExistingBinding(Key.get(newParameterizedType(Supplier.class, genericReturnType), qualifier));
|
||||
if (binding != null)
|
||||
return Supplier.class.cast(binding.getProvider().get()).get();
|
||||
|
||||
// else try to create an instance
|
||||
return injector.getInstance(Key.get(genericReturnType, qualifier));
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ package org.jclouds.rest.internal;
|
|||
|
||||
import static com.google.common.base.Optional.fromNullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -33,57 +32,45 @@ import javax.inject.Named;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.reflect.Invocation.Result;
|
||||
import org.jclouds.reflect.Invokable;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class InvokeFutureAndBlock implements Function<Invocation, Result> {
|
||||
public class BlockOnFuture implements Function<ListenableFuture<?>, Result> {
|
||||
|
||||
public static interface Factory {
|
||||
/**
|
||||
* @param receiver
|
||||
* object whose interface matched {@code declaring} except all invokeds return {@link ListenableFuture}
|
||||
* @return blocking invocation handler
|
||||
* @param invocation
|
||||
* context for how the future was created
|
||||
*/
|
||||
InvokeFutureAndBlock create(Object async);
|
||||
BlockOnFuture create(TypeToken<?> enclosingType, Invocation invocation);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private Logger logger = Logger.NULL;
|
||||
|
||||
private final Cache<Invokable<?, ?>, Invokable<?, ?>> sync2AsyncInvokables;
|
||||
private final Map<String, Long> timeouts;
|
||||
private final Object receiver;
|
||||
private final TypeToken<?> enclosingType;
|
||||
private final Invocation invocation;
|
||||
|
||||
@Inject
|
||||
@VisibleForTesting
|
||||
InvokeFutureAndBlock(Cache<Invokable<?, ?>, Invokable<?, ?>> sync2AsyncInvokables,
|
||||
@Named("TIMEOUTS") Map<String, Long> timeouts, @Assisted Object receiver) {
|
||||
this.receiver = receiver;
|
||||
this.sync2AsyncInvokables = sync2AsyncInvokables;
|
||||
BlockOnFuture(@Named("TIMEOUTS") Map<String, Long> timeouts, @Assisted TypeToken<?> enclosingType,
|
||||
@Assisted Invocation invocation) {
|
||||
this.timeouts = timeouts;
|
||||
this.enclosingType = enclosingType;
|
||||
this.invocation = invocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result apply(Invocation invocation) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Invokable<? super Object, ListenableFuture<?>> asyncMethod = Invokable.class.cast(sync2AsyncInvokables
|
||||
.getIfPresent(invocation.getInvokable()));
|
||||
try {
|
||||
ListenableFuture<?> future = asyncMethod.invoke(receiver, invocation.getArgs().toArray());
|
||||
Optional<Long> timeoutNanos = timeoutInNanos(invocation.getInvokable(), timeouts);
|
||||
return block(future, timeoutNanos);
|
||||
} catch (InvocationTargetException e) {
|
||||
return Result.fail(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
return Result.fail(e);
|
||||
}
|
||||
|
||||
public Result apply(ListenableFuture<?> future) {
|
||||
Optional<Long> timeoutNanos = timeoutInNanos(invocation.getInvokable(), timeouts);
|
||||
return block(future, timeoutNanos);
|
||||
}
|
||||
|
||||
private Result block(ListenableFuture<?> future, Optional<Long> timeoutNanos) {
|
||||
|
@ -106,7 +93,7 @@ public class InvokeFutureAndBlock implements Function<Invocation, Result> {
|
|||
|
||||
// override timeout by values configured in properties(in ms)
|
||||
private Optional<Long> timeoutInNanos(Invokable<?, ?> invoked, Map<String, Long> timeouts) {
|
||||
String className = invoked.getEnclosingType().getRawType().getSimpleName();
|
||||
String className = enclosingType.getRawType().getSimpleName();
|
||||
Optional<Long> timeoutMillis = fromNullable(timeouts.get(className + "." + invoked.getName())).or(
|
||||
fromNullable(timeouts.get(className))).or(fromNullable(timeouts.get("default")));
|
||||
if (timeoutMillis.isPresent())
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue