Issue 95: multiple endpoints per interface

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1922 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-09-25 04:02:38 +00:00
parent 66c1b593b9
commit 58b075562f
48 changed files with 658 additions and 1031 deletions

View File

@ -62,6 +62,7 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.EntityParam;
import org.jclouds.rest.ExceptionParser;
import org.jclouds.rest.Headers;
@ -90,6 +91,7 @@ import com.google.inject.internal.Nullable;
@VirtualHost
@SkipEncoding('/')
@RequestFilters(RequestAuthorizeSignature.class)
@Endpoint(S3.class)
public interface S3BlobStore extends BlobStore<BucketMetadata, ObjectMetadata, S3Object> {
/**

View File

@ -75,8 +75,8 @@ public class RestS3ConnectionModule extends AbstractModule {
@Provides
@Singleton
protected S3BlobStore provideS3Connection(@S3 URI uri, RestClientFactory factory) {
return factory.create(uri, S3BlobStore.class);
protected S3BlobStore provideS3Connection(RestClientFactory factory) {
return factory.create(S3BlobStore.class);
}
protected void bindErrorHandlers() {

View File

@ -34,6 +34,7 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.domain.Blob;
import org.jclouds.azure.storage.blob.domain.BlobMetadata;
import org.jclouds.azure.storage.blob.domain.ContainerMetadata;
@ -57,6 +58,7 @@ import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.EntityParam;
import org.jclouds.rest.ExceptionParser;
import org.jclouds.rest.Headers;
@ -79,6 +81,7 @@ import org.jclouds.rest.XMLResponseParser;
@SkipEncoding('/')
@RequestFilters(SharedKeyAuthentication.class)
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
@Endpoint(AzureBlob.class)
public interface AzureBlobStore extends BlobStore<ContainerMetadata, BlobMetadata, Blob> {
/**

View File

@ -28,7 +28,7 @@ import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.azure.storage.blob.AzureBlob;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobStore;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
import org.jclouds.azure.storage.config.RestAzureStorageConnectionModule;
@ -62,8 +62,8 @@ public class RestAzureBlobStoreModule extends RestAzureStorageConnectionModule {
@Provides
@Singleton
protected AzureBlobStore provideAzureBlobStore(@AzureBlob URI uri, RestClientFactory factory) {
return factory.create(uri, AzureBlobStore.class);
protected AzureBlobStore provideAzureBlobStore(RestClientFactory factory) {
return factory.create(AzureBlobStore.class);
}
}

View File

@ -30,7 +30,7 @@ import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.azure.storage.blob.AzureBlob;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobContext;
import org.jclouds.azure.storage.blob.AzureBlobStore;
import org.jclouds.azure.storage.blob.domain.Blob;

View File

@ -33,6 +33,7 @@ import java.util.Collections;
import javax.ws.rs.HttpMethod;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.functions.ReturnTrueIfContainerAlreadyExists;
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
import org.jclouds.azure.storage.options.CreateOptions;
@ -63,13 +64,12 @@ import com.google.inject.Guice;
*/
@Test(groups = "unit", testName = "cloudservers.AzureBlobStoreTest")
public class AzureBlobStoreTest {
JaxrsAnnotationProcessor.Factory factory;
public void testListContainers() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("listContainers");
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/");
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
@ -84,9 +84,9 @@ public class AzureBlobStoreTest {
public void testListContainersOptions() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("listContainers", ListOptions.class);
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { maxResults(
1).marker("marker").prefix("prefix") });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { maxResults(1).marker(
"marker").prefix("prefix") });
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/");
assert httpMethod.getEndpoint().getQuery().contains("comp=list");
@ -104,9 +104,8 @@ public class AzureBlobStoreTest {
public void testCreateContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("createContainer", String.class);
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { "container" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container" });
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
@ -123,9 +122,8 @@ public class AzureBlobStoreTest {
public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("deleteContainer", String.class);
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { "container" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container" });
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
@ -142,9 +140,9 @@ public class AzureBlobStoreTest {
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("createContainer", String.class,
CreateContainerOptions.class);
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
"container", withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container",
withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
@ -164,8 +162,8 @@ public class AzureBlobStoreTest {
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("createRootContainer");
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
@ -182,8 +180,8 @@ public class AzureBlobStoreTest {
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("deleteRootContainer");
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
@ -199,9 +197,9 @@ public class AzureBlobStoreTest {
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("createRootContainer", CreateOptions.class);
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withPublicAcl()
.withMetadata(ImmutableMultimap.of("foo", "bar")) });
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container");
@ -221,9 +219,8 @@ public class AzureBlobStoreTest {
public void testListBlobs() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("listBlobs", String.class);
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { "container" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "container" });
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/container");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list");
@ -238,8 +235,8 @@ public class AzureBlobStoreTest {
public void testListRootBlobs() throws SecurityException, NoSuchMethodException {
Method method = AzureBlobStore.class.getMethod("listBlobs");
URI endpoint = URI.create("http://myaccount.blob.core.windows.net");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "myaccount.blob.core.windows.net");
assertEquals(httpMethod.getEndpoint().getPath(), "/$root");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=container&comp=list");
@ -260,7 +257,8 @@ public class AzureBlobStoreTest {
new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).toInstance(URI.create("http://blob.core.windows.net"));
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(
URI.create("http://myaccount.blob.core.windows.net"));
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
.to("myaccount");
@ -268,11 +266,9 @@ public class AzureBlobStoreTest {
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
HttpUtils.toBase64String("key".getBytes()));
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
JaxrsAnnotationProcessor.Factory.class);
processor = factory.create(AzureBlobStore.class);
}
}

View File

@ -25,7 +25,7 @@ package org.jclouds.azure.storage.blob.config;
import java.net.URI;
import org.jclouds.azure.storage.blob.AzureBlob;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.blob.AzureBlobStore;
import org.jclouds.azure.storage.blob.internal.StubAzureBlobStore;
import org.jclouds.cloud.ConfiguresCloudConnection;

View File

@ -1,4 +1,4 @@
package org.jclouds.azure.storage.blob;
package org.jclouds.azure.storage;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -1,4 +1,4 @@
package org.jclouds.azure.storage.queue;
package org.jclouds.azure.storage;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -0,0 +1,21 @@
package org.jclouds.azure.storage;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a resource of type Azure Table
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface AzureTable {
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.azure.storage.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertTrue;
import java.net.URI;
@ -30,22 +31,24 @@ import java.net.URI;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.jclouds.azure.storage.AzureBlob;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.QueryParams;
import org.jclouds.rest.RequestFilters;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.rest.config.JaxrsModule;
import org.jclouds.util.Jsr330;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.util.Jsr330;
/**
* Tests behavior of {@code JaxrsAnnotationProcessor}
@ -56,6 +59,7 @@ import org.jclouds.util.Jsr330;
public class SharedKeyAuthenticationLiveTest {
@RequestFilters(SharedKeyAuthentication.class)
@Endpoint(AzureBlob.class)
public interface IntegrationTestClient {
@GET
@ -77,13 +81,15 @@ public class SharedKeyAuthenticationLiveTest {
@BeforeClass
void setupFactory() {
final String account = System.getProperty("jclouds.test.user");
final String key = System.getProperty("jclouds.test.key");
final String account = checkNotNull(System.getProperty("jclouds.test.user"),
"jclouds.test.user");
final String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
uri = "http://" + account + ".blob.core.windows.net";
injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(URI.create(uri));
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)).to(account);
bindConstant().annotatedWith(
@ -93,7 +99,6 @@ public class SharedKeyAuthenticationLiveTest {
}, new JaxrsModule(), new Log4JLoggingModule(), new ExecutorServiceModule(
new WithinThreadExecutorService()), new JavaUrlHttpCommandExecutorServiceModule());
RestClientFactory factory = injector.getInstance(RestClientFactory.class);
uri = "http://" + account + ".blob.core.windows.net";
client = factory.create(URI.create(uri), IntegrationTestClient.class);
client = factory.create(IntegrationTestClient.class);
}
}

View File

@ -32,6 +32,7 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.azure.storage.AzureQueue;
import org.jclouds.azure.storage.domain.BoundedList;
import org.jclouds.azure.storage.filters.SharedKeyAuthentication;
import org.jclouds.azure.storage.options.CreateOptions;
@ -39,6 +40,7 @@ import org.jclouds.azure.storage.options.ListOptions;
import org.jclouds.azure.storage.queue.domain.QueueMetadata;
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
import org.jclouds.azure.storage.reference.AzureStorageHeaders;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.Headers;
import org.jclouds.rest.QueryParams;
import org.jclouds.rest.RequestFilters;
@ -67,6 +69,7 @@ import org.jclouds.rest.XMLResponseParser;
@SkipEncoding('/')
@RequestFilters(SharedKeyAuthentication.class)
@Headers(keys = AzureStorageHeaders.VERSION, values = "2009-07-17")
@Endpoint(AzureQueue.class)
public interface AzureQueueConnection {
/**

View File

@ -28,8 +28,8 @@ import java.net.URI;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.azure.storage.AzureQueue;
import org.jclouds.azure.storage.config.RestAzureStorageConnectionModule;
import org.jclouds.azure.storage.queue.AzureQueue;
import org.jclouds.azure.storage.queue.AzureQueueConnection;
import org.jclouds.azure.storage.queue.reference.AzureQueueConstants;
import org.jclouds.cloud.ConfiguresCloudConnection;
@ -57,9 +57,8 @@ public class RestAzureQueueConnectionModule extends RestAzureStorageConnectionMo
@Provides
@Singleton
protected AzureQueueConnection provideAzureStorageConnection(@AzureQueue URI uri,
RestClientFactory factory) {
return factory.create(uri, AzureQueueConnection.class);
protected AzureQueueConnection provideAzureStorageConnection(RestClientFactory factory) {
return factory.create(AzureQueueConnection.class);
}
}

View File

@ -30,7 +30,7 @@ import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.azure.storage.queue.AzureQueue;
import org.jclouds.azure.storage.AzureQueue;
import org.jclouds.azure.storage.queue.AzureQueueConnection;
import org.jclouds.azure.storage.queue.AzureQueueContext;
import org.jclouds.azure.storage.reference.AzureStorageConstants;

View File

@ -33,6 +33,7 @@ import java.util.Collections;
import javax.ws.rs.HttpMethod;
import org.jclouds.azure.storage.AzureQueue;
import org.jclouds.azure.storage.options.CreateOptions;
import org.jclouds.azure.storage.options.ListOptions;
import org.jclouds.azure.storage.reference.AzureStorageConstants;
@ -60,9 +61,7 @@ import com.google.inject.Guice;
*/
@Test(groups = "unit", testName = "cloudservers.AzureQueueConnectionTest")
public class AzureQueueConnectionTest {
JaxrsAnnotationProcessor.Factory factory;
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}
.getClass();
private static final Class<? extends CreateOptions[]> createOptionsVarargsClass = new CreateOptions[] {}
@ -70,8 +69,8 @@ public class AzureQueueConnectionTest {
public void testListQueues() throws SecurityException, NoSuchMethodException {
Method method = AzureQueueConnection.class.getMethod("listQueues", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/");
assertEquals(httpMethod.getEndpoint().getQuery(), "comp=list");
@ -86,9 +85,9 @@ public class AzureQueueConnectionTest {
public void testListQueuesOptions() throws SecurityException, NoSuchMethodException {
Method method = AzureQueueConnection.class.getMethod("listQueues", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { maxResults(
1).marker("marker").prefix("prefix") });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { maxResults(1).marker(
"marker").prefix("prefix") });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/");
assert httpMethod.getEndpoint().getQuery().contains("comp=list");
@ -107,8 +106,8 @@ public class AzureQueueConnectionTest {
public void testCreateQueue() throws SecurityException, NoSuchMethodException {
Method method = AzureQueueConnection.class.getMethod("createQueue", String.class,
createOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "queue" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "queue" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=queue");
@ -124,8 +123,8 @@ public class AzureQueueConnectionTest {
public void testDeleteQueue() throws SecurityException, NoSuchMethodException {
Method method = AzureQueueConnection.class.getMethod("deleteQueue", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "queue" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "queue" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
assertEquals(httpMethod.getEndpoint().getQuery(), "restype=queue");
@ -141,8 +140,8 @@ public class AzureQueueConnectionTest {
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException {
Method method = AzureQueueConnection.class.getMethod("createQueue", String.class,
createOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "queue",
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "queue",
withMetadata(ImmutableMultimap.of("foo", "bar")) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/queue");
@ -166,7 +165,8 @@ public class AzureQueueConnectionTest {
new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
bind(URI.class).annotatedWith(AzureQueue.class).toInstance(
URI.create("http://localhost:8080"));
bindConstant().annotatedWith(
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT))
.to("user");
@ -174,11 +174,9 @@ public class AzureQueueConnectionTest {
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
HttpUtils.toBase64String("key".getBytes()));
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
JaxrsAnnotationProcessor.Factory.class);
processor = factory.create(AzureQueueConnection.class);
}
}

View File

@ -21,19 +21,23 @@
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles;
package org.jclouds.rest;
import org.jclouds.cloud.CloudContext;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Represents an authenticated context to Cloud Files CDN.
*
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
* @see CloudFilesCDNConnection
* @see CloudContext
* @author James Murty
* Designates that this Resource expects virtual host style requests
*
* @author Adrian Cole
*/
public interface CloudFilesCDNContext extends CloudContext<CloudFilesCDNConnection> {
}
@Target( { TYPE, METHOD })
@Retention(RUNTIME)
public @interface Endpoint {
Class<? extends Annotation> value();
}

View File

@ -40,6 +40,9 @@ import java.util.Map.Entry;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.HttpHeaders;
@ -65,14 +68,11 @@ import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import javax.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import javax.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.internal.Lists;
import javax.inject.Named;
/**
* Tests behavior of JaxrsUtil
@ -260,7 +260,9 @@ public class JaxrsAnnotationProcessor {
private HttpRequestOptionsBinder optionsBinder;
public HttpRequest createRequest(URI endpoint, Method method, Object[] args) {
public HttpRequest createRequest(Method method, Object[] args) {
URI endpoint = getEndpointFor(method);
String httpMethod = getHttpMethodOrConstantOrThrowException(method);
UriBuilder builder = addHostPrefixIfPresent(endpoint, method, args);
@ -664,4 +666,17 @@ public class JaxrsAnnotationProcessor {
}
return postParams;
}
public URI getEndpointFor(Method method) {
Endpoint endpoint;
if (method.isAnnotationPresent(Endpoint.class)) {
endpoint = method.getAnnotation(Endpoint.class);
} else if (declaring.isAnnotationPresent(Endpoint.class)) {
endpoint = declaring.getAnnotation(Endpoint.class);
} else {
throw new IllegalStateException(
"There must be an @Endpoint annotation on type or method: " + method);
}
return injector.getInstance(Key.get(URI.class, endpoint.value()));
}
}

View File

@ -24,12 +24,11 @@
package org.jclouds.rest;
import java.lang.reflect.Proxy;
import java.net.URI;
import org.jclouds.rest.RestClientProxy.RestClientProxyFactory;
import javax.inject.Inject;
import org.jclouds.rest.RestClientProxy.RestClientProxyFactory;
public class RestClientFactory {
private final RestClientProxyFactory proxyFactory;
@ -39,9 +38,9 @@ public class RestClientFactory {
}
@SuppressWarnings("unchecked")
public <T> T create(URI endPoint, Class<T> clazz) {
public <T> T create(Class<T> clazz) {
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz },
proxyFactory.create(endPoint, clazz));
proxyFactory.create(clazz));
}
}

View File

@ -30,11 +30,12 @@ package org.jclouds.rest;
*/
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.concurrent.FutureExceptionParser;
import org.jclouds.http.HttpConstants;
@ -44,14 +45,11 @@ import org.jclouds.http.TransformingHttpCommand;
import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import javax.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import javax.inject.Named;
public class RestClientProxy implements InvocationHandler {
private final JaxrsAnnotationProcessor util;
private final Class<?> declaring;
private final URI endPoint;
private final TransformingHttpCommand.Factory commandFactory;
/**
@ -65,16 +63,14 @@ public class RestClientProxy implements InvocationHandler {
protected Logger logger = Logger.NULL;
public static interface RestClientProxyFactory {
RestClientProxy create(URI endPoint, Class<?> clazz);
RestClientProxy create(Class<?> clazz);
}
@Inject
public RestClientProxy(JaxrsAnnotationProcessor.Factory utilFactory,
TransformingHttpCommand.Factory factory, @Assisted URI endPoint,
@Assisted Class<?> declaring) {
TransformingHttpCommand.Factory factory, @Assisted Class<?> declaring) {
this.util = utilFactory.create(declaring);
this.declaring = declaring;
this.endPoint = endPoint;
this.commandFactory = factory;
}
@ -87,7 +83,7 @@ public class RestClientProxy implements InvocationHandler {
} else if (util.getDelegateOrNull(method) != null) {
method = util.getDelegateOrNull(method);
logger.trace("%s - converting method to request", method);
HttpRequest request = util.createRequest(endPoint, method, args);
HttpRequest request = util.createRequest(method, args);
logger.trace("%s - converted method to request %s", method, request);
Function<HttpResponse, ?> transformer = util.createResponseParser(method);

View File

@ -38,6 +38,7 @@ import org.jclouds.cloud.CloudContextBuilder;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.rest.JaxrsAnnotationProcessorTest.Localhost;
import org.jclouds.rest.config.JaxrsModule;
import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils;
@ -145,13 +146,14 @@ public abstract class BaseJettyTest {
@Override
protected void configure() {
Jsr330.bindProperties(binder(), properties);
bind(URI.class).annotatedWith(Localhost.class).toInstance(
URI.create("http://localhost:" + testPort));
}
}, new JDKLoggingModule(), new JaxrsModule(), createClientModule());
CloudContextBuilder.addExecutorServiceIfNotPresent(modules);
injector = Guice.createInjector(modules);
RestClientFactory factory = injector.getInstance(RestClientFactory.class);
client = factory.create(URI.create("http://localhost:" + testPort),
IntegrationTestClient.class);
client = factory.create(IntegrationTestClient.class);
closer = injector.getInstance(Closer.class);
assert client != null;
}

View File

@ -36,12 +36,14 @@ import javax.ws.rs.PathParam;
import org.jclouds.http.binders.JsonBinder;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.EntityParam;
import org.jclouds.rest.ExceptionParser;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.MapEntityParam;
import org.jclouds.rest.RequestFilters;
import org.jclouds.rest.XMLResponseParser;
import org.jclouds.rest.JaxrsAnnotationProcessorTest.Localhost;
import com.google.common.base.Function;
@ -50,6 +52,7 @@ import com.google.common.base.Function;
*
* @author Adrian Cole
*/
@Endpoint(Localhost.class)
public interface IntegrationTestClient {
@HEAD

View File

@ -40,6 +40,7 @@ import java.util.Map;
import java.util.concurrent.Future;
import javax.inject.Named;
import javax.inject.Qualifier;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.HttpMethod;
@ -63,6 +64,7 @@ import org.jclouds.http.options.GetOptions;
import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.rest.config.JaxrsModule;
import org.jclouds.util.DateService;
import org.jclouds.util.Jsr330;
import org.joda.time.DateTime;
import org.mortbay.jetty.HttpHeaders;
import org.testng.annotations.BeforeClass;
@ -74,7 +76,6 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import org.jclouds.util.Jsr330;
/**
* Tests behavior of {@code JaxrsAnnotationProcessor}
@ -83,14 +84,26 @@ import org.jclouds.util.Jsr330;
*/
@Test(groups = "unit", testName = "jaxrs.JaxrsUtilTest")
public class JaxrsAnnotationProcessorTest {
@Target( { ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@javax.ws.rs.HttpMethod("FOO")
public @interface FOO {
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Localhost {
}
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Localhost2 {
}
@QueryParams(keys = "x-ms-version", values = "2009-07-17")
@Endpoint(Localhost.class)
public class TestQuery {
@FOO
@QueryParams(keys = "x-ms-rubbish", values = "bin")
@ -105,8 +118,7 @@ public class JaxrsAnnotationProcessorTest {
public void testQuery() throws SecurityException, NoSuchMethodException {
Method method = TestQuery.class.getMethod("foo");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(method,
new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
@ -116,8 +128,7 @@ public class JaxrsAnnotationProcessorTest {
public void testQuery2() throws SecurityException, NoSuchMethodException {
Method method = TestQuery.class.getMethod("foo2");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestQuery.class).createRequest(method,
new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
@ -126,6 +137,7 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(httpMethod.getMethod(), "FOO");
}
@Endpoint(Localhost.class)
public class TestCustomMethod {
@FOO
public void foo() {
@ -134,9 +146,8 @@ public class JaxrsAnnotationProcessorTest {
public void testCustomMethod() throws SecurityException, NoSuchMethodException {
Method method = TestCustomMethod.class.getMethod("foo");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestCustomMethod.class).createRequest(endpoint,
method, new Object[] {});
HttpRequest httpMethod = factory.create(TestCustomMethod.class).createRequest(method,
new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "FOO");
@ -146,23 +157,42 @@ public class JaxrsAnnotationProcessorTest {
public void foo();
}
@Endpoint(Localhost.class)
public class TestOverridden implements Parent {
@POST
public void foo() {
}
}
public void testOverriddenMethod() throws SecurityException, NoSuchMethodException {
Method method = TestOverridden.class.getMethod("foo");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestOverridden.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestOverridden.class).createRequest(method,
new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "POST");
}
@Endpoint(Localhost.class)
public class TestOverriddenEndpoint implements Parent {
@POST
@Endpoint(Localhost2.class)
public void foo() {
}
}
public void testOverriddenEndpointMethod() throws SecurityException, NoSuchMethodException {
Method method = TestOverriddenEndpoint.class.getMethod("foo");
HttpRequest httpMethod = factory.create(TestOverriddenEndpoint.class).createRequest(method,
new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPort(), 8081);
assertEquals(httpMethod.getEndpoint().getPath(), "");
assertEquals(httpMethod.getMethod(), "POST");
}
@Endpoint(Localhost.class)
public class TestPost {
@POST
public void post(@EntityParam String content) {
@ -183,13 +213,11 @@ public class JaxrsAnnotationProcessorTest {
@MapBinder(JsonBinder.class)
public void postWithMethodBinder(@PathParam("foo") @MapEntityParam("fooble") String path) {
}
}
public void testCreatePostRequest() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("post", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
new Object[] { "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
@ -204,8 +232,7 @@ public class JaxrsAnnotationProcessorTest {
public void testCreatePostJsonRequest() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("postAsJson", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
new Object[] { "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "");
@ -220,10 +247,8 @@ public class JaxrsAnnotationProcessorTest {
public void testCreatePostWithPathRequest() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("postWithPath", String.class, MapEntityBinder.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
new Object[] { "data", new MapEntityBinder() {
public void addEntityToRequest(Map<String, String> postParams, HttpRequest request) {
request.setEntity(postParams.get("fooble"));
}
@ -231,7 +256,6 @@ public class JaxrsAnnotationProcessorTest {
public void addEntityToRequest(Object toBind, HttpRequest request) {
throw new RuntimeException("this shouldn't be used in POST");
}
} });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
@ -242,8 +266,7 @@ public class JaxrsAnnotationProcessorTest {
public void testCreatePostWithMethodBinder() throws SecurityException, NoSuchMethodException {
Method method = TestPost.class.getMethod("postWithMethodBinder", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestPost.class).createRequest(method,
new Object[] { "data", });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
@ -257,20 +280,18 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(httpMethod.getEntity(), expected);
}
@Endpoint(Localhost.class)
public class TestPut {
@PUT
@Path("{foo}")
@MapBinder(JsonBinder.class)
public void putWithMethodBinder(@PathParam("foo") @MapEntityParam("fooble") String path) {
}
}
public void testCreatePutWithMethodBinder() throws SecurityException, NoSuchMethodException {
Method method = TestPut.class.getMethod("putWithMethodBinder", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestPut.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestPut.class).createRequest(method,
new Object[] { "data", });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/data");
@ -285,57 +306,49 @@ public class JaxrsAnnotationProcessorTest {
}
static class TestRequestFilter1 implements HttpRequestFilter {
public HttpRequest filter(HttpRequest request) throws HttpException {
return null;
}
}
static class TestRequestFilter2 implements HttpRequestFilter {
public HttpRequest filter(HttpRequest request) throws HttpException {
return null;
}
}
@RequestFilters(TestRequestFilter1.class)
@Endpoint(Localhost.class)
static class TestRequestFilter {
@GET
@RequestFilters(TestRequestFilter2.class)
public void get() {
}
}
@Test
public void testRequestFilter() throws SecurityException, NoSuchMethodException {
Method method = TestRequestFilter.class.getMethod("get");
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequestFilter.class).createRequest(endpoint,
method, new Object[] {});
HttpRequest httpMethod = factory.create(TestRequestFilter.class).createRequest(method,
new Object[] {});
assertEquals(httpMethod.getFilters().size(), 2);
assertEquals(httpMethod.getFilters().get(0).getClass(), TestRequestFilter1.class);
assertEquals(httpMethod.getFilters().get(1).getClass(), TestRequestFilter2.class);
}
@SkipEncoding('/')
@Endpoint(Localhost.class)
public class TestEncoding {
@GET
@Path("{path1}/{path2}")
public void twoPaths(@PathParam("path1") String path, @PathParam("path2") String path2) {
}
}
@Test
public void testSkipEncoding() throws SecurityException, NoSuchMethodException {
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(method,
new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getPath(), "/1/localhost");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
@ -345,8 +358,7 @@ public class JaxrsAnnotationProcessorTest {
@Test
public void testEncodingPath() throws SecurityException, NoSuchMethodException {
Method method = TestEncoding.class.getMethod("twoPaths", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestEncoding.class).createRequest(method,
new Object[] { "/", "localhost" });
assertEquals(httpMethod.getEndpoint().getPath(), "///localhost");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
@ -355,8 +367,8 @@ public class JaxrsAnnotationProcessorTest {
@SkipEncoding('/')
@Path("/v1/{account}")
@Endpoint(Localhost.class)
public interface TestConstantPathParam {
@Named("testaccount")
@PathParam("account")
void setUsername();
@ -364,22 +376,20 @@ public class JaxrsAnnotationProcessorTest {
@GET
@Path("{path1}/{path2}")
public void twoPaths(@PathParam("path1") String path, @PathParam("path2") String path2);
}
@Test
public void testConstantPathParam() throws SecurityException, NoSuchMethodException {
Method method = TestConstantPathParam.class.getMethod("twoPaths", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestConstantPathParam.class).createRequest(endpoint,
method, new Object[] { "1", "localhost" });
HttpRequest httpMethod = factory.create(TestConstantPathParam.class).createRequest(method,
new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getPath(), "/v1/ralphie/1/localhost");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
}
@Endpoint(Localhost.class)
public class TestPath {
@GET
@Path("{path}")
public void onePath(@PathParam("path") String path) {
@ -404,15 +414,13 @@ public class JaxrsAnnotationProcessorTest {
}
static class FirstCharacter implements Function<Object, String> {
public String apply(Object from) {
return from.toString().substring(0, 1);
}
}
@Endpoint(Localhost.class)
public class TestHeader {
@GET
@Headers(keys = "x-amz-copy-source", values = "/{bucket}")
public void oneHeader(@PathParam("bucket") String path) {
@ -448,8 +456,8 @@ public class JaxrsAnnotationProcessorTest {
}
@Headers(keys = "x-amz-copy-source", values = "/{bucket}")
@Endpoint(Localhost.class)
public class TestClassHeader {
@GET
public void oneHeader(@PathParam("bucket") String path) {
}
@ -500,8 +508,8 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(headers.get("x-amz-copy-source"), Collections.singletonList("/eggs/robot"));
}
@Endpoint(Localhost.class)
public class TestTransformers {
@GET
public void noTransformer() {
}
@ -510,7 +518,6 @@ public class JaxrsAnnotationProcessorTest {
@ResponseParser(ReturnStringIf200.class)
public void oneTransformer() {
}
}
@SuppressWarnings("static-access")
@ -530,8 +537,8 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(transformer, ReturnStringIf200.class);
}
@Endpoint(Localhost.class)
public class TestRequest {
@GET
@VirtualHost
@Path("/{id}")
@ -597,8 +604,7 @@ public class JaxrsAnnotationProcessorTest {
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
HttpRequestOptions[] optionsHolder = new HttpRequestOptions[] {};
Method method = TestRequest.class.getMethod("get", String.class, optionsHolder.getClass());
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -614,10 +620,8 @@ public class JaxrsAnnotationProcessorTest {
NoSuchMethodException {
DateTime date = new DateTime();
GetOptions options = GetOptions.Builder.ifModifiedSince(date);
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -629,8 +633,8 @@ public class JaxrsAnnotationProcessorTest {
.singletonList(dateService.rfc822DateFormat(date)));
}
@Endpoint(Localhost.class)
public class PrefixOptions extends BaseHttpRequestOptions {
public PrefixOptions withPrefix(String prefix) {
queryParameters.put("prefix", checkNotNull(prefix, "prefix"));
return this;
@ -640,10 +644,8 @@ public class JaxrsAnnotationProcessorTest {
public void testCreateGetOptionsThatProducesQuery() throws SecurityException,
NoSuchMethodException {
PrefixOptions options = new PrefixOptions().withPrefix("1");
Method method = TestRequest.class.getMethod("get", String.class, HttpRequestOptions.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -652,13 +654,11 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost"));
}
public void testCreateGetQuery() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("getQuery", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -669,8 +669,7 @@ public class JaxrsAnnotationProcessorTest {
public void testCreateGetQueryNull() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("getQueryNull", String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -679,6 +678,7 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(httpMethod.getHeaders().size(), 0);
}
@Endpoint(Localhost.class)
public class EntityOptions extends BaseHttpRequestOptions {
@Override
public String buildStringEntity() {
@ -689,11 +689,9 @@ public class JaxrsAnnotationProcessorTest {
public void testCreateGetOptionsThatProducesEntity() throws SecurityException,
NoSuchMethodException {
EntityOptions options = new EntityOptions();
Method method = TestRequest.class.getMethod("putOptions", String.class,
HttpRequestOptions.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1", options });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -706,7 +704,6 @@ public class JaxrsAnnotationProcessorTest {
.singletonList("application/unknown"));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("foo".getBytes().length + ""));
}
@DataProvider(name = "strings")
@ -718,8 +715,7 @@ public class JaxrsAnnotationProcessorTest {
public void testCreateGetRequest(String key) throws SecurityException, NoSuchMethodException,
UnsupportedEncodingException {
Method method = TestRequest.class.getMethod("get", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { key, "localhost" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
String expectedPath = "/" + URLEncoder.encode(key, "UTF-8").replaceAll("\\+", "%20");
@ -729,13 +725,11 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost"));
}
public void testCreatePutRequest() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("put", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "111", "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -750,8 +744,7 @@ public class JaxrsAnnotationProcessorTest {
public void testCreatePutHeader() throws SecurityException, NoSuchMethodException {
Method method = TestRequest.class.getMethod("putHeader", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(endpoint, method,
HttpRequest httpMethod = factory.create(TestRequest.class).createRequest(method,
new Object[] { "1", "data" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
@ -765,34 +758,31 @@ public class JaxrsAnnotationProcessorTest {
assertEquals(httpMethod.getEntity(), "data");
}
@Endpoint(Localhost.class)
public class TestVirtualHostMethod {
@GET
@Path("/{id}")
@VirtualHost
public Future<String> get(@PathParam("id") String id, String foo) {
return null;
}
}
@Test
public void testVirtualHostMethod() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHostMethod.class.getMethod("get", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestVirtualHostMethod.class).createRequest(endpoint,
method, new Object[] { "1", "localhost" });
HttpRequest httpMethod = factory.create(TestVirtualHostMethod.class).createRequest(method,
new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost"));
}
@Endpoint(Localhost.class)
public class TestVirtualHost {
@GET
@Path("/{id}")
@VirtualHost
@ -816,37 +806,32 @@ public class JaxrsAnnotationProcessorTest {
@Test
public void testVirtualHost() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("get", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(endpoint,
method, new Object[] { "1", "localhost" });
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(method,
new Object[] { "1", "localhost" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get(HttpHeaders.HOST), Collections
.singletonList("localhost"));
}
@Test
public void testHostPrefix() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("getPrefix", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(endpoint,
method, new Object[] { "1", "holy" });
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(method,
new Object[] { "1", "holy" });
assertEquals(httpMethod.getEndpoint().getHost(), "holylocalhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
}
@Test
public void testHostPrefixDot() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(endpoint,
method, new Object[] { "1", "holy" });
HttpRequest httpMethod = factory.create(TestVirtualHost.class).createRequest(method,
new Object[] { "1", "holy" });
assertEquals(httpMethod.getEndpoint().getHost(), "holy.localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/1");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
@ -856,22 +841,17 @@ public class JaxrsAnnotationProcessorTest {
@Test(expectedExceptions = IllegalArgumentException.class)
public void testHostPrefixDotEmpty() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
URI endpoint = URI.create("http://localhost");
factory.create(TestVirtualHost.class).createRequest(endpoint, method,
new Object[] { "1", "" });
factory.create(TestVirtualHost.class).createRequest(method, new Object[] { "1", "" });
}
@Test(expectedExceptions = NullPointerException.class)
public void testHostPrefixDotNull() throws SecurityException, NoSuchMethodException {
Method method = TestVirtualHost.class.getMethod("getPrefixDot", String.class, String.class);
URI endpoint = URI.create("http://localhost");
factory.create(TestVirtualHost.class).createRequest(endpoint, method,
new Object[] { "1", null });
factory.create(TestVirtualHost.class).createRequest(method, new Object[] { "1", null });
}
@Endpoint(Localhost.class)
public class TestHeaders {
@GET
public void oneHeader(@HeaderParam("header") String header) {
}
@ -931,6 +911,7 @@ public class JaxrsAnnotationProcessorTest {
assert values.contains("egg");
}
@Endpoint(Localhost.class)
public class TestEntity {
@PUT
public void put(@EntityParam String content) {
@ -944,7 +925,6 @@ public class JaxrsAnnotationProcessorTest {
@PUT
public void twoEntities(@EntityParam String entity1, @EntityParam String entity2) {
}
}
@Test
@ -964,7 +944,6 @@ public class JaxrsAnnotationProcessorTest {
public void putWithPath() throws SecurityException, NoSuchMethodException {
Method method = TestEntity.class.getMethod("putWithPath", String.class, String.class);
HttpRequest request = new HttpRequest(HttpMethod.PUT, URI.create("http://localhost:8080"));
factory.create(TestEntity.class).buildEntityIfPostOrPutRequest(method,
new Object[] { "rabble", "test" }, request);
assertEquals(request.getEntity(), "test");
@ -987,13 +966,17 @@ public class JaxrsAnnotationProcessorTest {
@BeforeClass
void setupFactory() {
factory = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named("testaccount")).to("ralphie");
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
factory = Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named("testaccount")).to("ralphie");
bind(URI.class).annotatedWith(Localhost.class).toInstance(
URI.create("http://localhost:8080"));
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
URI.create("http://localhost:8081"));
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
JaxrsAnnotationProcessor.Factory.class);
}

View File

@ -30,6 +30,7 @@ import java.util.concurrent.Future;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@ -41,23 +42,34 @@ import org.jclouds.blobstore.binders.UserMetadataBinder;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.functions.BlobKey;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.http.options.GetOptions;
import org.jclouds.rackspace.CloudFiles;
import org.jclouds.rackspace.CloudFilesCDN;
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import org.jclouds.rackspace.cloudfiles.functions.ParseAccountMetadataResponseFromHeaders;
import org.jclouds.rackspace.cloudfiles.functions.ParseBlobMetadataListFromJsonResponse;
import org.jclouds.rackspace.cloudfiles.functions.ParseCdnUriFromHeaders;
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataListFromGsonResponse;
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerListFromJsonResponse;
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectFromHeadersAndHttpContent;
import org.jclouds.rackspace.cloudfiles.functions.ParseObjectMetadataFromHeaders;
import org.jclouds.rackspace.cloudfiles.functions.ReturnTrueOn404FalseOn409;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
import org.jclouds.rackspace.filters.AuthenticateRequest;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.EntityParam;
import org.jclouds.rest.ExceptionParser;
import org.jclouds.rest.Headers;
import org.jclouds.rest.ParamParser;
import org.jclouds.rest.QueryParams;
import org.jclouds.rest.RequestFilters;
@ -77,6 +89,7 @@ import com.google.common.collect.Multimap;
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(CloudFiles.class)
public interface CloudFilesBlobStore extends
BlobStore<ContainerMetadata, BlobMetadata, Blob<BlobMetadata>> {
@GET
@ -155,4 +168,48 @@ public interface CloudFilesBlobStore extends
@PathParam("key") String key,
@EntityParam(UserMetadataBinder.class) Multimap<String, String> userMetadata);
// / cdn functionality below
@GET
@ResponseParser(ParseContainerCDNMetadataListFromGsonResponse.class)
@QueryParams(keys = "format", values = "json")
@Path("/")
@Endpoint(CloudFilesCDN.class)
List<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options);
// TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it
// here.
@HEAD
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
@ExceptionParser(ThrowContainerNotFoundOn404.class)
@Path("{container}")
@Endpoint(CloudFilesCDN.class)
ContainerCDNMetadata getCDNMetadata(@PathParam("container") String container);
@PUT
@Path("{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CloudFilesCDN.class)
String enableCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
@PUT
@Path("{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CloudFilesCDN.class)
String enableCDN(@PathParam("container") String container);
@POST
@Path("{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
@Endpoint(CloudFilesCDN.class)
String updateCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
@POST
@Path("{container}")
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "False")
@Endpoint(CloudFilesCDN.class)
boolean disableCDN(@PathParam("container") String container);
}

View File

@ -1,97 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.HEAD;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.functions.ParseCdnUriFromHeaders;
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
import org.jclouds.rackspace.cloudfiles.functions.ParseContainerCDNMetadataListFromGsonResponse;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
import org.jclouds.rackspace.filters.AuthenticateRequest;
import org.jclouds.rest.ExceptionParser;
import org.jclouds.rest.Headers;
import org.jclouds.rest.QueryParams;
import org.jclouds.rest.RequestFilters;
import org.jclouds.rest.ResponseParser;
import org.jclouds.rest.SkipEncoding;
/**
* Provides access to the Cloud Files service's CDN offering via their REST API.
*
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090311.pdf" />
* @author James Murty
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
public interface CloudFilesCDNConnection {
@GET
@ResponseParser(ParseContainerCDNMetadataListFromGsonResponse.class)
@QueryParams(keys = "format", values = "json")
@Path("/")
List<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options);
// TODO: Container name is not included in CDN HEAD response headers, so we cannot populate it
// here.
@HEAD
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
@ExceptionParser(ThrowContainerNotFoundOn404.class)
@Path("{container}")
ContainerCDNMetadata getCDNMetadata(@PathParam("container") String container);
@PUT
@Path("{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
String enableCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
@PUT
@Path("{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
String enableCDN(@PathParam("container") String container);
@POST
@Path("{container}")
@ResponseParser(ParseCdnUriFromHeaders.class)
String updateCDN(@PathParam("container") String container,
@HeaderParam(CloudFilesHeaders.CDN_TTL) Long ttl);
@POST
@Path("{container}")
@Headers(keys = CloudFilesHeaders.CDN_ENABLED, values = "False")
boolean disableCDN(@PathParam("container") String container);
}

View File

@ -1,79 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles;
import java.util.List;
import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rackspace.RackspaceContextBuilder;
import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesCDNConnectionModule;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Creates {@link CloudFilesCDNContext} or {@link Injector} instances based on the most commonly
* requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author James Murty
* @see CloudFilesCDNContext, CloudFilesCDNContextBuilder
*/
public class CloudFilesCDNContextBuilder extends RackspaceContextBuilder<CloudFilesCDNContext> {
public CloudFilesCDNContextBuilder(Properties props) {
super(props);
}
public static CloudFilesCDNContextBuilder newBuilder(String id, String secret) {
Properties properties = new Properties();
CloudFilesCDNContextBuilder builder = new CloudFilesCDNContextBuilder(properties);
builder.authenticate(id, secret);
return builder;
}
@Override
public void addApiModule(List<Module> modules) {
super.addApiModule(modules);
modules.add(new RestCloudFilesCDNConnectionModule());
}
@Override
protected void addContextModule(List<Module> modules) {
// TODO
}
@Override
public CloudFilesCDNContext buildContext() {
return buildInjector().getInstance(CloudFilesCDNContext.class);
}
}

View File

@ -1,34 +0,0 @@
package org.jclouds.rackspace.cloudfiles;
import java.net.URI;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import com.google.inject.Module;
/**
* Creates {@link CloudFilesCDNContext} instances based on the most commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole, Andrew Newdigate
* @see CloudFilesCDNContext
*/
public class CloudFilesCDNContextFactory {
public static CloudFilesCDNContext createCloudFilesCDNContext(String user, String key,
Module... modules) {
return CloudFilesCDNContextBuilder.newBuilder(user, key).withModules(modules).buildContext();
}
public static CloudFilesCDNContext createCloudFilesCDNContext(URI endpoint, String user,
String key, Module... modules) {
return CloudFilesCDNContextBuilder.newBuilder(user, key).withEndpoint(endpoint).withModules(
modules).buildContext();
}
}

View File

@ -23,17 +23,15 @@
*/
package org.jclouds.rackspace.cloudfiles.config;
import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.cloud.ConfiguresCloudConnection;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rackspace.Storage;
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import javax.inject.Singleton;
/**
* Configures the Cloud Files connection, including logging and http transport.
@ -50,9 +48,8 @@ public class RestCloudFilesBlobStoreModule extends AbstractModule {
@Provides
@Singleton
protected CloudFilesBlobStore provideConnection(@Storage URI authenticationUri,
RestClientFactory factory) {
return factory.create(authenticationUri, CloudFilesBlobStore.class);
protected CloudFilesBlobStore provideConnection(RestClientFactory factory) {
return factory.create(CloudFilesBlobStore.class);
}
}

View File

@ -1,63 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles.config;
import java.net.URI;
import org.jclouds.cloud.ConfiguresCloudConnection;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rackspace.CDN;
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNConnection;
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNContext;
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesCDNContext;
import org.jclouds.rest.RestClientFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import javax.inject.Singleton;
/**
* Configures the Cloud Files CDN connection, including logging and http transport.
* This class supplies the CDN-specific URI required for the CDN operations in the
* Cloud Files service.
*
* @author James Murty
*/
@ConfiguresCloudConnection
@RequiresHttp
public class RestCloudFilesCDNConnectionModule extends AbstractModule {
@Override
protected void configure() {
bind(CloudFilesCDNContext.class).to(GuiceCloudFilesCDNContext.class);
}
@Provides
@Singleton
protected CloudFilesCDNConnection provideCDNConnection(@CDN URI cdnUri,
RestClientFactory factory) {
return factory.create(cdnUri, CloudFilesCDNConnection.class);
}
}

View File

@ -1,92 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles.internal;
import java.io.IOException;
import java.net.URI;
import javax.annotation.Resource;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.Logger;
import org.jclouds.rackspace.Authentication;
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNConnection;
import org.jclouds.rackspace.cloudfiles.CloudFilesCDNContext;
import org.jclouds.rackspace.reference.RackspaceConstants;
import javax.inject.Inject;
import com.google.inject.Injector;
import javax.inject.Named;
/**
* Uses a Guice Injector to configure the objects served by CloudFilesCDNContext methods.
*
* @author Adrian Cole
* @see Injector
*/
public class GuiceCloudFilesCDNContext implements CloudFilesCDNContext {
@Resource
private Logger logger = Logger.NULL;
private final Injector injector;
private final Closer closer;
private final URI endPoint;
private final String account;
@Inject
private GuiceCloudFilesCDNContext(Injector injector, Closer closer,
@Authentication URI endPoint,
@Named(RackspaceConstants.PROPERTY_RACKSPACE_USER) String account) {
this.injector = injector;
this.closer = closer;
this.endPoint = endPoint;
this.account = account;
}
/**
* {@inheritDoc}
*
* @see Closer
*/
public void close() {
try {
closer.close();
} catch (IOException e) {
logger.error(e, "error closing content");
}
}
public String getAccount() {
return account;
}
public CloudFilesCDNConnection getApi() {
return injector.getInstance(CloudFilesCDNConnection.class);
}
public URI getEndPoint() {
return endPoint;
}
}

View File

@ -34,6 +34,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
@ -42,11 +43,14 @@ import org.jclouds.http.HttpUtils;
import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
@ -70,6 +74,99 @@ public class CloudFilesBlobStoreLiveTest {
new Log4JLoggingModule()).getApi();
}
@Test
public void testCDNOperations() throws Exception {
final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour
// Create two new containers for testing
final String containerNameWithCDN = bucketPrefix + ".testCDNOperationsContainerWithCDN";
final String containerNameWithoutCDN = bucketPrefix + ".testCDNOperationsContainerWithoutCDN";
assertTrue(connection.createContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
assertTrue(connection.createContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
ContainerCDNMetadata cdnMetadata = null;
// Enable CDN with PUT for one container
final String cdnUri = connection.enableCDN(containerNameWithCDN);
assertTrue(cdnUri != null);
assertTrue(cdnUri.startsWith("http://"));
// Confirm CDN is enabled via HEAD request and has default TTL
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCdnEnabled());
assertEquals(cdnMetadata.getCdnUri(), cdnUri);
final long initialTTL = cdnMetadata.getTtl();
try {
cdnMetadata = connection.getCDNMetadata(containerNameWithoutCDN);
assert false : "should not exist";
} catch (ContainerNotFoundException e) {
}
try {
cdnMetadata = connection.getCDNMetadata("DoesNotExist");
assert false : "should not exist";
} catch (ContainerNotFoundException e) {
}
// List CDN metadata for containers, and ensure all CDN info is available for enabled
// container
List<ContainerCDNMetadata> cdnMetadataList = connection.listCDNContainers();
assertTrue(cdnMetadataList.size() >= 1);
assertTrue(Iterables.any(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return (cdnMetadata.getName().equals(containerNameWithCDN)
&& cdnMetadata.isCdnEnabled() && cdnMetadata.getTtl() == initialTTL && cdnMetadata
.getCdnUri().equals(cdnUri));
}
}));
// Test listing with options
cdnMetadataList = connection.listCDNContainers(ListCdnContainerOptions.Builder.enabledOnly());
assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return cdnMetadata.isCdnEnabled();
}
}));
cdnMetadataList = connection.listCDNContainers(ListCdnContainerOptions.Builder.afterMarker(
containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1)).maxResults(1));
assertEquals(cdnMetadataList.size(), 1);
assertEquals(cdnMetadataList.get(0).getName(), containerNameWithCDN);
// Enable CDN with PUT for the same container, this time with a custom TTL
long ttl = 4000;
connection.enableCDN(containerNameWithCDN, ttl);
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCdnEnabled());
assertEquals(cdnMetadata.getTtl(), ttl);
// Check POST by updating TTL settings
ttl = minimumTTL;
connection.updateCDN(containerNameWithCDN, minimumTTL);
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCdnEnabled());
assertEquals(cdnMetadata.getTtl(), minimumTTL);
// Confirm that minimum allowed value for TTL is 3600, lower values are ignored.
connection.updateCDN(containerNameWithCDN, 3599L);
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.getTtl(), minimumTTL); // Note that TTL is 3600 here, not 3599
// Disable CDN with POST
assertTrue(connection.disableCDN(containerNameWithCDN));
cdnMetadata = connection.getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.isCdnEnabled(), false);
// Delete test containers
assertTrue(connection.deleteContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
assertTrue(connection.deleteContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
}
@Test
public void testListOwnedContainers() throws Exception {
List<ContainerMetadata> response = connection.listContainers();

View File

@ -1,159 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Tests behavior of {@code JaxrsAnnotationProcessor} for Cloud Files CDN service.
*
* @author James Murty
*/
@Test(groups = "live", testName = "cloudfiles.CloudFilesAuthenticationLiveTest")
public class CloudFilesCDNConnectionLiveTest {
private String bucketPrefix = System.getProperty("user.name") + "-cfcdnint";
CloudFilesCDNConnection cdnConnection;
CloudFilesBlobStore filesConnection;
@BeforeGroups(groups = { "live" })
public void setupConnection() {
String account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key");
cdnConnection = CloudFilesCDNContextFactory.createCloudFilesCDNContext(account, key,
new Log4JLoggingModule()).getApi();
filesConnection = CloudFilesContextFactory.createCloudFilesContext(account, key,
new Log4JLoggingModule()).getApi();
}
@Test
public void testCDNOperations() throws Exception {
final long minimumTTL = 60 * 60; // The minimum TTL is 1 hour
// Create two new containers for testing
final String containerNameWithCDN = bucketPrefix + ".testCDNOperationsContainerWithCDN";
final String containerNameWithoutCDN = bucketPrefix + ".testCDNOperationsContainerWithoutCDN";
assertTrue(filesConnection.createContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
assertTrue(filesConnection.createContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
ContainerCDNMetadata cdnMetadata = null;
// Enable CDN with PUT for one container
final String cdnUri = cdnConnection.enableCDN(containerNameWithCDN);
assertTrue(cdnUri != null);
assertTrue(cdnUri.startsWith("http://"));
// Confirm CDN is enabled via HEAD request and has default TTL
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCdnEnabled());
assertEquals(cdnMetadata.getCdnUri(), cdnUri);
final long initialTTL = cdnMetadata.getTtl();
try {
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithoutCDN);
assert false : "should not exist";
} catch (ContainerNotFoundException e) {
}
try {
cdnMetadata = cdnConnection.getCDNMetadata("DoesNotExist");
assert false : "should not exist";
} catch (ContainerNotFoundException e) {
}
// List CDN metadata for containers, and ensure all CDN info is available for enabled
// container
List<ContainerCDNMetadata> cdnMetadataList = cdnConnection.listCDNContainers();
assertTrue(cdnMetadataList.size() >= 1);
assertTrue(Iterables.any(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return (cdnMetadata.getName().equals(containerNameWithCDN)
&& cdnMetadata.isCdnEnabled() && cdnMetadata.getTtl() == initialTTL && cdnMetadata
.getCdnUri().equals(cdnUri));
}
}));
// Test listing with options
cdnMetadataList = cdnConnection.listCDNContainers(ListCdnContainerOptions.Builder
.enabledOnly());
assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return cdnMetadata.isCdnEnabled();
}
}));
cdnMetadataList = cdnConnection.listCDNContainers(ListCdnContainerOptions.Builder
.afterMarker(containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1))
.maxResults(1));
assertEquals(cdnMetadataList.size(), 1);
assertEquals(cdnMetadataList.get(0).getName(), containerNameWithCDN);
// Enable CDN with PUT for the same container, this time with a custom TTL
long ttl = 4000;
cdnConnection.enableCDN(containerNameWithCDN, ttl);
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCdnEnabled());
assertEquals(cdnMetadata.getTtl(), ttl);
// Check POST by updating TTL settings
ttl = minimumTTL;
cdnConnection.updateCDN(containerNameWithCDN, minimumTTL);
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
assertTrue(cdnMetadata.isCdnEnabled());
assertEquals(cdnMetadata.getTtl(), minimumTTL);
// Confirm that minimum allowed value for TTL is 3600, lower values are ignored.
cdnConnection.updateCDN(containerNameWithCDN, 3599L);
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.getTtl(), minimumTTL); // Note that TTL is 3600 here, not 3599
// Disable CDN with POST
assertTrue(cdnConnection.disableCDN(containerNameWithCDN));
cdnMetadata = cdnConnection.getCDNMetadata(containerNameWithCDN);
assertEquals(cdnMetadata.isCdnEnabled(), false);
// Delete test containers
assertTrue(filesConnection.deleteContainer(containerNameWithCDN).get(10, TimeUnit.SECONDS));
assertTrue(filesConnection.deleteContainer(containerNameWithoutCDN).get(10, TimeUnit.SECONDS));
}
}

View File

@ -1,89 +0,0 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudfiles;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.jclouds.cloud.CloudContext;
import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesCDNConnectionModule;
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesCDNContext;
import org.jclouds.rackspace.config.RestRackspaceAuthenticationModule;
import org.jclouds.rackspace.reference.RackspaceConstants;
import org.testng.annotations.Test;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Tests behavior of modules configured in CloudFilesCDNContextBuilder
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudfiles.CloudFilesCDNContextBuilderTest")
public class CloudFilesCDNContextBuilderTest {
public void testNewBuilder() {
CloudFilesCDNContextBuilder builder = CloudFilesCDNContextBuilder.newBuilder("id", "secret");
assertEquals(builder.getProperties().getProperty(
RackspaceConstants.PROPERTY_RACKSPACE_ENDPOINT), "https://api.mosso.com");
assertEquals(builder.getProperties().getProperty(RackspaceConstants.PROPERTY_RACKSPACE_USER),
"id");
assertEquals(builder.getProperties().getProperty(RackspaceConstants.PROPERTY_RACKSPACE_KEY),
"secret");
}
public void testBuildContext() {
CloudContext<CloudFilesCDNConnection> context = CloudFilesCDNContextBuilder.newBuilder("id",
"secret").buildContext();
assertEquals(context.getClass(), GuiceCloudFilesCDNContext.class);
assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("https://api.mosso.com"));
}
public void testBuildInjector() {
Injector i = CloudFilesCDNContextBuilder.newBuilder("id", "secret").buildInjector();
assert i.getInstance(CloudFilesCDNContext.class) != null;
}
protected void testAddContextModule() {
List<Module> modules = new ArrayList<Module>();
CloudFilesCDNContextBuilder builder = CloudFilesCDNContextBuilder.newBuilder("id", "secret");
builder.addContextModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), RestRackspaceAuthenticationModule.class);
}
protected void addConnectionModule() {
List<Module> modules = new ArrayList<Module>();
CloudFilesCDNContextBuilder builder = CloudFilesCDNContextBuilder.newBuilder("id", "secret");
builder.addApiModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), RestCloudFilesCDNConnectionModule.class);
}
}

View File

@ -32,7 +32,9 @@ import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.integration.internal.StubBlobStore;
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
import com.google.common.collect.Multimap;
@ -85,4 +87,28 @@ public class StubCloudFilesBlobStore extends
return false;
}
public boolean disableCDN(String container) {
return false;
}
public String enableCDN(String container, Long ttl) {
return null;
}
public String enableCDN(String container) {
return null;
}
public ContainerCDNMetadata getCDNMetadata(String container) {
return null;
}
public List<ContainerCDNMetadata> listCDNContainers(ListCdnContainerOptions... options) {
return null;
}
public String updateCDN(String container, Long ttl) {
return null;
}
}

View File

@ -36,6 +36,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.rackspace.CloudServers;
import org.jclouds.rackspace.cloudservers.binders.BackupScheduleBinder;
import org.jclouds.rackspace.cloudservers.binders.ChangeAdminPassBinder;
import org.jclouds.rackspace.cloudservers.binders.ChangeServerNameBinder;
@ -73,6 +74,7 @@ import org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions;
import org.jclouds.rackspace.cloudservers.options.ListOptions;
import org.jclouds.rackspace.cloudservers.options.RebuildServerOptions;
import org.jclouds.rackspace.filters.AuthenticateRequest;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.EntityParam;
import org.jclouds.rest.ExceptionParser;
import org.jclouds.rest.MapBinder;
@ -94,6 +96,7 @@ import org.jclouds.rest.SkipEncoding;
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(CloudServers.class)
public interface CloudServersConnection {
/**

View File

@ -23,11 +23,10 @@
*/
package org.jclouds.rackspace.cloudservers.config;
import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.cloud.ConfiguresCloudConnection;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rackspace.Server;
import org.jclouds.rackspace.cloudservers.CloudServersConnection;
import org.jclouds.rackspace.cloudservers.CloudServersContext;
import org.jclouds.rackspace.cloudservers.internal.GuiceCloudServersContext;
@ -35,7 +34,6 @@ import org.jclouds.rest.RestClientFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import javax.inject.Singleton;
/**
* Configures the Cloud Servers connection, including logging and http transport.
@ -53,9 +51,8 @@ public class RestCloudServersConnectionModule extends AbstractModule {
@Provides
@Singleton
protected CloudServersConnection provideConnection(@Server URI authenticationUri,
RestClientFactory factory) {
return factory.create(authenticationUri, CloudServersConnection.class);
protected CloudServersConnection provideConnection(RestClientFactory factory) {
return factory.create(CloudServersConnection.class);
}
}

View File

@ -46,9 +46,9 @@ public class Server {
private Integer flavorId;
private String hostId;
private Integer imageId;
private Integer sharedIpGroupId;
private Integer progress;
private Integer sharedIpGroupId;
private ServerStatus status;
public Server() {
@ -163,9 +163,7 @@ public class Server {
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((progress == null) ? 0 : progress.hashCode());
result = prime * result + ((sharedIpGroupId == null) ? 0 : sharedIpGroupId.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@ -215,21 +213,11 @@ public class Server {
return false;
} else if (!getName().equals(other.getName()))
return false;
if (progress == null) {
if (other.progress != null)
return false;
} else if (!progress.equals(other.progress))
return false;
if (sharedIpGroupId == null) {
if (other.sharedIpGroupId != null)
return false;
} else if (!sharedIpGroupId.equals(other.sharedIpGroupId))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
return true;
}

View File

@ -44,7 +44,7 @@ public class CreateSharedIpGroupOptions extends JsonBinder {
Integer serverId;
@SuppressWarnings("unused")
private class SharedIpGroupRequest {
private static class SharedIpGroupRequest {
final String name;
Integer server;

View File

@ -68,7 +68,8 @@ import com.google.inject.Injector;
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "cloudservers.CloudServersConnectionLiveTest")
// disabled [Web Hosting #129069
@Test(groups = "live", enabled = false, sequential = true, testName = "cloudservers.CloudServersConnectionLiveTest")
public class CloudServersConnectionLiveTest {
protected CloudServersConnection connection;
@ -475,7 +476,8 @@ public class CloudServersConnectionLiveTest {
}
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateServerIp")
// [Web Hosting #129069
@Test(enabled = false, timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp")
public void testUnshare() throws Exception {
connection.unshareIp(ip, serverId2);
blockUntilServerActive(serverId2);
@ -496,7 +498,8 @@ public class CloudServersConnectionLiveTest {
}
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testUnshare")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateServerIp")
// "testUnshare")
public void testShareConfig() throws Exception {
connection.shareIp(ip, serverId2, sharedIpGroupId, true);
blockUntilServerActive(serverId2);
@ -506,7 +509,7 @@ public class CloudServersConnectionLiveTest {
testUnshare();
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testShareConfig")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareConfig")
public void testShareNoConfig() throws Exception {
connection.shareIp(ip, serverId2, sharedIpGroupId, false);
blockUntilServerActive(serverId2);
@ -516,7 +519,7 @@ public class CloudServersConnectionLiveTest {
testUnshare();
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testShareNoConfig")
public void testBackup() throws Exception {
assertEquals(new BackupSchedule(), connection.listBackupSchedule(serverId));
BackupSchedule dailyWeekly = new BackupSchedule();
@ -529,7 +532,7 @@ public class CloudServersConnectionLiveTest {
assertEquals(connection.listBackupSchedule(serverId).isEnabled(), false);
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testBackup")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testBackup")
public void testCreateImage() throws Exception {
Image image = connection.createImageFromServer("hoofie", serverId);
assertEquals("hoofie", image.getName());
@ -538,7 +541,7 @@ public class CloudServersConnectionLiveTest {
blockUntilImageActive(imageId);
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testCreateImage")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testCreateImage")
public void testRebuildServer() throws Exception {
assertTrue(connection.rebuildServer(serverId, withImage(imageId)));
blockUntilServerActive(serverId);
@ -546,19 +549,19 @@ public class CloudServersConnectionLiveTest {
// assertEquals(new Integer(imageId), connection.getServer(serverId).getImageId());
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebuildServer")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebuildServer")
public void testRebootHard() throws Exception {
assertTrue(connection.rebootServer(serverId, RebootType.HARD));
blockUntilServerActive(serverId);
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebootHard")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootHard")
public void testRebootSoft() throws Exception {
assertTrue(connection.rebootServer(serverId, RebootType.SOFT));
blockUntilServerActive(serverId);
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebootSoft")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
public void testRevertResize() throws Exception {
assertTrue(connection.resizeServer(serverId, 2));
blockUntilServerVerifyResize(serverId);
@ -567,7 +570,7 @@ public class CloudServersConnectionLiveTest {
assertEquals(new Integer(1), connection.getServer(serverId).getFlavorId());
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = "testRebootSoft")
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = "testRebootSoft")
public void testConfirmResize() throws Exception {
assertTrue(connection.resizeServer(serverId2, 2));
blockUntilServerVerifyResize(serverId2);
@ -577,7 +580,7 @@ public class CloudServersConnectionLiveTest {
}
// must be last!. do not rely on positional order.
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize",
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "testRebootSoft", "testRevertResize",
"testConfirmResize" })
void deleteServers() {
if (serverId > 0) {
@ -592,7 +595,7 @@ public class CloudServersConnectionLiveTest {
}
}
@Test(timeOut = 5 * 60 * 1000, dependsOnMethods = { "deleteServers" })
@Test(timeOut = 10 * 60 * 1000, dependsOnMethods = { "deleteServers" })
void testDeleteSharedIpGroup() {
if (sharedIpGroupId > 0) {
connection.deleteSharedIpGroup(sharedIpGroupId);

View File

@ -50,6 +50,7 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.rackspace.Authentication;
import org.jclouds.rackspace.CloudServers;
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
import org.jclouds.rackspace.cloudservers.domain.RebootType;
@ -91,21 +92,17 @@ import com.google.inject.Provides;
*/
@Test(groups = "unit", testName = "cloudservers.CloudServersConnectionTest")
public class CloudServersConnectionTest {
JaxrsAnnotationProcessor.Factory factory;
private static final Class<? extends ListOptions[]> listOptionsVarargsClass = new ListOptions[] {}
.getClass();
private static final Class<? extends CreateServerOptions[]> createServerOptionsVarargsClass = new CreateServerOptions[] {}
.getClass();
public void testCreateServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2, 1 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1 });
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
.getEntity());
validateCreateServer(method, httpMethod);
@ -114,9 +111,9 @@ public class CloudServersConnectionTest {
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2, 1, withSharedIpGroup(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1,
withSharedIpGroup(2) });
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
httpMethod.getEntity());
@ -126,9 +123,9 @@ public class CloudServersConnectionTest {
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2, 1, new CreateServerOptions[] { withFile("/etc/jclouds", "foo".getBytes()) } });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1,
new CreateServerOptions[] { withFile("/etc/jclouds", "foo".getBytes()) } });
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
httpMethod.getEntity());
@ -138,9 +135,9 @@ public class CloudServersConnectionTest {
public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2, 1, withMetadata(ImmutableMap.of("foo", "bar")) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1,
withMetadata(ImmutableMap.of("foo", "bar")) });
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
httpMethod.getEntity());
@ -151,8 +148,8 @@ public class CloudServersConnectionTest {
NoSuchMethodException, UnknownHostException {
Method method = CloudServersConnection.class.getMethod("createServer", String.class,
int.class, int.class, createServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
"ralphie",
2,
1,
@ -184,8 +181,8 @@ public class CloudServersConnectionTest {
public void testListServers() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listServers", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -201,9 +198,9 @@ public class CloudServersConnectionTest {
public void testListServersOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listServers", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
.maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -218,9 +215,8 @@ public class CloudServersConnectionTest {
public void testListServersDetail() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listServers", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails() });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -233,8 +229,8 @@ public class CloudServersConnectionTest {
public void testGetServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getServer", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -249,8 +245,8 @@ public class CloudServersConnectionTest {
public void testListFlavors() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -264,9 +260,9 @@ public class CloudServersConnectionTest {
public void testListFlavorsOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
.maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -281,9 +277,8 @@ public class CloudServersConnectionTest {
public void testListFlavorsDetail() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails() });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -297,9 +292,9 @@ public class CloudServersConnectionTest {
public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class
.getMethod("listFlavors", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails()
.changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -313,8 +308,8 @@ public class CloudServersConnectionTest {
public void testGetFlavor() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getFlavor", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/flavors/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -328,8 +323,8 @@ public class CloudServersConnectionTest {
public void testListImages() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -342,9 +337,8 @@ public class CloudServersConnectionTest {
public void testListImagesDetail() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails() });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -357,9 +351,9 @@ public class CloudServersConnectionTest {
public void testListImagesOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
.maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -373,9 +367,9 @@ public class CloudServersConnectionTest {
public void testListImagesDetailOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listImages", listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails()
.changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/images/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -389,8 +383,8 @@ public class CloudServersConnectionTest {
public void testGetImage() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getImage", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/images/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -404,8 +398,8 @@ public class CloudServersConnectionTest {
public void testDeleteServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("deleteServer", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
@ -419,8 +413,8 @@ public class CloudServersConnectionTest {
UnknownHostException {
Method method = CloudServersConnection.class.getMethod("shareIp", InetAddress.class,
int.class, int.class, boolean.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
@ -440,8 +434,8 @@ public class CloudServersConnectionTest {
UnknownHostException {
Method method = CloudServersConnection.class.getMethod("shareIp", InetAddress.class,
int.class, int.class, boolean.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, true });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
@ -462,8 +456,8 @@ public class CloudServersConnectionTest {
UnknownHostException {
Method method = CloudServersConnection.class.getMethod("unshareIp", InetAddress.class,
int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {
HttpRequest httpMethod = processor.createRequest(method, new Object[] {
InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }), 2, 3, false });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public/127.0.0.1");
@ -477,8 +471,8 @@ public class CloudServersConnectionTest {
public void testReplaceBackupSchedule() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("replaceBackupSchedule", int.class,
BackupSchedule.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2,
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2,
new BackupSchedule(WeeklyBackup.MONDAY, DailyBackup.H_0800_1000, true) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
@ -498,8 +492,8 @@ public class CloudServersConnectionTest {
public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("deleteBackupSchedule", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
@ -512,8 +506,8 @@ public class CloudServersConnectionTest {
public void testChangeAdminPass() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("changeAdminPass", int.class,
String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2, "foo" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, "foo" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
@ -531,8 +525,8 @@ public class CloudServersConnectionTest {
public void testChangeServerName() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("renameServer", int.class,
String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2, "foo" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, "foo" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2");
assertEquals(httpMethod.getMethod(), HttpMethod.PUT);
@ -550,8 +544,8 @@ public class CloudServersConnectionTest {
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] {});
HttpRequest httpMethod = processor.createRequest(method, new Object[] {});
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -565,9 +559,9 @@ public class CloudServersConnectionTest {
public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { changesSince(now)
.maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -582,9 +576,8 @@ public class CloudServersConnectionTest {
public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails() });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails() });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -599,9 +592,9 @@ public class CloudServersConnectionTest {
NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listSharedIpGroups",
listOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method,
new Object[] { withDetails().changesSince(now).maxResults(1).startAt(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { withDetails()
.changesSince(now).maxResults(1).startAt(2) });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/detail");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json" + "&limit=1&changes-since="
@ -615,8 +608,8 @@ public class CloudServersConnectionTest {
public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("getSharedIpGroup", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -634,9 +627,8 @@ public class CloudServersConnectionTest {
public void testCreateSharedIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
createSharedIpGroupOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor
.createRequest(endpoint, method, new Object[] { "ralphie" });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie" });
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\"}}", httpMethod.getEntity());
validateCreateSharedIpGroup(method, httpMethod);
}
@ -644,8 +636,8 @@ public class CloudServersConnectionTest {
public void testCreateSharedIpGroupWithIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createSharedIpGroup", String.class,
createSharedIpGroupOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie",
withServer(2) });
assertEquals("{\"sharedIpGroup\":{\"name\":\"ralphie\",\"server\":2}}", httpMethod
.getEntity());
@ -671,8 +663,8 @@ public class CloudServersConnectionTest {
public void testDeleteSharedIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("deleteSharedIpGroup", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/shared_ip_groups/2");
assertEquals(httpMethod.getMethod(), HttpMethod.DELETE);
@ -684,8 +676,8 @@ public class CloudServersConnectionTest {
public void testListAddresses() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listAddresses", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -697,8 +689,8 @@ public class CloudServersConnectionTest {
public void testListPublicAddresses() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listPublicAddresses", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/public");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -710,8 +702,8 @@ public class CloudServersConnectionTest {
public void testListPrivateAddresses() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listPrivateAddresses", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/ips/private");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -723,8 +715,8 @@ public class CloudServersConnectionTest {
public void testListBackupSchedule() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("listBackupSchedule", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/backup_schedule");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -737,9 +729,8 @@ public class CloudServersConnectionTest {
public void testCreateImageWithIpGroup() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("createImageFromServer", String.class,
int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { "ralphie",
2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2 });
assertEquals("{\"image\":{\"serverId\":2,\"name\":\"ralphie\"}}", httpMethod.getEntity());
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/images");
@ -762,8 +753,8 @@ public class CloudServersConnectionTest {
public void testRebuildServer() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("rebuildServer", int.class,
rebuildServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 3 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 3 });
assertEquals("{\"rebuild\":{}}", httpMethod.getEntity());
validateRebuildServer(method, httpMethod);
}
@ -771,9 +762,8 @@ public class CloudServersConnectionTest {
public void testRebuildServerWithImage() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("rebuildServer", int.class,
rebuildServerOptionsVarargsClass);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 3,
withImage(2) });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 3, withImage(2) });
assertEquals("{\"rebuild\":{\"imageId\":2}}", httpMethod.getEntity());
validateRebuildServer(method, httpMethod);
}
@ -798,9 +788,8 @@ public class CloudServersConnectionTest {
public void testReboot() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("rebootServer", int.class,
RebootType.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2,
RebootType.HARD });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, RebootType.HARD });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
@ -817,8 +806,8 @@ public class CloudServersConnectionTest {
public void testResize() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("resizeServer", int.class, int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2, 3 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2, 3 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
@ -835,8 +824,8 @@ public class CloudServersConnectionTest {
public void testConfirmResize() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("confirmResizeServer", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
@ -853,8 +842,7 @@ public class CloudServersConnectionTest {
public void testRevertResize() throws SecurityException, NoSuchMethodException {
Method method = CloudServersConnection.class.getMethod("revertResizeServer", int.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = processor.createRequest(endpoint, method, new Object[] { 2 });
HttpRequest httpMethod = processor.createRequest(method, new Object[] { 2 });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/servers/2/action");
assertEquals(httpMethod.getMethod(), HttpMethod.POST);
@ -873,22 +861,23 @@ public class CloudServersConnectionTest {
@BeforeClass
void setupFactory() {
factory = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
}
factory = Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(CloudServers.class).toInstance(
URI.create("http://localhost:8080"));
}
@SuppressWarnings("unused")
@Provides
@Authentication
public String getAuthToken() {
return "testtoken";
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
@SuppressWarnings("unused")
@Provides
@Authentication
public String getAuthToken() {
return "testtoken";
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
JaxrsAnnotationProcessor.Factory.class);
processor = factory.create(CloudServersConnection.class);
}
}

View File

@ -0,0 +1,53 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.rackspace.cloudservers.domain;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code CreateImageBinder}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "cloudservers.CreateImageBinderTest")
public class ServerTest {
public void testStatusDoesntAffectEquals() {
Server server1 = new Server(1, "hello");
server1.setStatus(ServerStatus.ACTIVE);
Server server2 = new Server(1, "hello");
server2.setStatus(ServerStatus.BUILD);
assertEquals(server1, server2);
}
public void testProgressDoesntAffectEquals() {
Server server1 = new Server(1, "hello");
server1.setProgress(1);
Server server2 = new Server(1, "hello");
server2.setProgress(2);
assertEquals(server1, server2);
}
}

View File

@ -38,7 +38,7 @@ import javax.inject.Qualifier;
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Authentication {

View File

@ -38,8 +38,8 @@ import javax.inject.Qualifier;
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Storage {
public @interface CloudFiles {
}

View File

@ -38,8 +38,8 @@ import javax.inject.Qualifier;
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface CDN {
public @interface CloudFilesCDN {
}

View File

@ -38,8 +38,8 @@ import javax.inject.Qualifier;
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Server {
public @interface CloudServers {
}

View File

@ -31,6 +31,7 @@ import javax.ws.rs.Path;
import org.jclouds.rackspace.functions.ParseAuthenticationResponseFromHeaders;
import org.jclouds.rackspace.reference.RackspaceHeaders;
import org.jclouds.rest.Endpoint;
import org.jclouds.rest.ResponseParser;
/**
@ -40,17 +41,17 @@ import org.jclouds.rest.ResponseParser;
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
* @author Adrian Cole
*/
@Endpoint(Authentication.class)
public interface RackspaceAuthentication {
public interface AuthenticationResponse {
@Storage
@CloudFiles
URI getStorageUrl();
@CDN
@CloudFilesCDN
URI getCDNManagementUrl();
@Server
@CloudServers
URI getServerManagementUrl();
@Authentication

View File

@ -34,10 +34,10 @@ import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rackspace.Authentication;
import org.jclouds.rackspace.CDN;
import org.jclouds.rackspace.CloudFilesCDN;
import org.jclouds.rackspace.RackspaceAuthentication;
import org.jclouds.rackspace.Server;
import org.jclouds.rackspace.Storage;
import org.jclouds.rackspace.CloudServers;
import org.jclouds.rackspace.CloudFiles;
import org.jclouds.rackspace.RackspaceAuthentication.AuthenticationResponse;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.rest.config.JaxrsModule;
@ -69,39 +69,35 @@ public class RestRackspaceAuthenticationModule extends AbstractModule {
@Provides
@Singleton
protected AuthenticationResponse provideAuthenticationResponse(
@Authentication URI authenticationUri, RestClientFactory factory,
protected AuthenticationResponse provideAuthenticationResponse(RestClientFactory factory,
@Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) {
return factory.create(authenticationUri, RackspaceAuthentication.class).authenticate(user,
key);
return factory.create(RackspaceAuthentication.class).authenticate(user, key);
}
@Provides
@Authentication
protected String provideAuthenticationToken(@Authentication URI authenticationUri,
RestClientFactory factory, @Named(PROPERTY_RACKSPACE_USER) String user,
@Named(PROPERTY_RACKSPACE_KEY) String key) {
return factory.create(authenticationUri, RackspaceAuthentication.class).authenticate(user,
key).getAuthToken();
protected String provideAuthenticationToken(RestClientFactory factory,
@Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) {
return factory.create(RackspaceAuthentication.class).authenticate(user, key).getAuthToken();
}
@Provides
@Singleton
@Storage
@CloudFiles
protected URI provideStorageUrl(AuthenticationResponse response) {
return response.getStorageUrl();
}
@Provides
@Singleton
@Server
@CloudServers
protected URI provideServerUrl(AuthenticationResponse response) {
return response.getServerManagementUrl();
}
@Provides
@Singleton
@CDN
@CloudFilesCDN
protected URI provideCDNUrl(AuthenticationResponse response) {
return response.getCDNManagementUrl();
}

View File

@ -30,6 +30,8 @@ import static org.testng.Assert.fail;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpResponseException;
@ -44,7 +46,7 @@ import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Tests behavior of {@code JaxrsAnnotationProcessor}
@ -54,8 +56,8 @@ import javax.inject.Singleton;
@Test(groups = "live", testName = "rackspace.RackspaceAuthenticationLiveTest")
public class RackspaceAuthenticationLiveTest {
String account = System.getProperty("jclouds.test.user");
String key = System.getProperty("jclouds.test.key");
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
private Injector injector;
@ -89,6 +91,8 @@ public class RackspaceAuthenticationLiveTest {
new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(Authentication.class).toInstance(
URI.create("https://api.mosso.com"));
}
@SuppressWarnings("unused")
@ -96,8 +100,7 @@ public class RackspaceAuthenticationLiveTest {
@Singleton
protected RackspaceAuthentication provideCloudFilesAuthentication(
RestClientFactory factory) {
return factory.create(URI.create("https://api.mosso.com"),
RackspaceAuthentication.class);
return factory.create(RackspaceAuthentication.class);
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule());

View File

@ -58,9 +58,8 @@ public class RackspaceAuthenticationTest {
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = RackspaceAuthentication.class.getMethod("authenticate", String.class,
String.class);
URI endpoint = URI.create("http://localhost");
HttpRequest httpMethod = factory.create(RackspaceAuthentication.class).createRequest(
endpoint, method, new Object[] { "foo", "bar" });
HttpRequest httpMethod = factory.create(RackspaceAuthentication.class).createRequest(method,
new Object[] { "foo", "bar" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/auth");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
@ -77,12 +76,14 @@ public class RackspaceAuthenticationTest {
@BeforeClass
void setupFactory() {
factory = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
factory = Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(Authentication.class).toInstance(
URI.create("http://localhost:8080"));
}
}, new JaxrsModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule()).getInstance(
JaxrsAnnotationProcessor.Factory.class);
}