Issue 215: removed RuntimeDelegate.setInstance and turned to dependency injection for UriBuilder

This commit is contained in:
Adrian Cole 2010-03-22 22:33:26 -07:00
parent 9ea446ac9f
commit ebcaae325f
36 changed files with 331 additions and 281 deletions

View File

@ -22,6 +22,9 @@ import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler; import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler;
import org.jclouds.atmosonline.saas.handlers.ParseAtmosStorageErrorFromXmlContent; import org.jclouds.atmosonline.saas.handlers.ParseAtmosStorageErrorFromXmlContent;
@ -72,6 +75,7 @@ public class AtmosStorageRestClientModuleTest {
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0"); Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith( bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1"); Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -27,7 +27,6 @@ import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;

View File

@ -19,8 +19,10 @@
package org.jclouds.aws.handlers; package org.jclouds.aws.handlers;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
@ -41,8 +43,9 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler {
private final AWSUtils utils; private final AWSUtils utils;
@Inject @Inject
public AWSRedirectionRetryHandler(BackoffLimitedRetryHandler backoffHandler, AWSUtils utils) { public AWSRedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
super(backoffHandler); BackoffLimitedRetryHandler backoffHandler, AWSUtils utils) {
super(uriBuilderProvider, backoffHandler);
this.utils = utils; this.utils = utils;
} }

View File

@ -22,6 +22,7 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
@ -42,9 +43,11 @@ public class QueueHandler extends ParseSax.HandlerWithResult<Queue> {
Queue queue; Queue queue;
private final ImmutableBiMap<Region, URI> regionBiMap; private final ImmutableBiMap<Region, URI> regionBiMap;
private final Provider<UriBuilder> uriBuilderProvider;
@Inject @Inject
QueueHandler(Map<Region, URI> regionMap) { QueueHandler(Provider<UriBuilder> uriBuilderProvider, Map<Region, URI> regionMap) {
this.uriBuilderProvider = uriBuilderProvider;
this.regionBiMap = ImmutableBiMap.copyOf(regionMap); this.regionBiMap = ImmutableBiMap.copyOf(regionMap);
} }
@ -58,7 +61,7 @@ public class QueueHandler extends ParseSax.HandlerWithResult<Queue> {
String uriText = currentText.toString().trim(); String uriText = currentText.toString().trim();
String queueName = uriText.substring(uriText.lastIndexOf('/') + 1); String queueName = uriText.substring(uriText.lastIndexOf('/') + 1);
URI location = URI.create(uriText); URI location = URI.create(uriText);
URI regionURI = UriBuilder.fromUri(location).replacePath("").build(); URI regionURI = uriBuilderProvider.get().uri(location).replacePath("").build();
Region region = regionBiMap.inverse().get(regionURI); Region region = regionBiMap.inverse().get(regionURI);
this.queue = new Queue(region, queueName, location); this.queue = new Queue(region, queueName, location);
} }

View File

@ -21,6 +21,9 @@ package org.jclouds.aws.ec2.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.ec2.reference.EC2Constants; import org.jclouds.aws.ec2.reference.EC2Constants;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
@ -61,6 +64,7 @@ public class EC2RestClientModuleTest {
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1"); .to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -30,9 +30,6 @@ import javax.inject.Singleton;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.EC2ContextFactory;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.BlockDeviceMapping; import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.InstanceType;
@ -51,12 +48,11 @@ import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
import org.jclouds.aws.filters.FormSigner; import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.CloseContentAndReturn; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
@ -161,8 +157,8 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
RunInstancesOptions.class, 0).getClass()); RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5, Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5,
new RunInstancesOptions().withKernelId("kernelId").enableMonitoring(). new RunInstancesOptions().withKernelId("kernelId").enableMonitoring()
withSecurityGroups("group1", "group2")); .withSecurityGroups("group1", "group2"));
assertRequestLineEquals(httpMethod, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
@ -172,7 +168,6 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
httpMethod, httpMethod,
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a"); "Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class); assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -529,13 +524,13 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class Method method = InstanceAsyncClient.class.getMethod(
.getMethod("setBlockDeviceMappingForInstanceInRegion", Region.class, String.class, "setBlockDeviceMappingForInstanceInRegion", Region.class, String.class,
BlockDeviceMapping.class); BlockDeviceMapping.class);
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping(); BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
blockDeviceMapping.addEbsBlockDevice blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(
("/dev/sda1", new RunningInstance.EbsBlockDevice("vol-test1", true)); "vol-test1", true));
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.DEFAULT, "1", blockDeviceMapping); Region.DEFAULT, "1", blockDeviceMapping);

View File

@ -22,6 +22,9 @@ import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler; import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
@ -64,6 +67,7 @@ public class S3RestClientModuleTest {
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1"); .to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -25,7 +25,9 @@ import java.net.URI;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.s3.config.S3RestClientModule; import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.reference.S3Constants;
@ -154,6 +156,7 @@ public class RequestAuthorizeSignatureTest {
.to("1"); .to("1");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)) bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT))
.to("https://s3.amazonaws.com"); .to("https://s3.amazonaws.com");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
filter = injector.getInstance(RequestAuthorizeSignature.class); filter = injector.getInstance(RequestAuthorizeSignature.class);

View File

@ -25,6 +25,9 @@ import java.io.InputStream;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.s3.config.S3RestClientModule; import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.reference.S3Constants;
@ -72,6 +75,7 @@ public class S3UtilsTest {
Jsr330.named(S3Constants.PROPERTY_S3_SESSIONINTERVAL)).to("2"); Jsr330.named(S3Constants.PROPERTY_S3_SESSIONINTERVAL)).to("2");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)) bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT))
.to("https://s3.amazonaws.com"); .to("https://s3.amazonaws.com");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });

View File

@ -25,6 +25,9 @@ import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
@ -75,6 +78,7 @@ public class SQSRestClientModuleTest {
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1"); Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1"); .to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -30,8 +30,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.ext.RuntimeDelegate; import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.PerformanceTest; import org.jclouds.PerformanceTest;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.sqs.domain.Queue; import org.jclouds.aws.sqs.domain.Queue;
@ -39,7 +40,6 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -79,7 +79,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
@Override @Override
protected void configure() { protected void configure() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl()); bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -21,6 +21,9 @@ package org.jclouds.azure.storage.blob.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.azure.storage.blob.handlers.AzureBlobClientErrorRetryHandler; import org.jclouds.azure.storage.blob.handlers.AzureBlobClientErrorRetryHandler;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants; import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
@ -73,6 +76,7 @@ public class RestAzureBlobClientModuleTest {
Jsr330 Jsr330
.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL)) .named(AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL))
.to(1l); .to(1l);
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -25,6 +25,9 @@ import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent; import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
@ -68,6 +71,7 @@ public class AzureStorageRestClientModuleTest {
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0"); Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith( bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1"); Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }

View File

@ -23,6 +23,7 @@ import java.util.concurrent.ExecutionException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
@ -45,6 +46,7 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
private final TransformingHttpCommandExecutorService executorService; private final TransformingHttpCommandExecutorService executorService;
private final Function<HttpResponse, T> transformer; private final Function<HttpResponse, T> transformer;
private final Provider<UriBuilder> uriBuilderProvider;
private GeneratedHttpRequest<?> request; private GeneratedHttpRequest<?> request;
private volatile int failureCount; private volatile int failureCount;
@ -56,8 +58,10 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
protected volatile Exception exception; protected volatile Exception exception;
@Inject @Inject
public TransformingHttpCommandImpl(TransformingHttpCommandExecutorService executorService, public TransformingHttpCommandImpl(Provider<UriBuilder> uriBuilderProvider,
TransformingHttpCommandExecutorService executorService,
GeneratedHttpRequest<?> request, Function<HttpResponse, T> transformer) { GeneratedHttpRequest<?> request, Function<HttpResponse, T> transformer) {
this.uriBuilderProvider = uriBuilderProvider;
this.request = request; this.request = request;
this.executorService = executorService; this.executorService = executorService;
this.transformer = transformer; this.transformer = transformer;
@ -85,7 +89,7 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
*/ */
@Override @Override
public void changeSchemeHostAndPortTo(String scheme, String host, int port) { public void changeSchemeHostAndPortTo(String scheme, String host, int port) {
UriBuilder builder = UriBuilder.fromUri(request.getEndpoint()); UriBuilder builder = uriBuilderProvider.get().uri(request.getEndpoint());
builder.scheme(scheme); builder.scheme(scheme);
builder.host(host); builder.host(host);
builder.port(port); builder.port(port);

View File

@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkState;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
@ -42,6 +44,13 @@ import com.google.common.base.Function;
*/ */
public class ParseURIFromListOrLocationHeaderIf20x implements Function<HttpResponse, URI>, public class ParseURIFromListOrLocationHeaderIf20x implements Function<HttpResponse, URI>,
InvocationContext { InvocationContext {
private final Provider<UriBuilder> uriBuilderProvider;
@Inject
ParseURIFromListOrLocationHeaderIf20x(Provider<UriBuilder> uriBuilderProvider) {
this.uriBuilderProvider = uriBuilderProvider;
}
private GeneratedHttpRequest<?> request; private GeneratedHttpRequest<?> request;
public URI apply(HttpResponse from) { public URI apply(HttpResponse from) {
@ -67,7 +76,8 @@ public class ParseURIFromListOrLocationHeaderIf20x implements Function<HttpRespo
checkState(request != null, "request should have been initialized"); checkState(request != null, "request should have been initialized");
if (!location.startsWith("/")) if (!location.startsWith("/"))
location = "/" + location; location = "/" + location;
UriBuilder builder = UriBuilder.fromUri(URI.create("http://localhost" + location)); UriBuilder builder = uriBuilderProvider.get().uri(
URI.create("http://localhost" + location));
builder.host(request.getEndpoint().getHost()); builder.host(request.getEndpoint().getHost());
builder.port(request.getEndpoint().getPort()); builder.port(request.getEndpoint().getPort());
builder.scheme(request.getEndpoint().getScheme()); builder.scheme(request.getEndpoint().getScheme());

View File

@ -18,6 +18,9 @@
*/ */
package org.jclouds.http.handlers; package org.jclouds.http.handlers;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
@ -51,10 +54,11 @@ public class DelegatingRetryHandler implements HttpRetryHandler {
@ServerError @ServerError
HttpRetryHandler serverErrorRetryHandler; HttpRetryHandler serverErrorRetryHandler;
public DelegatingRetryHandler() { @Inject
public DelegatingRetryHandler(Provider<UriBuilder> uriBuilderProvider) {
BackoffLimitedRetryHandler backOff = new BackoffLimitedRetryHandler(); BackoffLimitedRetryHandler backOff = new BackoffLimitedRetryHandler();
this.serverErrorRetryHandler = backOff; this.serverErrorRetryHandler = backOff;
this.redirectionRetryHandler = new RedirectionRetryHandler(backOff); this.redirectionRetryHandler = new RedirectionRetryHandler(uriBuilderProvider, backOff);
this.clientErrorRetryHandler = HttpRetryHandler.NEVER_RETRY; this.clientErrorRetryHandler = HttpRetryHandler.NEVER_RETRY;
} }

View File

@ -24,6 +24,7 @@ import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
@ -52,10 +53,13 @@ public class RedirectionRetryHandler implements HttpRetryHandler {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final BackoffLimitedRetryHandler backoffHandler; protected final BackoffLimitedRetryHandler backoffHandler;
private final Provider<UriBuilder> uriBuilderProvider;
@Inject @Inject
public RedirectionRetryHandler(BackoffLimitedRetryHandler backoffHandler) { public RedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
BackoffLimitedRetryHandler backoffHandler) {
this.backoffHandler = backoffHandler; this.backoffHandler = backoffHandler;
this.uriBuilderProvider = uriBuilderProvider;
} }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
@ -63,7 +67,7 @@ public class RedirectionRetryHandler implements HttpRetryHandler {
String hostHeader = response.getFirstHeaderOrNull(HttpHeaders.LOCATION); String hostHeader = response.getFirstHeaderOrNull(HttpHeaders.LOCATION);
if (hostHeader != null && command.incrementRedirectCount() < retryCountLimit) { if (hostHeader != null && command.incrementRedirectCount() < retryCountLimit) {
URI redirectionUrl = UriBuilder.fromUri(hostHeader).build(); URI redirectionUrl = uriBuilderProvider.get().uri(URI.create(hostHeader)).build();
if (redirectionUrl.getScheme().equals(command.getRequest().getEndpoint().getScheme()) if (redirectionUrl.getScheme().equals(command.getRequest().getEndpoint().getScheme())
&& redirectionUrl.getHost().equals(command.getRequest().getEndpoint().getHost()) && redirectionUrl.getHost().equals(command.getRequest().getEndpoint().getHost())
&& redirectionUrl.getPort() == command.getRequest().getEndpoint().getPort()) { && redirectionUrl.getPort() == command.getRequest().getEndpoint().getPort()) {

View File

@ -19,8 +19,10 @@
package org.jclouds.rest.config; package org.jclouds.rest.config;
import javax.inject.Inject; import javax.inject.Inject;
import javax.ws.rs.ext.RuntimeDelegate; import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.TransformingHttpCommand; import org.jclouds.http.TransformingHttpCommand;
import org.jclouds.http.TransformingHttpCommandExecutorService; import org.jclouds.http.TransformingHttpCommandExecutorService;
@ -28,7 +30,6 @@ import org.jclouds.http.TransformingHttpCommandImpl;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.internal.AsyncRestClientProxy; import org.jclouds.rest.internal.AsyncRestClientProxy;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -43,18 +44,21 @@ public class RestModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
install(new ParserModule()); install(new ParserModule());
RuntimeDelegate.setInstance(new RuntimeDelegateImpl()); bind(UriBuilder.class).to(UriBuilderImpl.class);
bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(Scopes.SINGLETON); bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
} }
private static class Factory implements AsyncRestClientProxy.Factory { private static class Factory implements AsyncRestClientProxy.Factory {
@Inject @Inject
private TransformingHttpCommandExecutorService executorService; private TransformingHttpCommandExecutorService executorService;
@Inject
private Provider<UriBuilder> uriBuilderProvider;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request, public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request,
Function<HttpResponse, ?> transformer) { Function<HttpResponse, ?> transformer) {
return new TransformingHttpCommandImpl(executorService, request, transformer); return new TransformingHttpCommandImpl(uriBuilderProvider, executorService, request,
transformer);
} }
} }

View File

@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -40,10 +41,13 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
private final Method javaMethod; private final Method javaMethod;
private final Object[] args; private final Object[] args;
private final RestAnnotationProcessor<T> processor; private final RestAnnotationProcessor<T> processor;
private final Provider<UriBuilder> uriBuilderProvider;
GeneratedHttpRequest(String method, URI endpoint, RestAnnotationProcessor<T> processor, GeneratedHttpRequest(Provider<UriBuilder> uriBuilderProvider, String method, URI endpoint,
Class<T> declaring, Method javaMethod, Object... args) { RestAnnotationProcessor<T> processor, Class<T> declaring, Method javaMethod,
Object... args) {
super(method, endpoint); super(method, endpoint);
this.uriBuilderProvider = uriBuilderProvider;
this.processor = processor; this.processor = processor;
this.declaring = declaring; this.declaring = declaring;
this.javaMethod = javaMethod; this.javaMethod = javaMethod;
@ -67,7 +71,7 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
} }
public void replaceMatrixParam(String name, Object... values) { public void replaceMatrixParam(String name, Object... values) {
UriBuilder builder = UriBuilder.fromUri(getEndpoint()); UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replaceMatrixParam(name, values); builder.replaceMatrixParam(name, values);
replacePath(builder.build().getPath()); replacePath(builder.build().getPath());
} }
@ -81,7 +85,7 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
} }
public void replacePath(String path) { public void replacePath(String path) {
UriBuilder builder = UriBuilder.fromUri(getEndpoint()); UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replacePath(path); builder.replacePath(path);
setEndpoint(builder.build()); setEndpoint(builder.build());
} }

View File

@ -42,6 +42,7 @@ import java.util.Map.Entry;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@ -71,8 +72,8 @@ import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.Binder; import org.jclouds.rest.Binder;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.InputParamValidator; import org.jclouds.rest.InputParamValidator;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
@ -191,6 +192,7 @@ public class RestAnnotationProcessor<T> {
}); });
private final ParseSax.Factory parserFactory; private final ParseSax.Factory parserFactory;
private final Provider<UriBuilder> uriBuilderProvider;
private char[] skips; private char[] skips;
@ -230,6 +232,7 @@ public class RestAnnotationProcessor<T> {
this.declaring = (Class<T>) typeLiteral.getRawType(); this.declaring = (Class<T>) typeLiteral.getRawType();
this.injector = injector; this.injector = injector;
this.parserFactory = parserFactory; this.parserFactory = parserFactory;
this.uriBuilderProvider = injector.getProvider(UriBuilder.class);
seedCache(declaring); seedCache(declaring);
if (declaring.isAnnotationPresent(SkipEncoding.class)) { if (declaring.isAnnotationPresent(SkipEncoding.class)) {
skips = declaring.getAnnotation(SkipEncoding.class).value(); skips = declaring.getAnnotation(SkipEncoding.class).value();
@ -374,8 +377,8 @@ public class RestAnnotationProcessor<T> {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, this, GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(uriBuilderProvider, httpMethod,
declaring, method, args); endpoint, this, declaring, method, args);
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method); addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
addFiltersIfAnnotated(method, request); addFiltersIfAnnotated(method, request);
@ -399,22 +402,23 @@ public class RestAnnotationProcessor<T> {
public URI replaceQuery(URI in, String newQuery, public URI replaceQuery(URI in, String newQuery,
@Nullable Comparator<Entry<String, String>> sorter) { @Nullable Comparator<Entry<String, String>> sorter) {
return replaceQuery(in, newQuery, sorter, skips); return replaceQuery(uriBuilderProvider, in, newQuery, sorter, skips);
} }
public static URI replaceQuery(URI in, String newQuery, public static URI replaceQuery(Provider<UriBuilder> uriBuilderProvider, URI in, String newQuery,
@Nullable Comparator<Entry<String, String>> sorter, char... skips) { @Nullable Comparator<Entry<String, String>> sorter, char... skips) {
UriBuilder builder = UriBuilder.fromUri(in); UriBuilder builder = uriBuilderProvider.get().uri(in);
builder.replaceQuery(makeQueryLine(parseQueryToMap(newQuery), sorter, skips)); builder.replaceQuery(makeQueryLine(parseQueryToMap(newQuery), sorter, skips));
return builder.build(); return builder.build();
} }
public URI addQueryParam(URI in, String key, String[] values) { public URI addQueryParam(URI in, String key, String[] values) {
return addQueryParam(in, key, values, skips); return addQueryParam(uriBuilderProvider, in, key, values, skips);
} }
public static URI addQueryParam(URI in, String key, String[] values, char... skips) { public static URI addQueryParam(Provider<UriBuilder> uriBuilderProvider, URI in, String key,
UriBuilder builder = UriBuilder.fromUri(in); String[] values, char... skips) {
UriBuilder builder = uriBuilderProvider.get().uri(in);
Multimap<String, String> map = parseQueryToMap(in.getQuery()); Multimap<String, String> map = parseQueryToMap(in.getQuery());
map.putAll(key, Arrays.asList(values)); map.putAll(key, Arrays.asList(values));
builder.replaceQuery(makeQueryLine(map, null, skips)); builder.replaceQuery(makeQueryLine(map, null, skips));
@ -435,8 +439,10 @@ public class RestAnnotationProcessor<T> {
Multimap<String, String> map = LinkedListMultimap.create(); Multimap<String, String> map = LinkedListMultimap.create();
if (in == null) { if (in == null) {
} else if (in.indexOf('&') == -1) { } else if (in.indexOf('&') == -1) {
if(in.contains("=")) parseKeyValueFromStringToMap(in, map); if (in.contains("="))
else map.put(in, null); parseKeyValueFromStringToMap(in, map);
else
map.put(in, null);
} else { } else {
String[] parts = HttpUtils.urlDecode(in).split("&"); String[] parts = HttpUtils.urlDecode(in).split("&");
for (String part : parts) { for (String part : parts) {
@ -446,11 +452,12 @@ public class RestAnnotationProcessor<T> {
return map; return map;
} }
public static void parseKeyValueFromStringToMap(String stringToParse, Multimap<String, String> map) { public static void parseKeyValueFromStringToMap(String stringToParse,
Multimap<String, String> map) {
// note that '=' can be a valid part of the value // note that '=' can be a valid part of the value
int indexOfFirstEquals = stringToParse.indexOf('='); int indexOfFirstEquals = stringToParse.indexOf('=');
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring( String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0,
0, indexOfFirstEquals); indexOfFirstEquals);
String value = indexOfFirstEquals == -1 ? null : stringToParse String value = indexOfFirstEquals == -1 ? null : stringToParse
.substring(indexOfFirstEquals + 1); .substring(indexOfFirstEquals + 1);
map.put(key, value); map.put(key, value);
@ -614,7 +621,7 @@ public class RestAnnotationProcessor<T> {
private UriBuilder addHostPrefixIfPresent(URI endpoint, Method method, Object... args) { private UriBuilder addHostPrefixIfPresent(URI endpoint, Method method, Object... args) {
Map<Integer, Set<Annotation>> map = indexWithOnlyOneAnnotation(method, "@HostPrefixParam", Map<Integer, Set<Annotation>> map = indexWithOnlyOneAnnotation(method, "@HostPrefixParam",
methodToIndexOfParamToHostPrefixParamAnnotations); methodToIndexOfParamToHostPrefixParamAnnotations);
UriBuilder builder = UriBuilder.fromUri(endpoint); UriBuilder builder = uriBuilderProvider.get().uri(endpoint);
if (map.size() == 1) { if (map.size() == 1) {
HostPrefixParam param = (HostPrefixParam) map.values().iterator().next().iterator().next(); HostPrefixParam param = (HostPrefixParam) map.values().iterator().next().iterator().next();
int index = map.keySet().iterator().next(); int index = map.keySet().iterator().next();

View File

@ -1,81 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.rest.internal;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Variant.VariantListBuilder;
import javax.ws.rs.ext.RuntimeDelegate;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
/**
* @author Adrian Cole
*
* @see RuntimeDelegate
*/
public class RuntimeDelegateImpl extends RuntimeDelegate {
/**
* operation is currently unsupported.
*/
@Override
public <T> T createEndpoint(Application application, Class<T> endpointType)
throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException(
"jclouds does not currently implement the entire jaxrs spec.");
}
/**
* operation is currently unsupported.
*/
@Override
public <T> HeaderDelegate<T> createHeaderDelegate(Class<T> type) {
throw new UnsupportedOperationException(
"jclouds does not currently implement the entire jaxrs spec.");
}
/**
* operation is currently unsupported.
*/
@Override
public ResponseBuilder createResponseBuilder() {
throw new UnsupportedOperationException(
"jclouds does not currently implement the entire jaxrs spec.");
}
/**
* {@inheritDoc}
*/
@Override
public UriBuilder createUriBuilder() {
return new UriBuilderImpl();
}
/**
* operation is currently unsupported.
*/
@Override
public VariantListBuilder createVariantListBuilder() {
throw new UnsupportedOperationException(
"jclouds does not currently implement the entire jaxrs spec.");
}
}

View File

@ -26,11 +26,12 @@ import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Collections; import java.util.Collections;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.ext.RuntimeDelegate; import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
@ -41,15 +42,21 @@ import com.google.common.collect.Multimap;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TransformingHttpCommandImplTest { public class TransformingHttpCommandImplTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void testChangeSchemeHostAndPortTo() { public void testChangeSchemeHostAndPortTo() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
TransformingHttpCommandImpl<?> command = new TransformingHttpCommandImpl(null, request, TransformingHttpCommandImpl<?> command = new TransformingHttpCommandImpl(uriBuilderProvider,
null); null, request, null);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath")); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath"));
request.setEndpoint(URI.create("https://remotehost:443/mypath")); request.setEndpoint(URI.create("https://remotehost:443/mypath"));
Multimap<String, String> headers = HashMultimap.create(); Multimap<String, String> headers = HashMultimap.create();
@ -57,7 +64,6 @@ public class TransformingHttpCommandImplTest {
replay(request); replay(request);
command.changeSchemeHostAndPortTo("https", "remotehost", 443); command.changeSchemeHostAndPortTo("https", "remotehost", 443);
assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost")); assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost"));
} }
@Test @Test

View File

@ -29,25 +29,34 @@ import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.ws.rs.ext.RuntimeDelegate; import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.mortbay.jetty.HttpHeaders; import org.mortbay.jetty.HttpHeaders;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
@Test(groups = { "unit" }) @Test(groups = { "unit" })
public class ParseURIFromListOrLocationHeaderIf20xTest { public class ParseURIFromListOrLocationHeaderIf20xTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@Test @Test
public void testExceptionWhenNoContentOn200() throws ExecutionException, InterruptedException, public void testExceptionWhenNoContentOn200() throws ExecutionException, InterruptedException,
TimeoutException, IOException { TimeoutException, IOException {
Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(); Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
expect(response.getStatusCode()).andReturn(200).atLeastOnce(); expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list"); expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list");
@ -64,7 +73,8 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
@Test @Test
public void testExceptionWhenIOExceptionOn200() throws ExecutionException, InterruptedException, public void testExceptionWhenIOExceptionOn200() throws ExecutionException, InterruptedException,
TimeoutException, IOException { TimeoutException, IOException {
Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(); Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
expect(response.getStatusCode()).andReturn(200).atLeastOnce(); expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list"); expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list");
@ -81,12 +91,12 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
@Test @Test
public void testResponseOk() throws Exception { public void testResponseOk() throws Exception {
Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(); Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
expect(response.getStatusCode()).andReturn(200).atLeastOnce(); expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list"); expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list");
expect(response.getContent()).andReturn(Utils.toInputStream("http://locahost")) expect(response.getContent()).andReturn(Utils.toInputStream("http://locahost")).atLeastOnce();
.atLeastOnce();
replay(response); replay(response);
assertEquals(function.apply(response), URI.create("http://locahost")); assertEquals(function.apply(response), URI.create("http://locahost"));
verify(response); verify(response);
@ -94,7 +104,8 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
@Test @Test
public void testResponseLocationOk() throws Exception { public void testResponseLocationOk() throws Exception {
Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(); Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
expect(response.getStatusCode()).andReturn(200).atLeastOnce(); expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/plain"); expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/plain");
@ -106,7 +117,8 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
@Test @Test
public void testResponseLowercaseLocationOk() throws Exception { public void testResponseLowercaseLocationOk() throws Exception {
Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(); Function<HttpResponse, URI> function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
expect(response.getStatusCode()).andReturn(200).atLeastOnce(); expect(response.getStatusCode()).andReturn(200).atLeastOnce();
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/plain"); expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/plain");
@ -117,14 +129,10 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
verify(response); verify(response);
} }
@BeforeTest
public void beforeTest() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
}
@Test @Test
public void testResponsePathLocationOk() throws Exception { public void testResponsePathLocationOk() throws Exception {
ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x(); ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
function.setContext(request); function.setContext(request);
@ -141,7 +149,8 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
@Test @Test
public void testResponsePathPortLocationOk() throws Exception { public void testResponsePathPortLocationOk() throws Exception {
ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x(); ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
function.setContext(request); function.setContext(request);
@ -156,10 +165,10 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
verify(response); verify(response);
} }
@Test @Test
public void testResponsePathSchemeLocationOk() throws Exception { public void testResponsePathSchemeLocationOk() throws Exception {
ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x(); ParseURIFromListOrLocationHeaderIf20x function = new ParseURIFromListOrLocationHeaderIf20x(
uriBuilderProvider);
HttpResponse response = createMock(HttpResponse.class); HttpResponse response = createMock(HttpResponse.class);
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
function.setContext(request); function.setContext(request);

View File

@ -28,6 +28,10 @@ import java.net.URI;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.PropertiesBuilder; import org.jclouds.PropertiesBuilder;
import org.jclouds.http.BaseJettyTest; import org.jclouds.http.BaseJettyTest;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
@ -88,13 +92,21 @@ public class BackoffLimitedRetryHandlerTest {
} }
TransformingHttpCommandExecutorServiceImpl executorService; TransformingHttpCommandExecutorServiceImpl executorService;
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@BeforeTest @BeforeTest
void setupExecutorService() throws Exception { void setupExecutorService() throws Exception {
ExecutorService execService = Executors.newCachedThreadPool(); ExecutorService execService = Executors.newCachedThreadPool();
JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService( JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService(
execService, new DelegatingRetryHandler(), new DelegatingErrorHandler(), execService, new DelegatingRetryHandler(uriBuilderProvider),
new HttpWire(), new HttpUtils(0, 500, 1, 1), null); new DelegatingErrorHandler(), new HttpWire(), new HttpUtils(0, 500, 1, 1), null);
executorService = new TransformingHttpCommandExecutorServiceImpl(httpService); executorService = new TransformingHttpCommandExecutorServiceImpl(httpService);
} }
@ -167,8 +179,8 @@ public class BackoffLimitedRetryHandlerTest {
private HttpCommand createCommand() throws SecurityException, NoSuchMethodException { private HttpCommand createCommand() throws SecurityException, NoSuchMethodException {
Method method = IntegrationTestAsyncClient.class.getMethod("download", String.class); Method method = IntegrationTestAsyncClient.class.getMethod("download", String.class);
return new TransformingHttpCommandImpl<String>(executorService, processor.createRequest( return new TransformingHttpCommandImpl<String>(uriBuilderProvider, executorService, processor
method, "1"), new ReturnStringIf200()); .createRequest(method, "1"), new ReturnStringIf200());
} }
@Test @Test

View File

@ -25,11 +25,9 @@ import java.io.File;
import java.net.URI; import java.net.URI;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.ext.RuntimeDelegate;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -41,9 +39,6 @@ import com.google.common.collect.ImmutableMap;
*/ */
@Test(groups = "unit", testName = "rest.BindMapToMatrixParamsTest") @Test(groups = "unit", testName = "rest.BindMapToMatrixParamsTest")
public class BindMapToMatrixParamsTest { public class BindMapToMatrixParamsTest {
static {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
}
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeMap() { public void testMustBeMap() {

View File

@ -41,6 +41,7 @@ import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Qualifier; import javax.inject.Qualifier;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@ -55,8 +56,9 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import com.google.common.collect.*; import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.PropertiesBuilder; import org.jclouds.PropertiesBuilder;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
@ -106,6 +108,12 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -121,6 +129,15 @@ import com.google.inject.util.Types;
*/ */
@Test(groups = "unit", testName = "jaxrs.JaxrsUtilTest") @Test(groups = "unit", testName = "jaxrs.JaxrsUtilTest")
public class RestAnnotationProcessorTest { public class RestAnnotationProcessorTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@Target( { ElementType.METHOD }) @Target( { ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@javax.ws.rs.HttpMethod("FOO") @javax.ws.rs.HttpMethod("FOO")
@ -164,7 +181,8 @@ public class RestAnnotationProcessorTest {
URI start = URI URI start = URI
.create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436"); .create("http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriancole-compute.testObjectOperations&metadata=chef%3Asushi&metadata=foo%3Abar&sessionToken=775ef26e-0740-4707-ad92-afe9814bc436");
URI value = RestAnnotationProcessor.replaceQuery(start, start.getQuery(), null, '/', ':'); URI value = RestAnnotationProcessor.replaceQuery(uriBuilderProvider, start, start.getQuery(),
null, '/', ':');
assertEquals(value, expects); assertEquals(value, expects);
} }
@ -822,22 +840,23 @@ public class RestAnnotationProcessorTest {
assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size(); assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys"; assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v")); String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
"Expected the value for 'v' to be '1.3', found: " + valueForV; + valueForV;
} }
@Test @Test
public void testParseQueryToMapMultiParam() { public void testParseQueryToMapMultiParam() {
Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3&sig=123"); Multimap<String, String> parsedMap = RestAnnotationProcessor.parseQueryToMap("v=1.3&sig=123");
assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: " + parsedMap.keySet().size(); assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: "
+ parsedMap.keySet().size();
assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys"; assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys";
assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys"; assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v")); String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") : assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
"Expected the value for 'v' to be '1.3', found: " + valueForV; + valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig")); String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") : assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: "
"Expected the value for 'v' to be '123', found: " + valueForSig; + valueForSig;
} }
@Endpoint(Localhost.class) @Endpoint(Localhost.class)
@ -1139,7 +1158,8 @@ public class RestAnnotationProcessorTest {
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class); RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
Method method = TestTransformers.class.getMethod("oneTransformerWithContext"); Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>( GeneratedHttpRequest<TestTransformers> request = new GeneratedHttpRequest<TestTransformers>(
"GET", URI.create("http://localhost"), processor, TestTransformers.class, method); uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestTransformers.class, method);
Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request); Function<HttpResponse, ?> transformer = processor.createResponseParser(method, request);
assertEquals(transformer.getClass(), ReturnStringIf200Context.class); assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
assertEquals(((ReturnStringIf200Context) transformer).request, request); assertEquals(((ReturnStringIf200Context) transformer).request, request);
@ -1547,8 +1567,9 @@ public class RestAnnotationProcessorTest {
public void testPut() throws SecurityException, NoSuchMethodException { public void testPut() throws SecurityException, NoSuchMethodException {
RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class); RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("put", String.class); Method method = TestPayload.class.getMethod("put", String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("GET", URI GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>(
.create("http://localhost"), processor, TestPayload.class, method, "test"); uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestPayload.class, method, "test");
processor.decorateRequest(request); processor.decorateRequest(request);
assertEquals(request.getPayload().toString(), "test"); assertEquals(request.getPayload().toString(), "test");
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
@ -1564,8 +1585,9 @@ public class RestAnnotationProcessorTest {
RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class); RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class); Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("GET", URI GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>(
.create("http://localhost"), processor, TestPayload.class, method, "rabble", "test"); uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestPayload.class, method, "rabble", "test");
processor.decorateRequest(request); processor.decorateRequest(request);
assertEquals(request.getPayload().toString(), "test"); assertEquals(request.getPayload().toString(), "test");
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections

View File

@ -22,6 +22,9 @@ import java.net.URI;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.PropertiesBuilder; import org.jclouds.PropertiesBuilder;
import org.jclouds.gae.GaeHttpCommandExecutorService; import org.jclouds.gae.GaeHttpCommandExecutorService;
@ -63,6 +66,7 @@ public class GoogleAppEngineConfigurationModuleTest {
return Logger.NULL; return Logger.NULL;
} }
}); });
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure(); super.configure();
} }
}); });

View File

@ -21,6 +21,9 @@ package org.jclouds.gogrid.config;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.gogrid.handlers.GoGridErrorHandler; import org.jclouds.gogrid.handlers.GoGridErrorHandler;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
@ -56,25 +59,24 @@ public class GoGridContextModuleTest {
.to("password"); .to("password");
bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT)) bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT))
.to("http://localhost"); .to("http://localhost");
bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL)) bindConstant().annotatedWith(
.to("30"); Jsr330.named(GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL)).to("30");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)) bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
.to("1"); .to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)) bindConstant().annotatedWith(
.to("0"); Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
.to("1"); .to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
.to("1"); bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_CONNECTION_TIMEOUT)).to(
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_CONNECTION_TIMEOUT)) "30");
.to("30"); bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_SO_TIMEOUT)).to("10");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_SO_TIMEOUT))
.to("10");
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) { public Logger getLogger(String category) {
return Logger.NULL; return Logger.NULL;
} }
}); });
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure(); super.configure();
} }
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),
@ -84,8 +86,7 @@ public class GoGridContextModuleTest {
@Test @Test
void testServerErrorHandler() { void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(), assertEquals(handler.getServerErrorHandler().getClass(), GoGridErrorHandler.class);
GoGridErrorHandler.class);
} }
@Test @Test
@ -97,8 +98,7 @@ public class GoGridContextModuleTest {
@Test @Test
void testClientErrorHandler() { void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), assertEquals(handler.getClientErrorHandler().getClass(), GoGridErrorHandler.class);
GoGridErrorHandler.class);
} }
@Test @Test

View File

@ -31,8 +31,10 @@ import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.StorageType; import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
@ -59,6 +61,14 @@ public class PCSClientLiveTest {
private PCSClient connection; private PCSClient connection;
private String user; private String user;
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException { public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
@ -167,7 +177,7 @@ public class PCSClientLiveTest {
connection.putMetadataItem(objectURI, "name", "object"); connection.putMetadataItem(objectURI, "name", "object");
try { try {
connection.downloadFile(UriBuilder.fromUri(objectURI).path("sad").build()); connection.downloadFile(uriBuilderProvider.get().uri(objectURI).path("sad").build());
assert false; assert false;
} catch (KeyNotFoundException e) { } catch (KeyNotFoundException e) {
} }

View File

@ -23,6 +23,9 @@ import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
@ -57,6 +60,7 @@ public class PCSContextModuleTest {
return Logger.NULL; return Logger.NULL;
} }
}); });
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure(); super.configure();
} }
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),

View File

@ -25,11 +25,9 @@ import java.io.File;
import java.net.URI; import java.net.URI;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.ext.RuntimeDelegate;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -41,9 +39,6 @@ import com.google.common.collect.ImmutableMap;
*/ */
@Test(groups = "unit", testName = "sdn.BindMetadataToQueryParamsTest") @Test(groups = "unit", testName = "sdn.BindMetadataToQueryParamsTest")
public class BindMetadataToQueryParamsTest { public class BindMetadataToQueryParamsTest {
static {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
}
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testMustBeMap() { public void testMustBeMap() {

View File

@ -25,7 +25,6 @@ import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.ext.RuntimeDelegate;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
@ -38,7 +37,6 @@ import org.jclouds.nirvanix.sdn.SessionToken;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.config.RestModule; import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -107,7 +105,6 @@ public class AddSessionTokenToRequestTest {
new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() { new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() {
protected void configure() { protected void configure() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
bind(DateService.class); bind(DateService.class);
Jsr330.bindProperties(this.binder(), new SDNPropertiesBuilder("appkey", Jsr330.bindProperties(this.binder(), new SDNPropertiesBuilder("appkey",
"appname", "username", "password").build()); "appname", "username", "password").build());

View File

@ -28,7 +28,6 @@ import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.ext.RuntimeDelegate;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -39,7 +38,6 @@ import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.config.RestModule; import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -96,7 +94,6 @@ public class InsertUserContextIntoPathTest {
new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() { new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() {
protected void configure() { protected void configure() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) { public Logger getLogger(String category) {
return Logger.NULL; return Logger.NULL;

View File

@ -21,6 +21,9 @@ package org.jclouds.rimuhosting.miro.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -58,6 +61,7 @@ public class RimuHostingContextModuleTest {
return Logger.NULL; return Logger.NULL;
} }
}); });
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure(); super.configure();
} }
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),

View File

@ -21,6 +21,9 @@ package org.jclouds.twitter.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -57,6 +60,7 @@ public class TwitterContextModuleTest {
return Logger.NULL; return Logger.NULL;
} }
}); });
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure(); super.configure();
} }
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),

View File

@ -32,6 +32,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler;
@ -68,6 +71,7 @@ public class VCloudRestClientModuleTest {
"http://localhost"); "http://localhost");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL)) bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL))
.to("2"); .to("2");
bind(UriBuilder.class).to(UriBuilderImpl.class);
} }
}); });
} }