mirror of https://github.com/apache/jclouds.git
Issue 292: added simple http client
This commit is contained in:
parent
5afc44b2b7
commit
055c56dc08
|
@ -29,6 +29,8 @@ import org.jclouds.atmosonline.saas.AtmosStorageClient;
|
||||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -48,12 +50,13 @@ public class AtmosStorageContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<AtmosStorageClient, AtmosStorageAsyncClient> provideContext(Closer closer,
|
RestContext<AtmosStorageClient, AtmosStorageAsyncClient> provideContext(
|
||||||
AtmosStorageAsyncClient async, AtmosStorageClient defaultApi,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@AtmosStorage URI endPoint,
|
AtmosStorageAsyncClient async, AtmosStorageClient defaultApi,
|
||||||
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
|
@AtmosStorage URI endPoint,
|
||||||
return new RestContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>(closer, async,
|
@Named(AtmosStorageConstants.PROPERTY_EMCSAAS_UID) String account) {
|
||||||
defaultApi, endPoint, account);
|
return new RestContextImpl<AtmosStorageClient, AtmosStorageAsyncClient>(
|
||||||
|
closer, http, asyncHttp, defaultApi, async, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ import org.jclouds.aws.reference.AWSConstants;
|
||||||
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -50,10 +52,11 @@ public class EC2ContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<EC2Client, EC2AsyncClient> provideContext(Closer closer,
|
RestContext<EC2Client, EC2AsyncClient> provideContext(Closer closer,
|
||||||
EC2AsyncClient defaultApi, EC2Client synchApi, @EC2 URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp, EC2AsyncClient defaultApi,
|
||||||
|
EC2Client synchApi, @EC2 URI endPoint,
|
||||||
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
||||||
return new RestContextImpl<EC2Client, EC2AsyncClient>(closer, defaultApi,
|
return new RestContextImpl<EC2Client, EC2AsyncClient>(closer, http,
|
||||||
synchApi, endPoint, account);
|
asyncHttp, synchApi, defaultApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -28,6 +28,8 @@ import org.jclouds.aws.s3.S3;
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
import org.jclouds.aws.s3.S3AsyncClient;
|
||||||
import org.jclouds.aws.s3.S3Client;
|
import org.jclouds.aws.s3.S3Client;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -47,11 +49,12 @@ public class S3ContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<S3Client, S3AsyncClient> provideContext(Closer closer, S3AsyncClient defaultApi,
|
RestContext<S3Client, S3AsyncClient> provideContext(Closer closer,
|
||||||
S3Client syncApi, @S3 URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp, S3AsyncClient defaultApi,
|
||||||
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
S3Client syncApi, @S3 URI endPoint,
|
||||||
return new RestContextImpl<S3Client, S3AsyncClient>(closer, defaultApi, syncApi, endPoint,
|
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
||||||
account);
|
return new RestContextImpl<S3Client, S3AsyncClient>(closer, http,
|
||||||
|
asyncHttp, syncApi, defaultApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ import org.jclouds.aws.sqs.SQSClient;
|
||||||
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -52,11 +54,12 @@ public class SQSContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<SQSClient, SQSAsyncClient> provideContext(Closer closer, SQSAsyncClient defaultApi,
|
RestContext<SQSClient, SQSAsyncClient> provideContext(Closer closer,
|
||||||
SQSClient synchApi, @SQS URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp, SQSAsyncClient defaultApi,
|
||||||
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
SQSClient synchApi, @SQS URI endPoint,
|
||||||
return new RestContextImpl<SQSClient, SQSAsyncClient>(closer, defaultApi, synchApi, endPoint,
|
@Named(AWSConstants.PROPERTY_AWS_ACCESSKEYID) String account) {
|
||||||
account);
|
return new RestContextImpl<SQSClient, SQSAsyncClient>(closer, http,
|
||||||
|
asyncHttp, synchApi, defaultApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -39,7 +39,8 @@ import com.google.inject.TypeLiteral;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
public class S3StubClientModule extends RestClientModule<S3Client, S3AsyncClient> {
|
public class S3StubClientModule extends
|
||||||
|
RestClientModule<S3Client, S3AsyncClient> {
|
||||||
|
|
||||||
public S3StubClientModule() {
|
public S3StubClientModule() {
|
||||||
super(S3Client.class, S3AsyncClient.class);
|
super(S3Client.class, S3AsyncClient.class);
|
||||||
|
@ -50,7 +51,8 @@ public class S3StubClientModule extends RestClientModule<S3Client, S3AsyncClient
|
||||||
install(new S3ObjectModule());
|
install(new S3ObjectModule());
|
||||||
install(new ParserModule());
|
install(new ParserModule());
|
||||||
install(new TransientBlobStoreModule());
|
install(new TransientBlobStoreModule());
|
||||||
bind(URI.class).annotatedWith(S3.class).toInstance(URI.create("https://localhost/s3stub"));
|
bind(URI.class).annotatedWith(S3.class).toInstance(
|
||||||
|
URI.create("https://localhost/s3stub"));
|
||||||
bind(String.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD);
|
bind(String.class).annotatedWith(S3.class).toInstance(Region.US_STANDARD);
|
||||||
bind(new TypeLiteral<Set<String>>() {
|
bind(new TypeLiteral<Set<String>>() {
|
||||||
}).annotatedWith(S3.class).toInstance(Region.ALL_S3);
|
}).annotatedWith(S3.class).toInstance(Region.ALL_S3);
|
||||||
|
@ -60,5 +62,4 @@ public class S3StubClientModule extends RestClientModule<S3Client, S3AsyncClient
|
||||||
protected void bindAsyncClient() {
|
protected void bindAsyncClient() {
|
||||||
bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
|
bind(S3AsyncClient.class).to(StubS3AsyncClient.class).asEagerSingleton();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.jclouds.azure.storage.blob.AzureBlobClient;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -48,11 +50,16 @@ public class AzureBlobContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<AzureBlobClient, AzureBlobAsyncClient> provideContext(Closer closer,
|
RestContext<AzureBlobClient, AzureBlobAsyncClient> provideContext(
|
||||||
AzureBlobAsyncClient asyncApi, AzureBlobClient defaultApi, @AzureBlob URI endPoint,
|
Closer closer,
|
||||||
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
|
HttpClient http,
|
||||||
return new RestContextImpl<AzureBlobClient, AzureBlobAsyncClient>(closer, asyncApi,
|
HttpAsyncClient asyncHttp,
|
||||||
defaultApi, endPoint, account);
|
AzureBlobAsyncClient asyncApi,
|
||||||
|
AzureBlobClient defaultApi,
|
||||||
|
@AzureBlob URI endPoint,
|
||||||
|
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
|
||||||
|
return new RestContextImpl<AzureBlobClient, AzureBlobAsyncClient>(closer,
|
||||||
|
http, asyncHttp, defaultApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -29,6 +29,8 @@ import org.jclouds.azure.storage.queue.AzureQueueClient;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -47,11 +49,16 @@ public class AzureQueueContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<AzureQueueClient, AzureQueueAsyncClient> provideContext(Closer closer,
|
RestContext<AzureQueueClient, AzureQueueAsyncClient> provideContext(
|
||||||
AzureQueueAsyncClient asynchApi, AzureQueueClient defaultApi, @AzureQueue URI endPoint,
|
Closer closer,
|
||||||
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
|
HttpClient http,
|
||||||
return new RestContextImpl<AzureQueueClient, AzureQueueAsyncClient>(closer, asynchApi,
|
HttpAsyncClient asyncHttp,
|
||||||
defaultApi, endPoint, account);
|
AzureQueueAsyncClient asynchApi,
|
||||||
|
AzureQueueClient defaultApi,
|
||||||
|
@AzureQueue URI endPoint,
|
||||||
|
@Named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT) String account) {
|
||||||
|
return new RestContextImpl<AzureQueueClient, AzureQueueAsyncClient>(
|
||||||
|
closer, http, asyncHttp, defaultApi, asynchApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -14,6 +14,8 @@ import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.jclouds.domain.internal.LocationImpl;
|
import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
@ -23,12 +25,13 @@ import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link TransientBlobStoreContext}; requires {@link TransientAsyncBlobStore} bound.
|
* Configures the {@link TransientBlobStoreContext}; requires
|
||||||
|
* {@link TransientAsyncBlobStore} bound.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class TransientBlobStoreContextModule extends
|
public class TransientBlobStoreContextModule extends
|
||||||
RestClientModule<TransientBlobStore, AsyncBlobStore> {
|
RestClientModule<TransientBlobStore, AsyncBlobStore> {
|
||||||
|
|
||||||
public TransientBlobStoreContextModule() {
|
public TransientBlobStoreContextModule() {
|
||||||
super(TransientBlobStore.class, AsyncBlobStore.class);
|
super(TransientBlobStore.class, AsyncBlobStore.class);
|
||||||
|
@ -40,9 +43,10 @@ public class TransientBlobStoreContextModule extends
|
||||||
install(new BlobStoreObjectModule());
|
install(new BlobStoreObjectModule());
|
||||||
install(new BlobStoreMapModule());
|
install(new BlobStoreMapModule());
|
||||||
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
bind(ConsistencyModel.class).toInstance(ConsistencyModel.STRICT);
|
||||||
bind(BlobStoreContext.class).to(
|
bind(BlobStoreContext.class)
|
||||||
new TypeLiteral<BlobStoreContextImpl<TransientBlobStore, AsyncBlobStore>>() {
|
.to(
|
||||||
}).in(Scopes.SINGLETON);
|
new TypeLiteral<BlobStoreContextImpl<TransientBlobStore, AsyncBlobStore>>() {
|
||||||
|
}).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -54,20 +58,25 @@ public class TransientBlobStoreContextModule extends
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Location provideDefaultLocation() {
|
Location provideDefaultLocation() {
|
||||||
return new LocationImpl(LocationScope.PROVIDER, "transient", "transient", null);
|
return new LocationImpl(LocationScope.PROVIDER, "transient", "transient",
|
||||||
}
|
null);
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
RestContext<TransientBlobStore, AsyncBlobStore> provideContext(Closer closer,
|
|
||||||
final AsyncBlobStore async, TransientBlobStore sync) {
|
|
||||||
return new RestContextImpl<TransientBlobStore, AsyncBlobStore>(closer, async, sync, URI
|
|
||||||
.create("http://localhost/transient"), System.getProperty("user.name"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void bindAsyncClient() {
|
protected void bindAsyncClient() {
|
||||||
bind(AsyncBlobStore.class).to(TransientAsyncBlobStore.class).asEagerSingleton();
|
bind(AsyncBlobStore.class).to(TransientAsyncBlobStore.class)
|
||||||
|
.asEagerSingleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
RestContext<TransientBlobStore, AsyncBlobStore> provideContext(
|
||||||
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
|
TransientBlobStore sync, AsyncBlobStore async) {
|
||||||
|
return new RestContextImpl<TransientBlobStore, AsyncBlobStore>(closer,
|
||||||
|
http, asyncHttp, sync, async, URI
|
||||||
|
.create("http://localhost/transient"), System
|
||||||
|
.getProperty("user.name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,16 @@ import org.jclouds.blobstore.TransientAsyncBlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.internal.ClassMethodArgs;
|
import org.jclouds.internal.ClassMethodArgs;
|
||||||
import com.google.inject.name.Names;
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
|
import org.jclouds.rest.config.BinderUtils;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
public class TransientBlobStoreModule extends AbstractModule {
|
public class TransientBlobStoreModule extends AbstractModule {
|
||||||
|
|
||||||
|
@ -45,17 +48,20 @@ public class TransientBlobStoreModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(new TypeLiteral<ConcurrentMap<String, ConcurrentMap<String, Blob>>>() {
|
bind(
|
||||||
}).toInstance(map);
|
new TypeLiteral<ConcurrentMap<String, ConcurrentMap<String, Blob>>>() {
|
||||||
|
}).toInstance(map);
|
||||||
bind(new TypeLiteral<ConcurrentMap<String, Location>>() {
|
bind(new TypeLiteral<ConcurrentMap<String, Location>>() {
|
||||||
}).toInstance(containerToLocation);
|
}).toInstance(containerToLocation);
|
||||||
// delegation on stubs is not currently supported
|
// delegation on stubs is not currently supported
|
||||||
bind(new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
|
bind(new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
|
||||||
}).annotatedWith(Names.named("async")).toInstance(
|
}).annotatedWith(Names.named("async")).toInstance(
|
||||||
new ConcurrentHashMap<ClassMethodArgs, Object>());
|
new ConcurrentHashMap<ClassMethodArgs, Object>());
|
||||||
bind(TransientAsyncBlobStore.class).in(Scopes.SINGLETON);
|
bind(TransientAsyncBlobStore.class).in(Scopes.SINGLETON);
|
||||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_USER_THREADS)).to(0);
|
bindConstant()
|
||||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_IO_WORKER_THREADS)).to(0);
|
.annotatedWith(Names.named(Constants.PROPERTY_USER_THREADS)).to(0);
|
||||||
|
bindConstant().annotatedWith(
|
||||||
|
Names.named(Constants.PROPERTY_IO_WORKER_THREADS)).to(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -63,4 +69,17 @@ public class TransientBlobStoreModule extends AbstractModule {
|
||||||
Set<Location> provideLocations(Location defaultLocation) {
|
Set<Location> provideLocations(Location defaultLocation) {
|
||||||
return ImmutableSet.of(defaultLocation);
|
return ImmutableSet.of(defaultLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
HttpClient provideClient() {
|
||||||
|
return BinderUtils.newNullProxy(HttpClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
HttpAsyncClient provideAsyncClient() {
|
||||||
|
return BinderUtils.newNullProxy(HttpAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -46,13 +46,15 @@ import java.net.URI;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.boxdotnet.BoxDotNet;
|
import org.jclouds.boxdotnet.BoxDotNet;
|
||||||
import org.jclouds.boxdotnet.BoxDotNetAsyncClient;
|
import org.jclouds.boxdotnet.BoxDotNetAsyncClient;
|
||||||
import org.jclouds.boxdotnet.BoxDotNetClient;
|
import org.jclouds.boxdotnet.BoxDotNetClient;
|
||||||
import org.jclouds.boxdotnet.reference.BoxDotNetConstants;
|
import org.jclouds.boxdotnet.reference.BoxDotNetConstants;
|
||||||
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -76,9 +78,13 @@ public class BoxDotNetContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<BoxDotNetClient, BoxDotNetAsyncClient> provideContext(Closer closer, BoxDotNetAsyncClient asyncApi,
|
RestContext<BoxDotNetClient, BoxDotNetAsyncClient> provideContext(
|
||||||
BoxDotNetClient syncApi, @BoxDotNet URI endPoint, @Named(BoxDotNetConstants.PROPERTY_BOXDOTNET_USER) String account) {
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
return new RestContextImpl<BoxDotNetClient, BoxDotNetAsyncClient>(closer, asyncApi, syncApi, endPoint, account);
|
BoxDotNetAsyncClient asyncApi, BoxDotNetClient syncApi,
|
||||||
|
@BoxDotNet URI endPoint,
|
||||||
|
@Named(BoxDotNetConstants.PROPERTY_BOXDOTNET_USER) String account) {
|
||||||
|
return new RestContextImpl<BoxDotNetClient, BoxDotNetAsyncClient>(closer,
|
||||||
|
http, asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -37,14 +37,18 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.chef.binders.BindChecksumsToJsonPayload;
|
||||||
import org.jclouds.chef.binders.BindClientnameToJsonPayload;
|
import org.jclouds.chef.binders.BindClientnameToJsonPayload;
|
||||||
import org.jclouds.chef.binders.BindGenerateKeyForClientToJsonPayload;
|
import org.jclouds.chef.binders.BindGenerateKeyForClientToJsonPayload;
|
||||||
|
import org.jclouds.chef.domain.Sandbox;
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||||
import org.jclouds.chef.functions.ParseKeyFromJson;
|
import org.jclouds.chef.functions.ParseKeyFromJson;
|
||||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||||
|
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
import org.jclouds.rest.annotations.Endpoint;
|
import org.jclouds.rest.annotations.Endpoint;
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
|
import org.jclouds.rest.annotations.Headers;
|
||||||
import org.jclouds.rest.annotations.PartParam;
|
import org.jclouds.rest.annotations.PartParam;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
@ -65,7 +69,18 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@Endpoint(Chef.class)
|
@Endpoint(Chef.class)
|
||||||
@RequestFilters(SignedHeaderAuth.class)
|
@RequestFilters(SignedHeaderAuth.class)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Headers(keys = "X-Chef-Version", values = "0.9.0")
|
||||||
public interface ChefAsyncClient {
|
public interface ChefAsyncClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ChefClient#getUploadUrisForContent
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("sandboxes")
|
||||||
|
@ResponseParser(ParseSandboxFromJson.class)
|
||||||
|
ListenableFuture<Sandbox> getUploadUrisForContent(
|
||||||
|
@BinderParam(BindChecksumsToJsonPayload.class) Set<String> checksums);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ChefCookbooks#listCookbooks
|
* @see ChefCookbooks#listCookbooks
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -45,6 +45,7 @@ import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.chef.domain.Sandbox;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
|
@ -60,6 +61,7 @@ import org.jclouds.rest.ResourceNotFoundException;
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface ChefClient {
|
public interface ChefClient {
|
||||||
|
Sandbox getUploadUrisForContent(Set<String> checksums);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -46,13 +46,15 @@ import java.net.URI;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
|
||||||
import org.jclouds.chef.Chef;
|
import org.jclouds.chef.Chef;
|
||||||
import org.jclouds.chef.ChefAsyncClient;
|
import org.jclouds.chef.ChefAsyncClient;
|
||||||
import org.jclouds.chef.ChefClient;
|
import org.jclouds.chef.ChefClient;
|
||||||
import org.jclouds.chef.reference.ChefConstants;
|
import org.jclouds.chef.reference.ChefConstants;
|
||||||
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -76,9 +78,12 @@ public class ChefContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<ChefClient, ChefAsyncClient> provideContext(Closer closer, ChefAsyncClient asyncApi,
|
RestContext<ChefClient, ChefAsyncClient> provideContext(Closer closer,
|
||||||
ChefClient syncApi, @Chef URI endPoint, @Named(ChefConstants.PROPERTY_CHEF_IDENTITY) String account) {
|
HttpClient http, HttpAsyncClient asyncHttp, ChefAsyncClient asyncApi,
|
||||||
return new RestContextImpl<ChefClient, ChefAsyncClient>(closer, asyncApi, syncApi, endPoint, account);
|
ChefClient syncApi, @Chef URI endPoint,
|
||||||
|
@Named(ChefConstants.PROPERTY_CHEF_IDENTITY) String account) {
|
||||||
|
return new RestContextImpl<ChefClient, ChefAsyncClient>(closer, http,
|
||||||
|
asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -99,15 +99,26 @@ public class User implements Comparable<User> {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((displayName == null) ? 0 : displayName.hashCode());
|
result = prime * result
|
||||||
|
+ ((displayName == null) ? 0 : displayName.hashCode());
|
||||||
result = prime * result + ((email == null) ? 0 : email.hashCode());
|
result = prime * result + ((email == null) ? 0 : email.hashCode());
|
||||||
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
|
result = prime * result
|
||||||
|
+ ((firstName == null) ? 0 : firstName.hashCode());
|
||||||
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
|
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
|
||||||
result = prime * result + ((middleName == null) ? 0 : middleName.hashCode());
|
result = prime * result
|
||||||
|
+ ((middleName == null) ? 0 : middleName.hashCode());
|
||||||
result = prime * result + ((password == null) ? 0 : password.hashCode());
|
result = prime * result + ((password == null) ? 0 : password.hashCode());
|
||||||
result = prime * result + ((username == null) ? 0 : username.hashCode());
|
result = prime * result + ((username == null) ? 0 : username.hashCode());
|
||||||
return result;
|
return result;
|
||||||
|
@ -162,16 +173,10 @@ public class User implements Comparable<User> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "User [username=" + username + ", displayName=" + displayName + ", firstName="
|
return "User [displayName=" + displayName + ", email=" + email
|
||||||
+ firstName + ", middleName=" + middleName + ", lastName=" + lastName + ", email="
|
+ ", firstName=" + firstName + ", lastName=" + lastName
|
||||||
+ email + "]";
|
+ ", middleName=" + middleName + ", password=" + password
|
||||||
|
+ ", username=" + username + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,14 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.chef.config.ChefRestClientModule;
|
import org.jclouds.chef.config.ChefRestClientModule;
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuth;
|
import org.jclouds.chef.filters.SignedHeaderAuth;
|
||||||
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
import org.jclouds.chef.filters.SignedHeaderAuthTest;
|
||||||
import org.jclouds.chef.functions.ParseKeyFromJson;
|
import org.jclouds.chef.functions.ParseKeyFromJson;
|
||||||
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
import org.jclouds.chef.functions.ParseKeySetFromJson;
|
||||||
|
import org.jclouds.chef.functions.ParseSandboxFromJson;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||||
import org.jclouds.http.functions.ReturnStringIf200;
|
import org.jclouds.http.functions.ReturnStringIf200;
|
||||||
|
@ -48,6 +50,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
@ -61,6 +64,34 @@ import com.google.inject.name.Names;
|
||||||
@Test(groups = "unit", testName = "chef.ChefAsyncClientTest")
|
@Test(groups = "unit", testName = "chef.ChefAsyncClientTest")
|
||||||
public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
|
|
||||||
|
public void testGetUploadUrisForContent() throws SecurityException,
|
||||||
|
NoSuchMethodException, IOException {
|
||||||
|
Method method = ChefAsyncClient.class.getMethod(
|
||||||
|
"getUploadUrisForContent", Set.class);
|
||||||
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor
|
||||||
|
.createRequest(method, ImmutableSet.of(
|
||||||
|
"0189e76ccc476701d6b374e5a1a27347",
|
||||||
|
"0c5ecd7788cf4f6c7de2a57193897a6c",
|
||||||
|
"1dda05ed139664f1f89b9dec482b77c0"));
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest,
|
||||||
|
"POST http://localhost:4000/sandboxes HTTP/1.1");
|
||||||
|
assertHeadersEqual(
|
||||||
|
httpRequest,
|
||||||
|
"Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
|
assertPayloadEquals(
|
||||||
|
httpRequest,
|
||||||
|
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}");
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
ParseSandboxFromJson.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void testGetCookbook() throws SecurityException,
|
public void testGetCookbook() throws SecurityException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
Method method = ChefAsyncClient.class.getMethod("getCookbook",
|
Method method = ChefAsyncClient.class.getMethod("getCookbook",
|
||||||
|
@ -69,7 +100,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
.createRequest(method, "cookbook");
|
.createRequest(method, "cookbook");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET http://localhost:4000/cookbooks/cookbook HTTP/1.1");
|
"GET http://localhost:4000/cookbooks/cookbook HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -89,7 +121,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
.createRequest(method, "cookbook");
|
.createRequest(method, "cookbook");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"DELETE http://localhost:4000/cookbooks/cookbook HTTP/1.1");
|
"DELETE http://localhost:4000/cookbooks/cookbook HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -128,7 +161,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: "
|
"Accept: application/json\nContent-Length: "
|
||||||
+ (file.getName().length() + 206)
|
+ (file.getName().length() + 206)
|
||||||
+ "\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
|
+ "\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, COOOKBOOK_BODY.replace(
|
assertPayloadEquals(httpRequest, COOOKBOOK_BODY.replace(
|
||||||
"cookbook.tar.gz", file.getName()));
|
"cookbook.tar.gz", file.getName()));
|
||||||
|
|
||||||
|
@ -152,7 +185,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"POST http://localhost:4000/cookbooks HTTP/1.1");
|
"POST http://localhost:4000/cookbooks HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 221\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
|
"Accept: application/json\nContent-Length: 221\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, COOOKBOOK_BODY);
|
assertPayloadEquals(httpRequest, COOOKBOOK_BODY);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -181,7 +214,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: "
|
"Accept: application/json\nContent-Length: "
|
||||||
+ (file.getName().length() + 206)
|
+ (file.getName().length() + 206)
|
||||||
+ "\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
|
+ "\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, COOOKBOOK_BODY.replace(
|
assertPayloadEquals(httpRequest, COOOKBOOK_BODY.replace(
|
||||||
"cookbook.tar.gz", file.getName()));
|
"cookbook.tar.gz", file.getName()));
|
||||||
|
|
||||||
|
@ -205,7 +238,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"PUT http://localhost:4000/cookbooks/cookbook/_content HTTP/1.1");
|
"PUT http://localhost:4000/cookbooks/cookbook/_content HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 221\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
|
"Accept: application/json\nContent-Length: 221\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, COOOKBOOK_BODY);
|
assertPayloadEquals(httpRequest, COOOKBOOK_BODY);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -225,7 +258,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET http://localhost:4000/cookbooks HTTP/1.1");
|
"GET http://localhost:4000/cookbooks HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -245,7 +279,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
.createRequest(method, "client");
|
.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"HEAD http://localhost:4000/clients/client HTTP/1.1");
|
"HEAD http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -265,7 +300,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
.createRequest(method, "client");
|
.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"DELETE http://localhost:4000/clients/client HTTP/1.1");
|
"DELETE http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -287,7 +323,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"PUT http://localhost:4000/clients/client HTTP/1.1");
|
"PUT http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\n");
|
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest,
|
assertPayloadEquals(httpRequest,
|
||||||
"{\"clientname\":\"client\", \"private_key\": true}");
|
"{\"clientname\":\"client\", \"private_key\": true}");
|
||||||
|
|
||||||
|
@ -311,7 +347,7 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"POST http://localhost:4000/clients HTTP/1.1");
|
"POST http://localhost:4000/clients HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\n");
|
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
|
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
@ -331,7 +367,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET http://localhost:4000/clients HTTP/1.1");
|
"GET http://localhost:4000/clients HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertHeadersEqual(httpRequest,
|
||||||
|
"Accept: application/json\nX-Chef-Version: 0.9.0\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest,
|
assertResponseParserClassEquals(method, httpRequest,
|
||||||
|
|
|
@ -66,8 +66,11 @@ import org.jclouds.domain.internal.LocationImpl;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.net.IPSocket;
|
import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.SocketOpen;
|
import org.jclouds.predicates.SocketOpen;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.config.BinderUtils;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -154,12 +157,26 @@ public class StubComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
HttpClient provideClient() {
|
||||||
|
return BinderUtils.newNullProxy(HttpClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
HttpAsyncClient provideAsyncClient() {
|
||||||
|
return BinderUtils.newNullProxy(HttpAsyncClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<ConcurrentMap, ConcurrentMap> provideRestContext(Closer closer) {
|
RestContext<ConcurrentMap, ConcurrentMap> provideRestContext(Closer closer,
|
||||||
return new RestContextImpl<ConcurrentMap, ConcurrentMap>(closer, nodes,
|
HttpClient http, HttpAsyncClient asyncHttp) {
|
||||||
nodes, URI.create("http://stub"), System.getProperty("user.name"));
|
return new RestContextImpl<ConcurrentMap, ConcurrentMap>(closer, http,
|
||||||
|
asyncHttp, nodes, nodes, URI.create("http://stub"), System
|
||||||
|
.getProperty("user.name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NORMAL STUFF
|
// NORMAL STUFF
|
||||||
|
|
|
@ -30,7 +30,7 @@ import com.google.common.io.InputSupplier;
|
||||||
public interface Payload extends InputSupplier<InputStream> {
|
public interface Payload extends InputSupplier<InputStream> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new InputStream object of the payload.
|
* Creates a new InputStream object of the payload.
|
||||||
*/
|
*/
|
||||||
InputStream getInput();
|
InputStream getInput();
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public interface Payload extends InputSupplier<InputStream> {
|
||||||
boolean isRepeatable();
|
boolean isRepeatable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the payload content to the output stream.
|
* Writes the payload content to the output stream.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package org.jclouds.rest;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.HEAD;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
|
||||||
|
import org.jclouds.http.Payload;
|
||||||
|
import org.jclouds.rest.annotations.EndpointParam;
|
||||||
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
|
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
|
||||||
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple rest client
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public interface HttpAsyncClient {
|
||||||
|
/**
|
||||||
|
* @see HttpClient#post
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
ListenableFuture<Void> put(@EndpointParam URI location, Payload payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HttpClient#post
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
ListenableFuture<Void> post(@EndpointParam URI location, Payload payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HttpClient#exists
|
||||||
|
*/
|
||||||
|
@HEAD
|
||||||
|
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Boolean> exists(@EndpointParam URI location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HttpClient#get
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<InputStream> get(@EndpointParam URI location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HttpClient#delete
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Boolean> delete(@EndpointParam URI location);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.http.Payload;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple client
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
public interface HttpClient {
|
||||||
|
|
||||||
|
void put(URI location, Payload payload);
|
||||||
|
|
||||||
|
void post(URI location, Payload payload);
|
||||||
|
|
||||||
|
boolean exists(URI location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null if the resource didn't exist.
|
||||||
|
*/
|
||||||
|
InputStream get(URI location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return false if the resource didn't exist.
|
||||||
|
*/
|
||||||
|
boolean delete(URI location);
|
||||||
|
}
|
|
@ -28,8 +28,8 @@ import com.google.inject.ImplementedBy;
|
||||||
/**
|
/**
|
||||||
* Represents an authenticated context to the cloud.
|
* Represents an authenticated context to the cloud.
|
||||||
*
|
*
|
||||||
* <h2>Note</h2> Please issue {@link #close()} when you are finished with this context in order to
|
* <h2>Note</h2> Please issue {@link #close()} when you are finished with this
|
||||||
* release resources.
|
* context in order to release resources.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -39,20 +39,26 @@ import com.google.inject.ImplementedBy;
|
||||||
public interface RestContext<S, A> {
|
public interface RestContext<S, A> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* low-level api to the cloud. Threadsafe implementations will return a singleton.
|
* low-level api to the cloud. Threadsafe implementations will return a
|
||||||
|
* singleton.
|
||||||
*
|
*
|
||||||
* @return a connection to the cloud where all methods return {@link ListenableFuture}s
|
* @return a connection to the cloud where all methods return
|
||||||
|
* {@link ListenableFuture}s
|
||||||
*/
|
*/
|
||||||
A getAsyncApi();
|
A getAsyncApi();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reflects a tuned connection to the cloud which calls {@link #getAsyncApi()} with predetermined
|
* reflects a tuned connection to the cloud which calls
|
||||||
* timeouts.
|
* {@link #getAsyncApi()} with predetermined timeouts.
|
||||||
*
|
*
|
||||||
* @return a connection to the cloud where all methods block
|
* @return a connection to the cloud where all methods block
|
||||||
*/
|
*/
|
||||||
S getApi();
|
S getApi();
|
||||||
|
|
||||||
|
HttpAsyncClient asyncHttp();
|
||||||
|
|
||||||
|
HttpClient http();
|
||||||
|
|
||||||
URI getEndPoint();
|
URI getEndPoint();
|
||||||
|
|
||||||
String getAccount();
|
String getAccount();
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.rest.AsyncClientFactory;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class AsyncClientProvider<A> implements Provider<A> {
|
||||||
|
@Inject
|
||||||
|
Injector injector;
|
||||||
|
private final Class<A> asyncClientType;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AsyncClientProvider(Class<A> asyncClientType) {
|
||||||
|
this.asyncClientType = asyncClientType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Singleton
|
||||||
|
public A get() {
|
||||||
|
return (A) injector.getInstance(AsyncClientFactory.class).create(
|
||||||
|
asyncClientType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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 java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.inject.Binder;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class BinderUtils {
|
||||||
|
|
||||||
|
public static <K, V> void bindClient(Binder binder, Class<K> syncClientType,
|
||||||
|
Class<V> asyncClientType, Map<Class<?>, Class<?>> delegates) {
|
||||||
|
Provider<K> asyncProvider = new ClientProvider<K, V>(syncClientType,
|
||||||
|
asyncClientType, delegates);
|
||||||
|
binder.requestInjection(asyncProvider);
|
||||||
|
binder.bind(syncClientType).toProvider(asyncProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void bindAsyncClient(Binder binder,
|
||||||
|
Class<T> asyncClientType) {
|
||||||
|
Provider<T> asyncProvider = new AsyncClientProvider<T>(asyncClientType);
|
||||||
|
binder.requestInjection(asyncProvider);
|
||||||
|
binder.bind(asyncClientType).toProvider(asyncProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static <T> T newNullProxy(Class<T> clazz) {
|
||||||
|
return (T) Proxy.newProxyInstance(clazz.getClassLoader(),
|
||||||
|
new Class<?>[] { clazz }, new InvocationHandler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args)
|
||||||
|
throws Throwable {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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 java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.internal.SyncProxy;
|
||||||
|
import org.jclouds.internal.ClassMethodArgs;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.google.inject.Key;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class ClientProvider<S, A> implements Provider<S> {
|
||||||
|
@Inject
|
||||||
|
Injector injector;
|
||||||
|
private final Class<S> syncClientType;
|
||||||
|
private final Class<A> asyncClientType;
|
||||||
|
private final Map<Class<?>, Class<?>> sync2Async;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ClientProvider(Class<S> syncClientType, Class<A> asyncClientType,
|
||||||
|
Map<Class<?>, Class<?>> sync2Async) {
|
||||||
|
this.asyncClientType = asyncClientType;
|
||||||
|
this.syncClientType = syncClientType;
|
||||||
|
this.sync2Async = sync2Async;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Singleton
|
||||||
|
public S get() {
|
||||||
|
A client = (A) injector.getInstance(asyncClientType);
|
||||||
|
ConcurrentMap<ClassMethodArgs, Object> delegateMap = injector
|
||||||
|
.getInstance(Key.get(
|
||||||
|
new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
|
||||||
|
}, Names.named("sync")));
|
||||||
|
try {
|
||||||
|
return (S) SyncProxy.proxy(syncClientType, new SyncProxy(
|
||||||
|
syncClientType, client, delegateMap, sync2Async));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
assert false : "should have propagated";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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 java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import org.jclouds.concurrent.internal.SyncProxy;
|
||||||
|
import org.jclouds.internal.ClassMethodArgs;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class CreateClientForCaller implements Function<ClassMethodArgs, Object> {
|
||||||
|
private final ConcurrentMap<ClassMethodArgs, Object> asyncMap;
|
||||||
|
private final Provider<ConcurrentMap<ClassMethodArgs, Object>> delegateMap;
|
||||||
|
Map<Class<?>, Class<?>> sync2Async;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CreateClientForCaller(
|
||||||
|
@Named("async") ConcurrentMap<ClassMethodArgs, Object> asyncMap,
|
||||||
|
@Named("sync") Provider<ConcurrentMap<ClassMethodArgs, Object>> delegateMap) {
|
||||||
|
this.asyncMap = asyncMap;
|
||||||
|
this.delegateMap = delegateMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Object apply(final ClassMethodArgs from) {
|
||||||
|
Class syncClass = from.getMethod().getReturnType();
|
||||||
|
Class asyncClass = sync2Async.get(syncClass);
|
||||||
|
checkState(asyncClass != null, "configuration error, sync class "
|
||||||
|
+ syncClass.getName() + " not mapped to an async class");
|
||||||
|
Object asyncClient = asyncMap.get(from);
|
||||||
|
checkState(asyncClient != null, "configuration error, sync client for "
|
||||||
|
+ from + " not found");
|
||||||
|
try {
|
||||||
|
return SyncProxy.proxy(syncClass, new SyncProxy(syncClass,
|
||||||
|
asyncClient, delegateMap.get(), sync2Async));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
assert false : "should have propagated";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,31 +18,19 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.rest.config;
|
package org.jclouds.rest.config;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.concurrent.internal.SyncProxy;
|
|
||||||
import org.jclouds.internal.ClassMethodArgs;
|
import org.jclouds.internal.ClassMethodArgs;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Provider;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -56,15 +44,15 @@ public class RestClientModule<S, A> extends AbstractModule {
|
||||||
protected final Map<Class<?>, Class<?>> delegates;
|
protected final Map<Class<?>, Class<?>> delegates;
|
||||||
|
|
||||||
public RestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
public RestClientModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||||
Map<Class<?>, Class<?>> delegates) {
|
Map<Class<?>, Class<?>> delegates) {
|
||||||
this.asyncClientType = asyncClientType;
|
this.asyncClientType = asyncClientType;
|
||||||
this.syncClientType = syncClientType;
|
this.syncClientType = syncClientType;
|
||||||
this.delegates = delegates;
|
this.delegates = delegates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
public RestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||||
this(syncClientType, asyncClientType, ImmutableMap.<Class<?>, Class<?>> of(syncClientType,
|
this(syncClientType, asyncClientType, ImmutableMap
|
||||||
asyncClientType));
|
.<Class<?>, Class<?>> of(syncClientType, asyncClientType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,8 +69,10 @@ public class RestClientModule<S, A> extends AbstractModule {
|
||||||
* ex.
|
* ex.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(AWSRedirectionRetryHandler.class);
|
* bind(HttpRetryHandler.class).annotatedWith(Redirection.class).to(
|
||||||
* bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AWSClientErrorRetryHandler.class);
|
* AWSRedirectionRetryHandler.class);
|
||||||
|
* bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(
|
||||||
|
* AWSClientErrorRetryHandler.class);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -95,9 +85,12 @@ public class RestClientModule<S, A> extends AbstractModule {
|
||||||
* ex.
|
* ex.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseAWSErrorFromXmlContent.class);
|
* bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
|
||||||
* bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseAWSErrorFromXmlContent.class);
|
* ParseAWSErrorFromXmlContent.class);
|
||||||
* bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseAWSErrorFromXmlContent.class);
|
* bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
|
||||||
|
* ParseAWSErrorFromXmlContent.class);
|
||||||
|
* bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
|
||||||
|
* ParseAWSErrorFromXmlContent.class);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -106,110 +99,21 @@ public class RestClientModule<S, A> extends AbstractModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bindAsyncClient() {
|
protected void bindAsyncClient() {
|
||||||
Provider<A> asyncProvider = new AsyncClientProvider<A>(asyncClientType);
|
BinderUtils.bindAsyncClient(binder(), asyncClientType);
|
||||||
binder().requestInjection(asyncProvider);
|
|
||||||
bind(asyncClientType).toProvider(asyncProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
static class AsyncClientProvider<A> implements Provider<A> {
|
|
||||||
@Inject
|
|
||||||
Injector injector;
|
|
||||||
private final Class<A> asyncClientType;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
AsyncClientProvider(Class<A> asyncClientType) {
|
|
||||||
this.asyncClientType = asyncClientType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Singleton
|
|
||||||
public A get() {
|
|
||||||
return (A) injector.getInstance(AsyncClientFactory.class).create(asyncClientType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void bindClient() {
|
protected void bindClient() {
|
||||||
Provider<S> asyncProvider = new ClientProvider<S, A>(asyncClientType, syncClientType,
|
BinderUtils.bindClient(binder(), syncClientType, asyncClientType,
|
||||||
delegates);
|
delegates);
|
||||||
binder().requestInjection(asyncProvider);
|
|
||||||
bind(syncClientType).toProvider(asyncProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
static class ClientProvider<S, A> implements Provider<S> {
|
|
||||||
@Inject
|
|
||||||
Injector injector;
|
|
||||||
private final Class<S> syncClientType;
|
|
||||||
private final Class<A> asyncClientType;
|
|
||||||
private final Map<Class<?>, Class<?>> sync2Async;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ClientProvider(Class<A> asyncClientType, Class<S> syncClientType,
|
|
||||||
Map<Class<?>, Class<?>> sync2Async) {
|
|
||||||
this.asyncClientType = asyncClientType;
|
|
||||||
this.syncClientType = syncClientType;
|
|
||||||
this.sync2Async = sync2Async;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Singleton
|
|
||||||
public S get() {
|
|
||||||
A client = (A) injector.getInstance(asyncClientType);
|
|
||||||
ConcurrentMap<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
|
|
||||||
new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
|
|
||||||
}, Names.named("sync")));
|
|
||||||
try {
|
|
||||||
return (S) SyncProxy.proxy(syncClientType, new SyncProxy(syncClientType, client,
|
|
||||||
delegateMap, sync2Async));
|
|
||||||
} catch (Exception e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
assert false : "should have propagated";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("sync")
|
@Named("sync")
|
||||||
ConcurrentMap<ClassMethodArgs, Object> provideSyncDelegateMap(
|
ConcurrentMap<ClassMethodArgs, Object> provideSyncDelegateMap(
|
||||||
CreateClientForCaller createClientForCaller) {
|
CreateClientForCaller createClientForCaller) {
|
||||||
createClientForCaller.sync2Async = delegates;
|
createClientForCaller.sync2Async = delegates;
|
||||||
return new MapMaker().makeComputingMap(createClientForCaller);
|
return new MapMaker().makeComputingMap(createClientForCaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CreateClientForCaller implements Function<ClassMethodArgs, Object> {
|
|
||||||
private final ConcurrentMap<ClassMethodArgs, Object> asyncMap;
|
|
||||||
private final Provider<ConcurrentMap<ClassMethodArgs, Object>> delegateMap;
|
|
||||||
private Map<Class<?>, Class<?>> sync2Async;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
CreateClientForCaller(@Named("async") ConcurrentMap<ClassMethodArgs, Object> asyncMap,
|
|
||||||
@Named("sync") Provider<ConcurrentMap<ClassMethodArgs, Object>> delegateMap) {
|
|
||||||
this.asyncMap = asyncMap;
|
|
||||||
this.delegateMap = delegateMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Object apply(final ClassMethodArgs from) {
|
|
||||||
Class syncClass = from.getMethod().getReturnType();
|
|
||||||
Class asyncClass = sync2Async.get(syncClass);
|
|
||||||
checkState(asyncClass != null, "configuration error, sync class " + syncClass.getName()
|
|
||||||
+ " not mapped to an async class");
|
|
||||||
Object asyncClient = asyncMap.get(from);
|
|
||||||
checkState(asyncClient != null, "configuration error, sync client for " + from
|
|
||||||
+ " not found");
|
|
||||||
try {
|
|
||||||
return SyncProxy.proxy(syncClass, new SyncProxy(syncClass, asyncClient, delegateMap
|
|
||||||
.get(), sync2Async));
|
|
||||||
} catch (Exception e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
assert false : "should have propagated";
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -34,11 +34,14 @@ import org.jclouds.http.TransformingHttpCommandImpl;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.internal.ClassMethodArgs;
|
import org.jclouds.internal.ClassMethodArgs;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
import org.jclouds.rest.AsyncClientFactory;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.internal.AsyncRestClientProxy;
|
import org.jclouds.rest.internal.AsyncRestClientProxy;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
@ -59,23 +62,30 @@ public class RestModule extends AbstractModule {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
install(new ParserModule());
|
install(new ParserModule());
|
||||||
bind(UriBuilder.class).to(UriBuilderImpl.class);
|
bind(UriBuilder.class).to(UriBuilderImpl.class);
|
||||||
bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
|
bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(
|
||||||
|
Scopes.SINGLETON);
|
||||||
|
BinderUtils.bindAsyncClient(binder(), HttpAsyncClient.class);
|
||||||
|
BinderUtils.bindClient(binder(), HttpClient.class, HttpAsyncClient.class,
|
||||||
|
ImmutableMap.<Class<?>, Class<?>> of(HttpClient.class,
|
||||||
|
HttpAsyncClient.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("async")
|
@Named("async")
|
||||||
ConcurrentMap<ClassMethodArgs, Object> provideAsyncDelegateMap(
|
ConcurrentMap<ClassMethodArgs, Object> provideAsyncDelegateMap(
|
||||||
CreateAsyncClientForCaller createAsyncClientForCaller) {
|
CreateAsyncClientForCaller createAsyncClientForCaller) {
|
||||||
return new MapMaker().makeComputingMap(createAsyncClientForCaller);
|
return new MapMaker().makeComputingMap(createAsyncClientForCaller);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CreateAsyncClientForCaller implements Function<ClassMethodArgs, Object> {
|
static class CreateAsyncClientForCaller implements
|
||||||
|
Function<ClassMethodArgs, Object> {
|
||||||
private final Injector injector;
|
private final Injector injector;
|
||||||
private final AsyncRestClientProxy.Factory factory;
|
private final AsyncRestClientProxy.Factory factory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CreateAsyncClientForCaller(Injector injector, AsyncRestClientProxy.Factory factory) {
|
CreateAsyncClientForCaller(Injector injector,
|
||||||
|
AsyncRestClientProxy.Factory factory) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
@ -85,16 +95,17 @@ public class RestModule extends AbstractModule {
|
||||||
public Object apply(ClassMethodArgs from) {
|
public Object apply(ClassMethodArgs from) {
|
||||||
Class clazz = from.getAsyncClass();
|
Class clazz = from.getAsyncClass();
|
||||||
TypeLiteral typeLiteral = TypeLiteral.get(clazz);
|
TypeLiteral typeLiteral = TypeLiteral.get(clazz);
|
||||||
RestAnnotationProcessor util = (RestAnnotationProcessor) injector.getInstance(Key
|
RestAnnotationProcessor util = (RestAnnotationProcessor) injector
|
||||||
.get(TypeLiteral.get(Types.newParameterizedType(RestAnnotationProcessor.class,
|
.getInstance(Key.get(TypeLiteral.get(Types.newParameterizedType(
|
||||||
clazz))));
|
RestAnnotationProcessor.class, clazz))));
|
||||||
util.setCaller(from);
|
util.setCaller(from);
|
||||||
|
|
||||||
ConcurrentMap<ClassMethodArgs, Object> delegateMap = injector.getInstance(Key.get(
|
ConcurrentMap<ClassMethodArgs, Object> delegateMap = injector
|
||||||
new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
|
.getInstance(Key.get(
|
||||||
}, Names.named("async")));
|
new TypeLiteral<ConcurrentMap<ClassMethodArgs, Object>>() {
|
||||||
AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector, factory, util,
|
}, Names.named("async")));
|
||||||
typeLiteral, delegateMap);
|
AsyncRestClientProxy proxy = new AsyncRestClientProxy(injector,
|
||||||
|
factory, util, typeLiteral, delegateMap);
|
||||||
injector.injectMembers(proxy);
|
injector.injectMembers(proxy);
|
||||||
return AsyncClientFactory.create(clazz, proxy);
|
return AsyncClientFactory.create(clazz, proxy);
|
||||||
}
|
}
|
||||||
|
@ -108,9 +119,9 @@ public class RestModule extends AbstractModule {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request,
|
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request,
|
||||||
Function<HttpResponse, ?> transformer) {
|
Function<HttpResponse, ?> transformer) {
|
||||||
return new TransformingHttpCommandImpl(uriBuilderProvider, executorService, request,
|
return new TransformingHttpCommandImpl(uriBuilderProvider,
|
||||||
transformer);
|
executorService, request, transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -27,6 +27,8 @@ import javax.inject.Inject;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -40,9 +42,15 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
|
||||||
private final Closer closer;
|
private final Closer closer;
|
||||||
private final URI endPoint;
|
private final URI endPoint;
|
||||||
private final String account;
|
private final String account;
|
||||||
|
private final HttpClient simpleClient;
|
||||||
|
private final HttpAsyncClient simpleAsyncClient;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestContextImpl(Closer closer, A asyncApi, S syncApi, URI endPoint, String account) {
|
public RestContextImpl(Closer closer, HttpClient simpleClient,
|
||||||
|
HttpAsyncClient simpleAsyncClient, S syncApi, A asyncApi,
|
||||||
|
URI endPoint, String account) {
|
||||||
|
this.simpleClient = simpleClient;
|
||||||
|
this.simpleAsyncClient = simpleAsyncClient;
|
||||||
this.asyncApi = asyncApi;
|
this.asyncApi = asyncApi;
|
||||||
this.syncApi = syncApi;
|
this.syncApi = syncApi;
|
||||||
this.closer = closer;
|
this.closer = closer;
|
||||||
|
@ -55,6 +63,7 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
|
||||||
*
|
*
|
||||||
* @see Closer
|
* @see Closer
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
closer.close();
|
closer.close();
|
||||||
|
@ -63,20 +72,34 @@ public class RestContextImpl<S, A> implements RestContext<S, A> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getAccount() {
|
public String getAccount() {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public A getAsyncApi() {
|
public A getAsyncApi() {
|
||||||
return asyncApi;
|
return asyncApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public S getApi() {
|
public S getApi() {
|
||||||
return syncApi;
|
return syncApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public URI getEndPoint() {
|
public URI getEndPoint() {
|
||||||
return endPoint;
|
return endPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpAsyncClient asyncHttp() {
|
||||||
|
return this.simpleAsyncClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpClient http() {
|
||||||
|
return this.simpleClient;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -42,91 +43,97 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for functionality all HttpCommandExecutorServices must express. These tests will operate
|
* Tests for functionality all HttpCommandExecutorServices must express. These
|
||||||
* against an in-memory http engine, so as to ensure end-to-end functionality works.
|
* tests will operate against an in-memory http engine, so as to ensure
|
||||||
|
* end-to-end functionality works.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(threadPoolSize = 10, groups = "integration", sequential = true)
|
@Test(threadPoolSize = 10, groups = "integration", sequential = true)
|
||||||
public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends BaseJettyTest {
|
public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends
|
||||||
|
BaseJettyTest {
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testRequestFilter() throws MalformedURLException, ExecutionException,
|
public void testRequestFilter() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.downloadFilter("", "filterme").trim(), "test");
|
assertEquals(client.downloadFilter("", "filterme").trim(), "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: filtering redirect test
|
// TODO: filtering redirect test
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetStringWithHeader() throws MalformedURLException, ExecutionException,
|
public void testGetStringWithHeader() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.download("", "test").trim(), "test");
|
assertEquals(client.download("", "test").trim(), "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetString() throws MalformedURLException, ExecutionException,
|
public void testGetString() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.download("").trim(), XML);
|
assertEquals(client.download("").trim(), XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "gets")
|
@DataProvider(name = "gets")
|
||||||
public Object[][] createData() {
|
public Object[][] createData() {
|
||||||
return new Object[][] { { "object" }, { "/path" }, { "sp ace" }, { "unic₪de" },
|
return new Object[][] { { "object" }, { "/path" }, { "sp ace" },
|
||||||
{ "qu?stion" } };
|
{ "unic₪de" }, { "qu?stion" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000, dataProvider = "gets")
|
@Test(invocationCount = 25, timeOut = 5000, dataProvider = "gets")
|
||||||
public void testGetStringSynch(String uri) throws MalformedURLException, ExecutionException,
|
public void testGetStringSynch(String uri) throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
// TODO why need trim?
|
// TODO why need trim?
|
||||||
assertEquals(client.synch(uri).trim(), XML);
|
assertEquals(client.synch(uri).trim(), XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetException() throws MalformedURLException, ExecutionException,
|
public void testGetException() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.downloadException("", GetOptions.Builder.tail(1)).trim(), "foo");
|
assertEquals(client.downloadException("", GetOptions.Builder.tail(1))
|
||||||
|
.trim(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetSynchException() throws MalformedURLException, ExecutionException,
|
public void testGetSynchException() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.synchException("", "").trim(), "foo");
|
assertEquals(client.synchException("", "").trim(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetStringRedirect() throws MalformedURLException, ExecutionException,
|
public void testGetStringRedirect() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.download("redirect").trim(), XML2);
|
assertEquals(client.download("redirect").trim(), XML2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 100, timeOut = 5000)
|
@Test(invocationCount = 100, timeOut = 5000)
|
||||||
public void testGetBigFile() throws MalformedURLException, ExecutionException,
|
public void testGetBigFile() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(encryptionService.toBase64String(encryptionService.md5(client
|
assertEquals(encryptionService.toBase64String(encryptionService
|
||||||
.downloadStream("101constitutions"))), md5);
|
.md5(context.http().get(
|
||||||
|
URI.create(String.format("http://localhost:%d/%s", testPort,
|
||||||
|
"101constitutions"))))), md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = false, invocationCount = 25, timeOut = 5000)
|
@Test(enabled = false, invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetStringPermanentRedirect() throws MalformedURLException, ExecutionException,
|
public void testGetStringPermanentRedirect() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
// GetString get = factory.createGetString("permanentredirect");
|
// GetString get = factory.createGetString("permanentredirect");
|
||||||
// assert get != null;
|
// assert get != null;
|
||||||
// client.submit(get);
|
// client.submit(get);
|
||||||
// assertEquals(get.get(10, TimeUnit.SECONDS).trim(), XML2);
|
// assertEquals(get.get(10, TimeUnit.SECONDS).trim(), XML2);
|
||||||
// TODO assert misses are only one, as permanent redirects paths should be remembered.
|
// TODO assert misses are only one, as permanent redirects paths should be
|
||||||
|
// remembered.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testPost() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPost() throws MalformedURLException, ExecutionException,
|
||||||
TimeoutException {
|
InterruptedException, TimeoutException {
|
||||||
assertEquals(client.post("", "foo").trim(), "fooPOST");
|
assertEquals(client.post("", "foo").trim(), "fooPOST");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 10000)
|
@Test(invocationCount = 25, timeOut = 10000)
|
||||||
public void testPostAsInputStream() throws MalformedURLException, ExecutionException,
|
public void testPostAsInputStream() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
try {
|
try {
|
||||||
assertEquals(client.postAsInputStream("", "foo").trim(), "fooPOST");
|
assertEquals(client.postAsInputStream("", "foo").trim(), "fooPOST");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -135,8 +142,8 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests sending a big file to the server. Note: this is a heavy test, takes several minutes to
|
* Tests sending a big file to the server. Note: this is a heavy test, takes
|
||||||
* finish.
|
* several minutes to finish.
|
||||||
*
|
*
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
|
@ -150,7 +157,8 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
f = File.createTempFile(filename, "tmp");
|
f = File.createTempFile(filename, "tmp");
|
||||||
f.deleteOnExit();
|
f.deleteOnExit();
|
||||||
long length = (long) (Runtime.getRuntime().freeMemory() * 1.1);
|
long length = (long) (Runtime.getRuntime().freeMemory() * 1.1);
|
||||||
os = new BufferedOutputStream(new FileOutputStream(f.getAbsolutePath()));
|
os = new BufferedOutputStream(
|
||||||
|
new FileOutputStream(f.getAbsolutePath()));
|
||||||
|
|
||||||
MessageDigest eTag = JCEEncryptionService.getDigest();
|
MessageDigest eTag = JCEEncryptionService.getDigest();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
@ -168,7 +176,8 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
|
|
||||||
// upload and verify the response
|
// upload and verify the response
|
||||||
assertEquals(client.postWithMd5("fileso",
|
assertEquals(client.postWithMd5("fileso",
|
||||||
this.encryptionService.toBase64String(eTag.digest()), f).trim(), "created");
|
this.encryptionService.toBase64String(eTag.digest()), f).trim(),
|
||||||
|
"created");
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (os != null)
|
if (os != null)
|
||||||
|
@ -192,39 +201,40 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testPostBinder() throws MalformedURLException, ExecutionException,
|
public void testPostBinder() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.postJson("", "foo").trim(), "{\"key\":\"foo\"}POST");
|
assertEquals(client.postJson("", "foo").trim(), "{\"key\":\"foo\"}POST");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testPut() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testPut() throws MalformedURLException, ExecutionException,
|
||||||
TimeoutException {
|
InterruptedException, TimeoutException {
|
||||||
assertEquals(client.upload("", "foo").trim(), "fooPUT");
|
assertEquals(client.upload("", "foo").trim(), "fooPUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testPutRedirect() throws MalformedURLException, ExecutionException,
|
public void testPutRedirect() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.upload("redirect", "foo").trim(), "fooPUTREDIRECT");
|
assertEquals(client.upload("redirect", "foo").trim(), "fooPUTREDIRECT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testKillRobotSlowly() throws MalformedURLException, ExecutionException,
|
public void testKillRobotSlowly() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.action("robot", "kill", ImmutableMap.of("death", "slow")).trim(),
|
assertEquals(client.action("robot", "kill",
|
||||||
"robot->kill:{death=slow}");
|
ImmutableMap.of("death", "slow")).trim(),
|
||||||
|
"robot->kill:{death=slow}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testHead() throws MalformedURLException, ExecutionException, InterruptedException,
|
public void testHead() throws MalformedURLException, ExecutionException,
|
||||||
TimeoutException {
|
InterruptedException, TimeoutException {
|
||||||
assert client.exists("");
|
assert client.exists("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(invocationCount = 25, timeOut = 5000)
|
@Test(invocationCount = 25, timeOut = 5000)
|
||||||
public void testGetAndParseSax() throws MalformedURLException, ExecutionException,
|
public void testGetAndParseSax() throws MalformedURLException,
|
||||||
InterruptedException, TimeoutException {
|
ExecutionException, InterruptedException, TimeoutException {
|
||||||
assertEquals(client.downloadAndParse(""), "whoppers");
|
assertEquals(client.downloadAndParse(""), "whoppers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
import org.jclouds.rest.config.RestClientModule;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessorTest.Localhost;
|
import org.jclouds.rest.internal.RestAnnotationProcessorTest.Localhost;
|
||||||
|
@ -68,12 +70,13 @@ import com.google.inject.Provides;
|
||||||
public abstract class BaseJettyTest {
|
public abstract class BaseJettyTest {
|
||||||
|
|
||||||
public static final class IntegrationContextBuilder extends
|
public static final class IntegrationContextBuilder extends
|
||||||
RestContextBuilder<IntegrationTestClient, IntegrationTestAsyncClient> {
|
RestContextBuilder<IntegrationTestClient, IntegrationTestAsyncClient> {
|
||||||
private final int testPort;
|
private final int testPort;
|
||||||
|
|
||||||
public IntegrationContextBuilder(String providerName, Properties properties, int testPort) {
|
public IntegrationContextBuilder(String providerName,
|
||||||
super(providerName, IntegrationTestClient.class, IntegrationTestAsyncClient.class,
|
Properties properties, int testPort) {
|
||||||
properties);
|
super(providerName, IntegrationTestClient.class,
|
||||||
|
IntegrationTestAsyncClient.class, properties);
|
||||||
this.testPort = testPort;
|
this.testPort = testPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +87,10 @@ public abstract class BaseJettyTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addClientModule(List<Module> modules) {
|
protected void addClientModule(List<Module> modules) {
|
||||||
modules.add(new RestClientModule<IntegrationTestClient, IntegrationTestAsyncClient>(
|
modules
|
||||||
syncClientType, asyncClientType) {
|
.add(new RestClientModule<IntegrationTestClient, IntegrationTestAsyncClient>(
|
||||||
});
|
syncClientType, asyncClientType) {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -102,17 +106,18 @@ public abstract class BaseJettyTest {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).annotatedWith(Localhost.class).toInstance(
|
bind(URI.class).annotatedWith(Localhost.class).toInstance(
|
||||||
URI.create("http://localhost:" + testPort));
|
URI.create("http://localhost:" + testPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( { "unchecked" })
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<IntegrationTestClient, IntegrationTestAsyncClient> provideContext(Closer closer,
|
RestContext<IntegrationTestClient, IntegrationTestAsyncClient> provideContext(
|
||||||
IntegrationTestClient aclient, IntegrationTestAsyncClient client,
|
Closer closer, HttpClient simpleClient,
|
||||||
@Localhost URI endPoint) {
|
HttpAsyncClient simpleAsyncClient, IntegrationTestClient client,
|
||||||
return new RestContextImpl(closer, client, aclient, endPoint, System
|
IntegrationTestAsyncClient aclient, @Localhost URI endPoint) {
|
||||||
.getProperty("user.name"));
|
return new RestContextImpl<IntegrationTestClient, IntegrationTestAsyncClient>(
|
||||||
|
closer, simpleClient, simpleAsyncClient, client, aclient,
|
||||||
|
endPoint, System.getProperty("user.name"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,40 +130,47 @@ public abstract class BaseJettyTest {
|
||||||
private AtomicInteger cycle = new AtomicInteger(0);
|
private AtomicInteger cycle = new AtomicInteger(0);
|
||||||
private Server server2;
|
private Server server2;
|
||||||
protected RestContext<IntegrationTestClient, IntegrationTestAsyncClient> context;
|
protected RestContext<IntegrationTestClient, IntegrationTestAsyncClient> context;
|
||||||
private int testPort;
|
protected int testPort;
|
||||||
protected EncryptionService encryptionService;
|
protected EncryptionService encryptionService;
|
||||||
protected String md5;
|
protected String md5;
|
||||||
static final Pattern actionPattern = Pattern.compile("/objects/(.*)/action/([a-z]*);?(.*)");
|
static final Pattern actionPattern = Pattern
|
||||||
|
.compile("/objects/(.*)/action/([a-z]*);?(.*)");
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
@Parameters( { "test-jetty-port" })
|
@Parameters( { "test-jetty-port" })
|
||||||
public void setUpJetty(@Optional("8123") final int testPort) throws Exception {
|
public void setUpJetty(@Optional("8123") final int testPort)
|
||||||
|
throws Exception {
|
||||||
this.testPort = testPort;
|
this.testPort = testPort;
|
||||||
|
|
||||||
final InputSupplier<InputStream> oneHundredOneConstitutions = getTestDataSupplier();
|
final InputSupplier<InputStream> oneHundredOneConstitutions = getTestDataSupplier();
|
||||||
|
|
||||||
encryptionService = Guice.createInjector().getInstance(EncryptionService.class);
|
encryptionService = Guice.createInjector().getInstance(
|
||||||
|
EncryptionService.class);
|
||||||
|
|
||||||
md5 = encryptionService.md5Base64(ByteStreams.toByteArray(oneHundredOneConstitutions
|
md5 = encryptionService.md5Base64(ByteStreams
|
||||||
.getInput()));
|
.toByteArray(oneHundredOneConstitutions.getInput()));
|
||||||
|
|
||||||
Handler server1Handler = new AbstractHandler() {
|
Handler server1Handler = new AbstractHandler() {
|
||||||
public void handle(String target, HttpServletRequest request,
|
public void handle(String target, HttpServletRequest request,
|
||||||
HttpServletResponse response, int dispatch) throws IOException, ServletException {
|
HttpServletResponse response, int dispatch) throws IOException,
|
||||||
|
ServletException {
|
||||||
if (failIfNoContentLength(request, response)) {
|
if (failIfNoContentLength(request, response)) {
|
||||||
return;
|
return;
|
||||||
} else if (target.indexOf("redirect") > 0) {
|
} else if (target.indexOf("redirect") > 0) {
|
||||||
response.sendRedirect("http://localhost:" + (testPort + 1) + "/");
|
response
|
||||||
|
.sendRedirect("http://localhost:" + (testPort + 1) + "/");
|
||||||
} else if (target.indexOf("101constitutions") > 0) {
|
} else if (target.indexOf("101constitutions") > 0) {
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
response.setHeader("Content-MD5", md5);
|
response.setHeader("Content-MD5", md5);
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
ByteStreams.copy(oneHundredOneConstitutions.getInput(), response.getOutputStream());
|
ByteStreams.copy(oneHundredOneConstitutions.getInput(), response
|
||||||
|
.getOutputStream());
|
||||||
} else if (request.getMethod().equals("PUT")) {
|
} else if (request.getMethod().equals("PUT")) {
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.getWriter().println(
|
response.getWriter().println(
|
||||||
Utils.toStringAndClose(request.getInputStream()) + "PUT");
|
Utils.toStringAndClose(request.getInputStream())
|
||||||
|
+ "PUT");
|
||||||
} else {
|
} else {
|
||||||
response.sendError(500, "no content");
|
response.sendError(500, "no content");
|
||||||
}
|
}
|
||||||
|
@ -170,8 +182,9 @@ public abstract class BaseJettyTest {
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
if (request.getHeader("Content-MD5") != null) {
|
if (request.getHeader("Content-MD5") != null) {
|
||||||
String expectedMd5 = request.getHeader("Content-MD5");
|
String expectedMd5 = request.getHeader("Content-MD5");
|
||||||
String realMd5FromRequest = Base64.encodeBytes(new JCEEncryptionService()
|
String realMd5FromRequest = Base64
|
||||||
.md5(request.getInputStream()));
|
.encodeBytes(new JCEEncryptionService().md5(request
|
||||||
|
.getInputStream()));
|
||||||
boolean matched = expectedMd5.equals(realMd5FromRequest);
|
boolean matched = expectedMd5.equals(realMd5FromRequest);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
response.setContentType("text/xml");
|
response.setContentType("text/xml");
|
||||||
|
@ -181,7 +194,8 @@ public abstract class BaseJettyTest {
|
||||||
} else {
|
} else {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.getWriter().println(
|
response.getWriter().println(
|
||||||
Utils.toStringAndClose(request.getInputStream()) + "POST");
|
Utils.toStringAndClose(request.getInputStream())
|
||||||
|
+ "POST");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleAction(request, response);
|
handleAction(request, response);
|
||||||
|
@ -194,7 +208,8 @@ public abstract class BaseJettyTest {
|
||||||
response.getWriter().println("test");
|
response.getWriter().println("test");
|
||||||
} else if (request.getMethod().equals("HEAD")) {
|
} else if (request.getMethod().equals("HEAD")) {
|
||||||
/*
|
/*
|
||||||
* NOTE: by HTML specification, HEAD response MUST NOT include a body
|
* NOTE: by HTML specification, HEAD response MUST NOT include a
|
||||||
|
* body
|
||||||
*/
|
*/
|
||||||
response.setContentType("text/xml");
|
response.setContentType("text/xml");
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
@ -216,19 +231,22 @@ public abstract class BaseJettyTest {
|
||||||
|
|
||||||
Handler server2Handler = new AbstractHandler() {
|
Handler server2Handler = new AbstractHandler() {
|
||||||
public void handle(String target, HttpServletRequest request,
|
public void handle(String target, HttpServletRequest request,
|
||||||
HttpServletResponse response, int dispatch) throws IOException, ServletException {
|
HttpServletResponse response, int dispatch) throws IOException,
|
||||||
|
ServletException {
|
||||||
if (request.getMethod().equals("PUT")) {
|
if (request.getMethod().equals("PUT")) {
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.getWriter().println(
|
response.getWriter().println(
|
||||||
Utils.toStringAndClose(request.getInputStream()) + "PUTREDIRECT");
|
Utils.toStringAndClose(request.getInputStream())
|
||||||
|
+ "PUTREDIRECT");
|
||||||
}
|
}
|
||||||
} else if (request.getMethod().equals("POST")) {
|
} else if (request.getMethod().equals("POST")) {
|
||||||
if (request.getContentLength() > 0) {
|
if (request.getContentLength() > 0) {
|
||||||
if (request.getHeader("Content-MD5") != null) {
|
if (request.getHeader("Content-MD5") != null) {
|
||||||
String expectedMd5 = request.getHeader("Content-MD5");
|
String expectedMd5 = request.getHeader("Content-MD5");
|
||||||
String realMd5FromRequest = Base64.encodeBytes(new JCEEncryptionService()
|
String realMd5FromRequest = Base64
|
||||||
.md5(request.getInputStream()));
|
.encodeBytes(new JCEEncryptionService().md5(request
|
||||||
|
.getInputStream()));
|
||||||
boolean matched = expectedMd5.equals(realMd5FromRequest);
|
boolean matched = expectedMd5.equals(realMd5FromRequest);
|
||||||
if (matched) {
|
if (matched) {
|
||||||
response.setContentType("text/xml");
|
response.setContentType("text/xml");
|
||||||
|
@ -238,14 +256,16 @@ public abstract class BaseJettyTest {
|
||||||
} else {
|
} else {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.getWriter().println(
|
response.getWriter().println(
|
||||||
Utils.toStringAndClose(request.getInputStream()) + "POST");
|
Utils.toStringAndClose(request.getInputStream())
|
||||||
|
+ "POST");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleAction(request, response);
|
handleAction(request, response);
|
||||||
}
|
}
|
||||||
} else if (request.getMethod().equals("HEAD")) {
|
} else if (request.getMethod().equals("HEAD")) {
|
||||||
/*
|
/*
|
||||||
* NOTE: by HTML specification, HEAD response MUST NOT include a body
|
* NOTE: by HTML specification, HEAD response MUST NOT include a
|
||||||
|
* body
|
||||||
*/
|
*/
|
||||||
response.setContentType("text/xml");
|
response.setContentType("text/xml");
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
@ -276,7 +296,8 @@ public abstract class BaseJettyTest {
|
||||||
|
|
||||||
}.build();
|
}.build();
|
||||||
addConnectionProperties(properties);
|
addConnectionProperties(properties);
|
||||||
context = newBuilder(testPort, properties, createConnectionModule()).buildContext();
|
context = newBuilder(testPort, properties, createConnectionModule())
|
||||||
|
.buildContext();
|
||||||
client = context.getApi();
|
client = context.getApi();
|
||||||
assert client != null;
|
assert client != null;
|
||||||
|
|
||||||
|
@ -284,11 +305,12 @@ public abstract class BaseJettyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static InputSupplier<InputStream> getTestDataSupplier() throws IOException {
|
public static InputSupplier<InputStream> getTestDataSupplier()
|
||||||
byte[] oneConstitution = ByteStreams.toByteArray(new GZIPInputStream(BaseJettyTest.class
|
throws IOException {
|
||||||
.getResourceAsStream("/const.txt.gz")));
|
byte[] oneConstitution = ByteStreams.toByteArray(new GZIPInputStream(
|
||||||
|
BaseJettyTest.class.getResourceAsStream("/const.txt.gz")));
|
||||||
InputSupplier<ByteArrayInputStream> constitutionSupplier = ByteStreams
|
InputSupplier<ByteArrayInputStream> constitutionSupplier = ByteStreams
|
||||||
.newInputStreamSupplier(oneConstitution);
|
.newInputStreamSupplier(oneConstitution);
|
||||||
|
|
||||||
InputSupplier<InputStream> temp = ByteStreams.join(constitutionSupplier);
|
InputSupplier<InputStream> temp = ByteStreams.join(constitutionSupplier);
|
||||||
|
|
||||||
|
@ -299,9 +321,10 @@ public abstract class BaseJettyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RestContextBuilder<IntegrationTestClient, IntegrationTestAsyncClient> newBuilder(
|
public static RestContextBuilder<IntegrationTestClient, IntegrationTestAsyncClient> newBuilder(
|
||||||
final int testPort, final Properties properties, Module connectionModule) {
|
final int testPort, final Properties properties,
|
||||||
return new IntegrationContextBuilder("integration-test", properties, testPort)
|
Module connectionModule) {
|
||||||
.withModules(connectionModule);
|
return new IntegrationContextBuilder("integration-test", properties,
|
||||||
|
testPort).withModules(connectionModule);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterTest
|
@AfterTest
|
||||||
|
@ -323,8 +346,8 @@ public abstract class BaseJettyTest {
|
||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
protected boolean failEveryTenRequests(HttpServletRequest request, HttpServletResponse response)
|
protected boolean failEveryTenRequests(HttpServletRequest request,
|
||||||
throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
if (cycle.incrementAndGet() % 10 == 0) {
|
if (cycle.incrementAndGet() % 10 == 0) {
|
||||||
response.sendError(500);
|
response.sendError(500);
|
||||||
((Request) request).setHandled(true);
|
((Request) request).setHandled(true);
|
||||||
|
@ -334,7 +357,7 @@ public abstract class BaseJettyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean redirectEveryTwentyRequests(HttpServletRequest request,
|
protected boolean redirectEveryTwentyRequests(HttpServletRequest request,
|
||||||
HttpServletResponse response) throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
if (cycle.incrementAndGet() % 20 == 0) {
|
if (cycle.incrementAndGet() % 20 == 0) {
|
||||||
response.sendRedirect("http://localhost:" + (testPort + 1) + "/");
|
response.sendRedirect("http://localhost:" + (testPort + 1) + "/");
|
||||||
((Request) request).setHandled(true);
|
((Request) request).setHandled(true);
|
||||||
|
@ -343,8 +366,8 @@ public abstract class BaseJettyTest {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean failIfNoContentLength(HttpServletRequest request, HttpServletResponse response)
|
protected boolean failIfNoContentLength(HttpServletRequest request,
|
||||||
throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
if (request.getHeader(HttpHeaders.CONTENT_LENGTH) == null) {
|
if (request.getHeader(HttpHeaders.CONTENT_LENGTH) == null) {
|
||||||
response.sendError(500);
|
response.sendError(500);
|
||||||
((Request) request).setHandled(true);
|
((Request) request).setHandled(true);
|
||||||
|
@ -353,8 +376,8 @@ public abstract class BaseJettyTest {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAction(HttpServletRequest request, HttpServletResponse response)
|
private void handleAction(HttpServletRequest request,
|
||||||
throws IOException {
|
HttpServletResponse response) throws IOException {
|
||||||
final Matcher matcher = actionPattern.matcher(request.getRequestURI());
|
final Matcher matcher = actionPattern.matcher(request.getRequestURI());
|
||||||
boolean matchFound = matcher.find();
|
boolean matchFound = matcher.find();
|
||||||
if (matchFound) {
|
if (matchFound) {
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.jclouds.http;
|
package org.jclouds.http;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -67,10 +66,6 @@ public interface IntegrationTestAsyncClient {
|
||||||
@Path("objects/{id}")
|
@Path("objects/{id}")
|
||||||
ListenableFuture<String> download(@PathParam("id") String id);
|
ListenableFuture<String> download(@PathParam("id") String id);
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("{path}")
|
|
||||||
ListenableFuture<InputStream> downloadStream(@PathParam("path") String path);
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{path}")
|
@Path("{path}")
|
||||||
ListenableFuture<String> synch(@PathParam("path") String id);
|
ListenableFuture<String> synch(@PathParam("path") String id);
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.jclouds.http;
|
package org.jclouds.http;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -40,8 +39,6 @@ public interface IntegrationTestClient {
|
||||||
|
|
||||||
String download(String id);
|
String download(String id);
|
||||||
|
|
||||||
InputStream downloadStream(String id);
|
|
||||||
|
|
||||||
String downloadException(String id, HttpRequestOptions options);
|
String downloadException(String id, HttpRequestOptions options);
|
||||||
|
|
||||||
String synchException(String id, String header);
|
String synchException(String id, String header);
|
||||||
|
|
|
@ -81,6 +81,16 @@ public class RestContextBuilderTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpAsyncClient asyncHttp() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpClient http() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestRestContextBuilder extends RestContextBuilder<String, String> {
|
class TestRestContextBuilder extends RestContextBuilder<String, String> {
|
||||||
|
@ -111,7 +121,8 @@ public class RestContextBuilderTest {
|
||||||
List<Module> modules = new ArrayList<Module>();
|
List<Module> modules = new ArrayList<Module>();
|
||||||
HttpModule module = new HttpModule();
|
HttpModule module = new HttpModule();
|
||||||
modules.add(module);
|
modules.add(module);
|
||||||
new TestRestContextBuilder(new Properties()).addHttpModuleIfNeededAndNotPresent(modules);
|
new TestRestContextBuilder(new Properties())
|
||||||
|
.addHttpModuleIfNeededAndNotPresent(modules);
|
||||||
assertEquals(modules.size(), 1);
|
assertEquals(modules.size(), 1);
|
||||||
assertEquals(modules.remove(0), module);
|
assertEquals(modules.remove(0), module);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +132,8 @@ public class RestContextBuilderTest {
|
||||||
List<Module> modules = new ArrayList<Module>();
|
List<Module> modules = new ArrayList<Module>();
|
||||||
LoggingModule module = new NullLoggingModule();
|
LoggingModule module = new NullLoggingModule();
|
||||||
modules.add(module);
|
modules.add(module);
|
||||||
new TestRestContextBuilder(new Properties()).addLoggingModuleIfNotPresent(modules);
|
new TestRestContextBuilder(new Properties())
|
||||||
|
.addLoggingModuleIfNotPresent(modules);
|
||||||
assertEquals(modules.size(), 1);
|
assertEquals(modules.size(), 1);
|
||||||
assertEquals(modules.remove(0), module);
|
assertEquals(modules.remove(0), module);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +145,8 @@ public class RestContextBuilderTest {
|
||||||
modules.add(loggingModule);
|
modules.add(loggingModule);
|
||||||
HttpModule httpModule = new HttpModule();
|
HttpModule httpModule = new HttpModule();
|
||||||
modules.add(httpModule);
|
modules.add(httpModule);
|
||||||
TestRestContextBuilder builder = new TestRestContextBuilder(new Properties());
|
TestRestContextBuilder builder = new TestRestContextBuilder(
|
||||||
|
new Properties());
|
||||||
builder.addHttpModuleIfNeededAndNotPresent(modules);
|
builder.addHttpModuleIfNeededAndNotPresent(modules);
|
||||||
builder.addLoggingModuleIfNotPresent(modules);
|
builder.addLoggingModuleIfNotPresent(modules);
|
||||||
assertEquals(modules.size(), 2);
|
assertEquals(modules.size(), 2);
|
||||||
|
@ -144,7 +157,8 @@ public class RestContextBuilderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddBothWhenDoesntRequireHttp() {
|
public void testAddBothWhenDoesntRequireHttp() {
|
||||||
List<Module> modules = new ArrayList<Module>();
|
List<Module> modules = new ArrayList<Module>();
|
||||||
TestRestContextBuilder builder = new TestRestContextBuilder(new Properties());
|
TestRestContextBuilder builder = new TestRestContextBuilder(
|
||||||
|
new Properties());
|
||||||
builder.addHttpModuleIfNeededAndNotPresent(modules);
|
builder.addHttpModuleIfNeededAndNotPresent(modules);
|
||||||
builder.addLoggingModuleIfNotPresent(modules);
|
builder.addLoggingModuleIfNotPresent(modules);
|
||||||
assertEquals(modules.size(), 1);
|
assertEquals(modules.size(), 1);
|
||||||
|
@ -163,7 +177,8 @@ public class RestContextBuilderTest {
|
||||||
public void testAddBothWhenLive() {
|
public void testAddBothWhenLive() {
|
||||||
List<Module> modules = new ArrayList<Module>();
|
List<Module> modules = new ArrayList<Module>();
|
||||||
modules.add(new RequiresHttpModule());
|
modules.add(new RequiresHttpModule());
|
||||||
TestRestContextBuilder builder = new TestRestContextBuilder(new Properties());
|
TestRestContextBuilder builder = new TestRestContextBuilder(
|
||||||
|
new Properties());
|
||||||
builder.addHttpModuleIfNeededAndNotPresent(modules);
|
builder.addHttpModuleIfNeededAndNotPresent(modules);
|
||||||
builder.addLoggingModuleIfNotPresent(modules);
|
builder.addLoggingModuleIfNotPresent(modules);
|
||||||
assertEquals(modules.size(), 3);
|
assertEquals(modules.size(), 3);
|
||||||
|
@ -186,7 +201,8 @@ public class RestContextBuilderTest {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TestRestContextBuilder builder = new TestRestContextBuilder(new Properties());
|
TestRestContextBuilder builder = new TestRestContextBuilder(
|
||||||
|
new Properties());
|
||||||
builder.withModules(module1, module2);
|
builder.withModules(module1, module2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -36,6 +36,8 @@ import org.jclouds.gogrid.GoGridClient;
|
||||||
import org.jclouds.gogrid.reference.GoGridConstants;
|
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -62,21 +64,24 @@ public class GoGridContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<GoGridClient, GoGridAsyncClient> provideContext(Closer closer,
|
RestContext<GoGridClient, GoGridAsyncClient> provideContext(Closer closer,
|
||||||
GoGridAsyncClient asyncApi, GoGridClient syncApi, @GoGrid URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) {
|
GoGridAsyncClient asyncApi, GoGridClient syncApi,
|
||||||
return new RestContextImpl<GoGridClient, GoGridAsyncClient>(closer, asyncApi, syncApi,
|
@GoGrid URI endPoint,
|
||||||
endPoint, account);
|
@Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) {
|
||||||
|
return new RestContextImpl<GoGridClient, GoGridAsyncClient>(closer, http,
|
||||||
|
asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public static class DateSecondsAdapter implements DateAdapter {
|
public static class DateSecondsAdapter implements DateAdapter {
|
||||||
|
|
||||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Date src, Type typeOfSrc,
|
||||||
|
JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src.getTime());
|
return new JsonPrimitive(src.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
public Date deserialize(JsonElement json, Type typeOfT,
|
||||||
throws JsonParseException {
|
JsonDeserializationContext context) throws JsonParseException {
|
||||||
String toParse = json.getAsJsonPrimitive().getAsString();
|
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||||
return new Date(Long.valueOf(toParse));
|
return new Date(Long.valueOf(toParse));
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ import org.jclouds.ibmdev.IBMDeveloperCloudAsyncClient;
|
||||||
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
||||||
import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants;
|
import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -58,7 +60,8 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the IBMDeveloperCloud connection, including logging and http transport.
|
* Configures the IBMDeveloperCloud connection, including logging and http
|
||||||
|
* transport.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -76,12 +79,16 @@ public class IBMDeveloperCloudContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient> provideContext(Closer closer,
|
RestContext<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient> provideContext(
|
||||||
IBMDeveloperCloudAsyncClient asyncApi, IBMDeveloperCloudClient syncApi,
|
Closer closer,
|
||||||
@IBMDeveloperCloud URI endPoint,
|
HttpClient http,
|
||||||
@Named(IBMDeveloperCloudConstants.PROPERTY_IBMDEVELOPERCLOUD_USER) String account) {
|
HttpAsyncClient asyncHttp,
|
||||||
return new RestContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>(closer,
|
IBMDeveloperCloudAsyncClient asyncApi,
|
||||||
asyncApi, syncApi, endPoint, account);
|
IBMDeveloperCloudClient syncApi,
|
||||||
|
@IBMDeveloperCloud URI endPoint,
|
||||||
|
@Named(IBMDeveloperCloudConstants.PROPERTY_IBMDEVELOPERCLOUD_USER) String account) {
|
||||||
|
return new RestContextImpl<IBMDeveloperCloudClient, IBMDeveloperCloudAsyncClient>(
|
||||||
|
closer, http, asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -28,6 +28,8 @@ import org.jclouds.mezeo.pcs2.PCS;
|
||||||
import org.jclouds.mezeo.pcs2.PCSAsyncClient;
|
import org.jclouds.mezeo.pcs2.PCSAsyncClient;
|
||||||
import org.jclouds.mezeo.pcs2.PCSClient;
|
import org.jclouds.mezeo.pcs2.PCSClient;
|
||||||
import org.jclouds.mezeo.pcs2.reference.PCSConstants;
|
import org.jclouds.mezeo.pcs2.reference.PCSConstants;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -50,11 +52,12 @@ public class PCSContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<PCSClient, PCSAsyncClient> provideContext(Closer closer, PCSAsyncClient async,
|
RestContext<PCSClient, PCSAsyncClient> provideContext(Closer closer,
|
||||||
PCSClient defaultApi, @PCS URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp, PCSAsyncClient async,
|
||||||
@Named(PCSConstants.PROPERTY_PCS2_USER) String account) {
|
PCSClient defaultApi, @PCS URI endPoint,
|
||||||
return new RestContextImpl<PCSClient, PCSAsyncClient>(closer, async, defaultApi, endPoint,
|
@Named(PCSConstants.PROPERTY_PCS2_USER) String account) {
|
||||||
account);
|
return new RestContextImpl<PCSClient, PCSAsyncClient>(closer, http,
|
||||||
|
asyncHttp, defaultApi, async, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -29,6 +29,8 @@ import org.jclouds.nirvanix.sdn.SDN;
|
||||||
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
||||||
import org.jclouds.nirvanix.sdn.SDNClient;
|
import org.jclouds.nirvanix.sdn.SDNClient;
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -47,11 +49,12 @@ public class SDNContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<SDNClient, SDNAsyncClient> provideContext(Closer closer, SDNAsyncClient async,
|
RestContext<SDNClient, SDNAsyncClient> provideContext(Closer closer,
|
||||||
SDNClient defaultApi, @SDN URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp, SDNAsyncClient async,
|
||||||
@Named(SDNConstants.PROPERTY_SDN_USERNAME) String account) {
|
SDNClient defaultApi, @SDN URI endPoint,
|
||||||
return new RestContextImpl<SDNClient, SDNAsyncClient>(closer, async, defaultApi, endPoint,
|
@Named(SDNConstants.PROPERTY_SDN_USERNAME) String account) {
|
||||||
account);
|
return new RestContextImpl<SDNClient, SDNAsyncClient>(closer, http,
|
||||||
|
asyncHttp, defaultApi, async, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -28,6 +28,8 @@ import org.jclouds.opscodeplatform.OpscodePlatform;
|
||||||
import org.jclouds.opscodeplatform.OpscodePlatformAsyncClient;
|
import org.jclouds.opscodeplatform.OpscodePlatformAsyncClient;
|
||||||
import org.jclouds.opscodeplatform.OpscodePlatformClient;
|
import org.jclouds.opscodeplatform.OpscodePlatformClient;
|
||||||
import org.jclouds.opscodeplatform.reference.OpscodePlatformConstants;
|
import org.jclouds.opscodeplatform.reference.OpscodePlatformConstants;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -35,7 +37,8 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the OpscodePlatform connection, including logging and http transport.
|
* Configures the OpscodePlatform connection, including logging and http
|
||||||
|
* transport.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -51,12 +54,16 @@ public class OpscodePlatformContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<OpscodePlatformClient, OpscodePlatformAsyncClient> provideContext(Closer closer,
|
RestContext<OpscodePlatformClient, OpscodePlatformAsyncClient> provideContext(
|
||||||
OpscodePlatformAsyncClient asyncApi, OpscodePlatformClient syncApi,
|
Closer closer,
|
||||||
@OpscodePlatform URI endPoint,
|
HttpClient http,
|
||||||
@Named(OpscodePlatformConstants.PROPERTY_OPSCODEPLATFORM_ENDPOINT) String account) {
|
HttpAsyncClient asyncHttp,
|
||||||
return new RestContextImpl<OpscodePlatformClient, OpscodePlatformAsyncClient>(closer,
|
OpscodePlatformAsyncClient asyncApi,
|
||||||
asyncApi, syncApi, endPoint, account);
|
OpscodePlatformClient syncApi,
|
||||||
|
@OpscodePlatform URI endPoint,
|
||||||
|
@Named(OpscodePlatformConstants.PROPERTY_OPSCODEPLATFORM_ENDPOINT) String account) {
|
||||||
|
return new RestContextImpl<OpscodePlatformClient, OpscodePlatformAsyncClient>(
|
||||||
|
closer, http, asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -28,6 +28,8 @@ import org.jclouds.rackspace.CloudFiles;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesAsyncClient;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesClient;
|
||||||
import org.jclouds.rackspace.reference.RackspaceConstants;
|
import org.jclouds.rackspace.reference.RackspaceConstants;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -35,7 +37,8 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link CloudFilesContextModule}; requires {@link CloudFilesAsyncClient} bound.
|
* Configures the {@link CloudFilesContextModule}; requires
|
||||||
|
* {@link CloudFilesAsyncClient} bound.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -47,11 +50,13 @@ public class CloudFilesContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<CloudFilesClient, CloudFilesAsyncClient> provideContext(Closer closer,
|
RestContext<CloudFilesClient, CloudFilesAsyncClient> provideContext(
|
||||||
CloudFilesAsyncClient asyncApi, CloudFilesClient defaultApi, @CloudFiles URI endPoint,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
CloudFilesAsyncClient asyncApi, CloudFilesClient defaultApi,
|
||||||
return new RestContextImpl<CloudFilesClient, CloudFilesAsyncClient>(closer, asyncApi,
|
@CloudFiles URI endPoint,
|
||||||
defaultApi, endPoint, account);
|
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
||||||
|
return new RestContextImpl<CloudFilesClient, CloudFilesAsyncClient>(
|
||||||
|
closer, http, asyncHttp, defaultApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.jclouds.rackspace.CloudServers;
|
||||||
import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient;
|
import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient;
|
||||||
import org.jclouds.rackspace.cloudservers.CloudServersClient;
|
import org.jclouds.rackspace.cloudservers.CloudServersClient;
|
||||||
import org.jclouds.rackspace.reference.RackspaceConstants;
|
import org.jclouds.rackspace.reference.RackspaceConstants;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
@ -44,12 +46,13 @@ public class CloudServersContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<CloudServersClient, CloudServersAsyncClient> provideContext(Closer closer,
|
RestContext<CloudServersClient, CloudServersAsyncClient> provideContext(
|
||||||
CloudServersAsyncClient asynchApi, CloudServersClient defaultApi,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@CloudServers URI endPoint,
|
CloudServersAsyncClient asynchApi, CloudServersClient defaultApi,
|
||||||
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
@CloudServers URI endPoint,
|
||||||
return new RestContextImpl<CloudServersClient, CloudServersAsyncClient>(closer, asynchApi,
|
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
||||||
defaultApi, endPoint, account);
|
return new RestContextImpl<CloudServersClient, CloudServersAsyncClient>(
|
||||||
|
closer, http, asyncHttp, defaultApi, asynchApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -39,6 +39,8 @@ import org.jclouds.rackspace.reference.RackspaceConstants;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
import org.jclouds.rest.AsyncClientFactory;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
@ -59,7 +61,8 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
|
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
private final class RestRackspaceAuthenticationClientModule extends AbstractModule {
|
private final class RestRackspaceAuthenticationClientModule extends
|
||||||
|
AbstractModule {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -74,16 +77,18 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class RackspaceAuthenticationContextModule extends AbstractModule {
|
private final class RackspaceAuthenticationContextModule extends
|
||||||
|
AbstractModule {
|
||||||
|
|
||||||
@SuppressWarnings( { "unused" })
|
@SuppressWarnings( { "unused" })
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<RackspaceAuthentication, RackspaceAuthentication> provideContext(Closer closer,
|
RestContext<RackspaceAuthentication, RackspaceAuthentication> provideContext(
|
||||||
RackspaceAuthentication api, @Authentication URI endPoint,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
RackspaceAuthentication api, @Authentication URI endPoint,
|
||||||
return new RestContextImpl<RackspaceAuthentication, RackspaceAuthentication>(closer, api,
|
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
|
||||||
api, endPoint, account);
|
return new RestContextImpl<RackspaceAuthentication, RackspaceAuthentication>(
|
||||||
|
closer, http, asyncHttp, api, api, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -92,16 +97,18 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
String account = checkNotNull(System.getProperty("jclouds.test.user"),
|
||||||
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
"jclouds.test.user");
|
||||||
|
String key = checkNotNull(System.getProperty("jclouds.test.key"),
|
||||||
|
"jclouds.test.key");
|
||||||
|
|
||||||
private RestContext<RackspaceAuthentication, RackspaceAuthentication> context;
|
private RestContext<RackspaceAuthentication, RackspaceAuthentication> context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthentication() throws Exception {
|
public void testAuthentication() throws Exception {
|
||||||
RackspaceAuthentication authentication = context.getAsyncApi();
|
RackspaceAuthentication authentication = context.getAsyncApi();
|
||||||
AuthenticationResponse response = authentication.authenticate(account, key).get(10,
|
AuthenticationResponse response = authentication.authenticate(account,
|
||||||
TimeUnit.SECONDS);
|
key).get(10, TimeUnit.SECONDS);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getStorageUrl());
|
assertNotNull(response.getStorageUrl());
|
||||||
assertNotNull(response.getCDNManagementUrl());
|
assertNotNull(response.getCDNManagementUrl());
|
||||||
|
@ -118,8 +125,9 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
context = new RestContextBuilder<RackspaceAuthentication, RackspaceAuthentication>(
|
context = new RestContextBuilder<RackspaceAuthentication, RackspaceAuthentication>(
|
||||||
"rackspace", RackspaceAuthentication.class, RackspaceAuthentication.class,
|
"rackspace", RackspaceAuthentication.class,
|
||||||
new RackspacePropertiesBuilder(account, key).build()) {
|
RackspaceAuthentication.class, new RackspacePropertiesBuilder(
|
||||||
|
account, key).build()) {
|
||||||
@Override
|
@Override
|
||||||
protected void addClientModule(List<Module> modules) {
|
protected void addClientModule(List<Module> modules) {
|
||||||
modules.add(new RestRackspaceAuthenticationClientModule());
|
modules.add(new RestRackspaceAuthenticationClientModule());
|
||||||
|
@ -127,12 +135,14 @@ public class RackspaceAuthenticationLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addContextModule(String providerName, List<Module> modules) {
|
protected void addContextModule(String providerName,
|
||||||
|
List<Module> modules) {
|
||||||
modules.add(new RackspaceAuthenticationContextModule());
|
modules.add(new RackspaceAuthenticationContextModule());
|
||||||
|
|
||||||
}
|
}
|
||||||
}.withModules(new Log4JLoggingModule(),
|
}.withModules(
|
||||||
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))
|
new Log4JLoggingModule(),
|
||||||
.buildContext();
|
new ExecutorServiceModule(sameThreadExecutor(),
|
||||||
|
sameThreadExecutor())).buildContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.rimuhosting.miro.RimuHosting;
|
import org.jclouds.rimuhosting.miro.RimuHosting;
|
||||||
|
@ -49,11 +51,13 @@ public class RimuHostingContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<RimuHostingClient, RimuHostingAsyncClient> provideContext(Closer closer,
|
RestContext<RimuHostingClient, RimuHostingAsyncClient> provideContext(
|
||||||
RimuHostingAsyncClient asyncApi, RimuHostingClient syncApi, @RimuHosting URI endPoint,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY) String account) {
|
RimuHostingAsyncClient asyncApi, RimuHostingClient syncApi,
|
||||||
return new RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>(closer, asyncApi,
|
@RimuHosting URI endPoint,
|
||||||
syncApi, endPoint, account);
|
@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY) String account) {
|
||||||
|
return new RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>(
|
||||||
|
closer, http, asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -26,6 +26,8 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.CDateAdapter;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.twitter.Twitter;
|
import org.jclouds.twitter.Twitter;
|
||||||
|
@ -53,10 +55,12 @@ public class TwitterContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<TwitterClient, TwitterAsyncClient> provideContext(Closer closer,
|
RestContext<TwitterClient, TwitterAsyncClient> provideContext(Closer closer,
|
||||||
TwitterAsyncClient asyncApi, TwitterClient syncApi, @Twitter URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Named(TwitterConstants.PROPERTY_TWITTER_USER) String account) {
|
TwitterAsyncClient asyncApi, TwitterClient syncApi,
|
||||||
return new RestContextImpl<TwitterClient, TwitterAsyncClient>(closer, asyncApi, syncApi,
|
@Twitter URI endPoint,
|
||||||
endPoint, account);
|
@Named(TwitterConstants.PROPERTY_TWITTER_USER) String account) {
|
||||||
|
return new RestContextImpl<TwitterClient, TwitterAsyncClient>(closer,
|
||||||
|
http, asyncHttp, syncApi, asyncApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,6 +24,8 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.vcloud.VCloudAsyncClient;
|
import org.jclouds.vcloud.VCloudAsyncClient;
|
||||||
|
@ -45,10 +47,12 @@ public class VCloudContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<VCloudClient, VCloudAsyncClient> provideContext(Closer closer,
|
RestContext<VCloudClient, VCloudAsyncClient> provideContext(Closer closer,
|
||||||
VCloudAsyncClient asynchApi, VCloudClient defaultApi, @Org URI endPoint,
|
HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
VCloudAsyncClient asynchApi, VCloudClient defaultApi,
|
||||||
return new RestContextImpl<VCloudClient, VCloudAsyncClient>(closer, asynchApi, defaultApi,
|
@Org URI endPoint,
|
||||||
endPoint, account);
|
@Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
||||||
|
return new RestContextImpl<VCloudClient, VCloudAsyncClient>(closer, http,
|
||||||
|
asyncHttp, defaultApi, asynchApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -41,6 +41,8 @@ import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
import org.jclouds.rest.AsyncClientFactory;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
@ -64,12 +66,14 @@ public class VCloudLoginLiveTest {
|
||||||
|
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
private static final class VCloudLoginRestClientModule extends AbstractModule {
|
private static final class VCloudLoginRestClientModule extends
|
||||||
|
AbstractModule {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
|
protected VCloudLoginAsyncClient provideVCloudLogin(
|
||||||
|
AsyncClientFactory factory) {
|
||||||
return factory.create(VCloudLoginAsyncClient.class);
|
return factory.create(VCloudLoginAsyncClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +81,10 @@ public class VCloudLoginLiveTest {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
public BasicAuthentication provideBasicAuthentication(
|
public BasicAuthentication provideBasicAuthentication(
|
||||||
@Named(PROPERTY_VCLOUD_USER) String user, @Named(PROPERTY_VCLOUD_KEY) String key,
|
@Named(PROPERTY_VCLOUD_USER) String user,
|
||||||
EncryptionService encryptionService) throws UnsupportedEncodingException {
|
@Named(PROPERTY_VCLOUD_KEY) String key,
|
||||||
|
EncryptionService encryptionService)
|
||||||
|
throws UnsupportedEncodingException {
|
||||||
return new BasicAuthentication(user, key, encryptionService);
|
return new BasicAuthentication(user, key, encryptionService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,10 +108,11 @@ public class VCloudLoginLiveTest {
|
||||||
@SuppressWarnings( { "unused" })
|
@SuppressWarnings( { "unused" })
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<VCloudLoginAsyncClient, VCloudLoginAsyncClient> provideContext(Closer closer,
|
RestContext<VCloudLoginAsyncClient, VCloudLoginAsyncClient> provideContext(
|
||||||
VCloudLoginAsyncClient api, @VCloudLogin URI endPoint) {
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
return new RestContextImpl<VCloudLoginAsyncClient, VCloudLoginAsyncClient>(closer, api,
|
VCloudLoginAsyncClient api, @VCloudLogin URI endPoint) {
|
||||||
api, endPoint, "");
|
return new RestContextImpl<VCloudLoginAsyncClient, VCloudLoginAsyncClient>(
|
||||||
|
closer, http, asyncHttp, api, api, endPoint, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -120,7 +127,8 @@ public class VCloudLoginLiveTest {
|
||||||
public void testLogin() throws Exception {
|
public void testLogin() throws Exception {
|
||||||
VCloudLoginAsyncClient authentication = context.getAsyncApi();
|
VCloudLoginAsyncClient authentication = context.getAsyncApi();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
VCloudSession response = authentication.login().get(45, TimeUnit.SECONDS);
|
VCloudSession response = authentication.login().get(45,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getVCloudToken());
|
assertNotNull(response.getVCloudToken());
|
||||||
assertNotNull(response.getOrgs());
|
assertNotNull(response.getOrgs());
|
||||||
|
@ -129,14 +137,17 @@ public class VCloudLoginLiveTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
String endpoint = checkNotNull(System
|
||||||
"jclouds.test.endpoint")
|
.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint")
|
||||||
+ "/v0.8/login";
|
+ "/v0.8/login";
|
||||||
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
String account = checkNotNull(System.getProperty("jclouds.test.user"),
|
||||||
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
"jclouds.test.user");
|
||||||
context = new RestContextBuilder<VCloudLoginAsyncClient, VCloudLoginAsyncClient>("vcloud",
|
String key = checkNotNull(System.getProperty("jclouds.test.key"),
|
||||||
VCloudLoginAsyncClient.class, VCloudLoginAsyncClient.class,
|
"jclouds.test.key");
|
||||||
new VCloudPropertiesBuilder(URI.create(endpoint), account, key).build()) {
|
context = new RestContextBuilder<VCloudLoginAsyncClient, VCloudLoginAsyncClient>(
|
||||||
|
"vcloud", VCloudLoginAsyncClient.class,
|
||||||
|
VCloudLoginAsyncClient.class, new VCloudPropertiesBuilder(URI
|
||||||
|
.create(endpoint), account, key).build()) {
|
||||||
|
|
||||||
public void addContextModule(String providerName, List<Module> modules) {
|
public void addContextModule(String providerName, List<Module> modules) {
|
||||||
modules.add(new VCloudLoginContextModule());
|
modules.add(new VCloudLoginContextModule());
|
||||||
|
@ -147,8 +158,9 @@ public class VCloudLoginLiveTest {
|
||||||
modules.add(new VCloudLoginRestClientModule());
|
modules.add(new VCloudLoginRestClientModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
}.withModules(new Log4JLoggingModule(),
|
}.withModules(
|
||||||
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))
|
new Log4JLoggingModule(),
|
||||||
.buildContext();
|
new ExecutorServiceModule(sameThreadExecutor(),
|
||||||
|
sameThreadExecutor())).buildContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ import org.jclouds.lifecycle.Closer;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
import org.jclouds.rest.AsyncClientFactory;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
import org.jclouds.rest.RestContextBuilder;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
@ -59,11 +61,13 @@ public class VCloudVersionsLiveTest {
|
||||||
|
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
private static final class VCloudVersionsRestClientModule extends AbstractModule {
|
private static final class VCloudVersionsRestClientModule extends
|
||||||
|
AbstractModule {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
|
protected VCloudVersionsAsyncClient provideVCloudVersions(
|
||||||
|
AsyncClientFactory factory) {
|
||||||
return factory.create(VCloudVersionsAsyncClient.class);
|
return factory.create(VCloudVersionsAsyncClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +90,10 @@ public class VCloudVersionsLiveTest {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient> provideContext(
|
RestContext<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient> provideContext(
|
||||||
Closer closer, VCloudVersionsAsyncClient api, @VCloud URI endPoint) {
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
return new RestContextImpl<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(closer,
|
VCloudVersionsAsyncClient api, @VCloud URI endPoint) {
|
||||||
api, api, endPoint, "");
|
return new RestContextImpl<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(
|
||||||
|
closer, http, asyncHttp, api, api, endPoint, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,8 +108,8 @@ public class VCloudVersionsLiveTest {
|
||||||
public void testGetSupportedVersions() throws Exception {
|
public void testGetSupportedVersions() throws Exception {
|
||||||
VCloudVersionsAsyncClient authentication = context.getAsyncApi();
|
VCloudVersionsAsyncClient authentication = context.getAsyncApi();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
SortedMap<String, URI> response = authentication.getSupportedVersions().get(45,
|
SortedMap<String, URI> response = authentication
|
||||||
TimeUnit.SECONDS);
|
.getSupportedVersions().get(45, TimeUnit.SECONDS);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.containsKey("0.8"));
|
assertNotNull(response.containsKey("0.8"));
|
||||||
}
|
}
|
||||||
|
@ -112,13 +117,16 @@ public class VCloudVersionsLiveTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
void setupFactory() {
|
void setupFactory() {
|
||||||
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
String endpoint = checkNotNull(System
|
||||||
"jclouds.test.endpoint");
|
.getProperty("jclouds.test.endpoint"), "jclouds.test.endpoint");
|
||||||
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
String account = checkNotNull(System.getProperty("jclouds.test.user"),
|
||||||
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
"jclouds.test.user");
|
||||||
|
String key = checkNotNull(System.getProperty("jclouds.test.key"),
|
||||||
|
"jclouds.test.key");
|
||||||
context = new RestContextBuilder<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(
|
context = new RestContextBuilder<VCloudVersionsAsyncClient, VCloudVersionsAsyncClient>(
|
||||||
"vcloud", VCloudVersionsAsyncClient.class, VCloudVersionsAsyncClient.class,
|
"vcloud", VCloudVersionsAsyncClient.class,
|
||||||
new VCloudPropertiesBuilder(URI.create(endpoint), account, key).build()) {
|
VCloudVersionsAsyncClient.class, new VCloudPropertiesBuilder(URI
|
||||||
|
.create(endpoint), account, key).build()) {
|
||||||
|
|
||||||
public void addContextModule(String providerName, List<Module> modules) {
|
public void addContextModule(String providerName, List<Module> modules) {
|
||||||
|
|
||||||
|
@ -130,8 +138,9 @@ public class VCloudVersionsLiveTest {
|
||||||
modules.add(new VCloudVersionsRestClientModule());
|
modules.add(new VCloudVersionsRestClientModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
}.withModules(new Log4JLoggingModule(),
|
}.withModules(
|
||||||
new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))
|
new Log4JLoggingModule(),
|
||||||
.buildContext();
|
new ExecutorServiceModule(sameThreadExecutor(),
|
||||||
|
sameThreadExecutor())).buildContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.vcloud.endpoints.Org;
|
import org.jclouds.vcloud.endpoints.Org;
|
||||||
|
@ -44,11 +46,13 @@ public class HostingDotComVCloudContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<HostingDotComVCloudClient, HostingDotComVCloudAsyncClient> provideContext(Closer closer,
|
RestContext<HostingDotComVCloudClient, HostingDotComVCloudAsyncClient> provideContext(
|
||||||
HostingDotComVCloudAsyncClient asynchApi, HostingDotComVCloudClient defaultApi,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Org URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
HostingDotComVCloudAsyncClient asynchApi,
|
||||||
return new RestContextImpl<HostingDotComVCloudClient, HostingDotComVCloudAsyncClient>(closer,
|
HostingDotComVCloudClient defaultApi, @Org URI endPoint,
|
||||||
asynchApi, defaultApi, endPoint, account);
|
@Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
||||||
|
return new RestContextImpl<HostingDotComVCloudClient, HostingDotComVCloudAsyncClient>(
|
||||||
|
closer, http, asyncHttp, defaultApi, asynchApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,6 +24,8 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.lifecycle.Closer;
|
import org.jclouds.lifecycle.Closer;
|
||||||
|
import org.jclouds.rest.HttpAsyncClient;
|
||||||
|
import org.jclouds.rest.HttpClient;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.vcloud.endpoints.Org;
|
import org.jclouds.vcloud.endpoints.Org;
|
||||||
|
@ -44,11 +46,13 @@ public class TerremarkVCloudContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RestContext<TerremarkVCloudClient, TerremarkVCloudAsyncClient> provideContext(Closer closer,
|
RestContext<TerremarkVCloudClient, TerremarkVCloudAsyncClient> provideContext(
|
||||||
TerremarkVCloudAsyncClient asynchApi, TerremarkVCloudClient defaultApi,
|
Closer closer, HttpClient http, HttpAsyncClient asyncHttp,
|
||||||
@Org URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
TerremarkVCloudAsyncClient asynchApi,
|
||||||
return new RestContextImpl<TerremarkVCloudClient, TerremarkVCloudAsyncClient>(closer,
|
TerremarkVCloudClient defaultApi, @Org URI endPoint,
|
||||||
asynchApi, defaultApi, endPoint, account);
|
@Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) {
|
||||||
|
return new RestContextImpl<TerremarkVCloudClient, TerremarkVCloudAsyncClient>(
|
||||||
|
closer, http, asyncHttp, defaultApi, asynchApi, endPoint, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue