Merge branch 'master' of github.com:jclouds/jclouds

This commit is contained in:
Alex Yarmula 2010-03-24 14:05:28 -07:00
commit 9b6dbd59ed
38 changed files with 338 additions and 303 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.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.atmosonline.saas.handlers.AtmosStorageClientErrorRetryHandler;
import org.jclouds.atmosonline.saas.handlers.ParseAtmosStorageErrorFromXmlContent;
@ -72,6 +75,7 @@ public class AtmosStorageRestClientModuleTest {
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
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.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import javax.inject.Inject;

View File

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

View File

@ -22,6 +22,7 @@ import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.domain.Region;
@ -42,9 +43,11 @@ public class QueueHandler extends ParseSax.HandlerWithResult<Queue> {
Queue queue;
private final ImmutableBiMap<Region, URI> regionBiMap;
private final Provider<UriBuilder> uriBuilderProvider;
@Inject
QueueHandler(Map<Region, URI> regionMap) {
QueueHandler(Provider<UriBuilder> uriBuilderProvider, Map<Region, URI> regionMap) {
this.uriBuilderProvider = uriBuilderProvider;
this.regionBiMap = ImmutableBiMap.copyOf(regionMap);
}
@ -58,7 +61,7 @@ public class QueueHandler extends ParseSax.HandlerWithResult<Queue> {
String uriText = currentText.toString().trim();
String queueName = uriText.substring(uriText.lastIndexOf('/') + 1);
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);
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 org.testng.Assert.assertEquals;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.aws.ec2.reference.EC2Constants;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
@ -61,6 +64,7 @@ public class EC2RestClientModuleTest {
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.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.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.BlockDeviceMapping;
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.reference.AWSConstants;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
@ -161,8 +157,8 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5,
new RunInstancesOptions().withKernelId("kernelId").enableMonitoring().
withSecurityGroups("group1", "group2"));
new RunInstancesOptions().withKernelId("kernelId").enableMonitoring()
.withSecurityGroups("group1", "group2"));
assertRequestLineEquals(httpMethod, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
@ -172,7 +168,6 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
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");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
assertExceptionParserClassEquals(method, null);
@ -529,13 +524,13 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class
.getMethod("setBlockDeviceMappingForInstanceInRegion", Region.class, String.class,
Method method = InstanceAsyncClient.class.getMethod(
"setBlockDeviceMappingForInstanceInRegion", Region.class, String.class,
BlockDeviceMapping.class);
BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
blockDeviceMapping.addEbsBlockDevice
("/dev/sda1", new RunningInstance.EbsBlockDevice("vol-test1", true));
blockDeviceMapping.addEbsBlockDevice("/dev/sda1", new RunningInstance.EbsBlockDevice(
"vol-test1", true));
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
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.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.AWSRedirectionRetryHandler;
@ -64,6 +67,7 @@ public class S3RestClientModuleTest {
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.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.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.reference.S3Constants;
@ -154,6 +156,7 @@ public class RequestAuthorizeSignatureTest {
.to("1");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT))
.to("https://s3.amazonaws.com");
bind(UriBuilder.class).to(UriBuilderImpl.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.Executors;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.s3.config.S3RestClientModule;
import org.jclouds.aws.s3.reference.S3Constants;
@ -72,6 +75,7 @@ public class S3UtilsTest {
Jsr330.named(S3Constants.PROPERTY_S3_SESSIONINTERVAL)).to("2");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT))
.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.util.Map;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
@ -75,6 +78,7 @@ public class SQSRestClientModuleTest {
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
.to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}

View File

@ -30,8 +30,9 @@ import java.util.Map;
import java.util.Set;
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.aws.domain.Region;
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.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -79,7 +79,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
@Override
protected void configure() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
@SuppressWarnings("unused")
@ -126,7 +126,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
}
}
@Test(enabled=false)
@Test(enabled = false)
void testRegexSerialResponseTime() throws IOException {
long now = System.currentTimeMillis();
for (int i = 0; i < LOOP_COUNT; i++)
@ -134,7 +134,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
System.out.println("testRegex serial: " + (System.currentTimeMillis() - now) + "");
}
@Test(enabled=false)
@Test(enabled = false)
void testRegexParallelResponseTime() throws Throwable {
List<Runnable> tasks = ImmutableList.<Runnable> of(new Runnable() {
public void run() {
@ -144,7 +144,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
executeMultiThreadedPerformanceTest("testRegexParallelResponseTime", tasks);
}
@Test(enabled=false)
@Test(enabled = false)
void testSaxSerialResponseTime() throws IOException {
long now = System.currentTimeMillis();
for (int i = 0; i < LOOP_COUNT; i++)
@ -152,7 +152,7 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
System.out.println("testSax serial: " + (System.currentTimeMillis() - now) + "");
}
@Test(enabled=false)
@Test(enabled = false)
void testSaxParallelResponseTime() throws Throwable {
List<Runnable> tasks = ImmutableList.<Runnable> of(new Runnable() {
public void run() {

View File

@ -21,6 +21,9 @@ package org.jclouds.azure.storage.blob.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
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.azure.storage.blob.handlers.AzureBlobClientErrorRetryHandler;
import org.jclouds.azure.storage.blob.reference.AzureBlobConstants;
@ -73,6 +76,7 @@ public class RestAzureBlobClientModuleTest {
Jsr330
.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_SESSIONINTERVAL))
.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.assertFalse;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.azure.storage.handlers.ParseAzureStorageErrorFromXmlContent;
import org.jclouds.concurrent.config.ExecutorServiceModule;
@ -68,6 +71,7 @@ public class AzureStorageRestClientModuleTest {
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
bindConstant().annotatedWith(
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}

View File

@ -118,25 +118,6 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>test-clojure</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<testNamespaces>
<testNamespace>!clojure.*</testNamespace>
</testNamespaces>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

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

View File

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

View File

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

View File

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

View File

@ -19,8 +19,10 @@
package org.jclouds.rest.config;
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.TransformingHttpCommand;
import org.jclouds.http.TransformingHttpCommandExecutorService;
@ -28,7 +30,6 @@ import org.jclouds.http.TransformingHttpCommandImpl;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.internal.AsyncRestClientProxy;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RuntimeDelegateImpl;
import com.google.common.base.Function;
import com.google.inject.AbstractModule;
@ -43,18 +44,21 @@ public class RestModule extends AbstractModule {
@Override
protected void configure() {
install(new ParserModule());
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
bind(UriBuilder.class).to(UriBuilderImpl.class);
bind(AsyncRestClientProxy.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
}
private static class Factory implements AsyncRestClientProxy.Factory {
@Inject
private TransformingHttpCommandExecutorService executorService;
@Inject
private Provider<UriBuilder> uriBuilderProvider;
@SuppressWarnings("unchecked")
public TransformingHttpCommand<?> create(GeneratedHttpRequest<?> request,
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.Map.Entry;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest;
@ -40,10 +41,13 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
private final Method javaMethod;
private final Object[] args;
private final RestAnnotationProcessor<T> processor;
private final Provider<UriBuilder> uriBuilderProvider;
GeneratedHttpRequest(String method, URI endpoint, RestAnnotationProcessor<T> processor,
Class<T> declaring, Method javaMethod, Object... args) {
GeneratedHttpRequest(Provider<UriBuilder> uriBuilderProvider, String method, URI endpoint,
RestAnnotationProcessor<T> processor, Class<T> declaring, Method javaMethod,
Object... args) {
super(method, endpoint);
this.uriBuilderProvider = uriBuilderProvider;
this.processor = processor;
this.declaring = declaring;
this.javaMethod = javaMethod;
@ -67,7 +71,7 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
}
public void replaceMatrixParam(String name, Object... values) {
UriBuilder builder = UriBuilder.fromUri(getEndpoint());
UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replaceMatrixParam(name, values);
replacePath(builder.build().getPath());
}
@ -81,7 +85,7 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
}
public void replacePath(String path) {
UriBuilder builder = UriBuilder.fromUri(getEndpoint());
UriBuilder builder = uriBuilderProvider.get().uri(getEndpoint());
builder.replacePath(path);
setEndpoint(builder.build());
}

View File

@ -42,6 +42,7 @@ import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.Consumes;
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.logging.Logger;
import org.jclouds.rest.Binder;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.InputParamValidator;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
@ -191,6 +192,7 @@ public class RestAnnotationProcessor<T> {
});
private final ParseSax.Factory parserFactory;
private final Provider<UriBuilder> uriBuilderProvider;
private char[] skips;
@ -230,6 +232,7 @@ public class RestAnnotationProcessor<T> {
this.declaring = (Class<T>) typeLiteral.getRawType();
this.injector = injector;
this.parserFactory = parserFactory;
this.uriBuilderProvider = injector.getProvider(UriBuilder.class);
seedCache(declaring);
if (declaring.isAnnotationPresent(SkipEncoding.class)) {
skips = declaring.getAnnotation(SkipEncoding.class).value();
@ -374,8 +377,8 @@ public class RestAnnotationProcessor<T> {
throw new IllegalStateException(e);
}
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, this,
declaring, method, args);
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(uriBuilderProvider, httpMethod,
endpoint, this, declaring, method, args);
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
addFiltersIfAnnotated(method, request);
@ -399,22 +402,23 @@ public class RestAnnotationProcessor<T> {
public URI replaceQuery(URI in, String newQuery,
@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) {
UriBuilder builder = UriBuilder.fromUri(in);
UriBuilder builder = uriBuilderProvider.get().uri(in);
builder.replaceQuery(makeQueryLine(parseQueryToMap(newQuery), sorter, skips));
return builder.build();
}
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) {
UriBuilder builder = UriBuilder.fromUri(in);
public static URI addQueryParam(Provider<UriBuilder> uriBuilderProvider, URI in, String key,
String[] values, char... skips) {
UriBuilder builder = uriBuilderProvider.get().uri(in);
Multimap<String, String> map = parseQueryToMap(in.getQuery());
map.putAll(key, Arrays.asList(values));
builder.replaceQuery(makeQueryLine(map, null, skips));
@ -435,22 +439,25 @@ public class RestAnnotationProcessor<T> {
Multimap<String, String> map = LinkedListMultimap.create();
if (in == null) {
} else if (in.indexOf('&') == -1) {
if(in.contains("=")) parseKeyValueFromStringToMap(in, map);
else map.put(in, null);
if (in.contains("="))
parseKeyValueFromStringToMap(in, map);
else
map.put(in, null);
} else {
String[] parts = HttpUtils.urlDecode(in).split("&");
for(String part : parts) {
for (String part : parts) {
parseKeyValueFromStringToMap(part, 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
int indexOfFirstEquals = stringToParse.indexOf('=');
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(
0, indexOfFirstEquals);
String key = indexOfFirstEquals == -1 ? stringToParse : stringToParse.substring(0,
indexOfFirstEquals);
String value = indexOfFirstEquals == -1 ? null : stringToParse
.substring(indexOfFirstEquals + 1);
map.put(key, value);
@ -614,7 +621,7 @@ public class RestAnnotationProcessor<T> {
private UriBuilder addHostPrefixIfPresent(URI endpoint, Method method, Object... args) {
Map<Integer, Set<Annotation>> map = indexWithOnlyOneAnnotation(method, "@HostPrefixParam",
methodToIndexOfParamToHostPrefixParamAnnotations);
UriBuilder builder = UriBuilder.fromUri(endpoint);
UriBuilder builder = uriBuilderProvider.get().uri(endpoint);
if (map.size() == 1) {
HostPrefixParam param = (HostPrefixParam) map.values().iterator().next().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.util.Collections;
import javax.inject.Provider;
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.RuntimeDelegateImpl;
import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
@ -41,15 +42,21 @@ import com.google.common.collect.Multimap;
* @author Adrian Cole
*/
public class TransformingHttpCommandImplTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@SuppressWarnings("unchecked")
@Test
public void testChangeSchemeHostAndPortTo() {
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
TransformingHttpCommandImpl<?> command = new TransformingHttpCommandImpl(null, request,
null);
TransformingHttpCommandImpl<?> command = new TransformingHttpCommandImpl(uriBuilderProvider,
null, request, null);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath"));
request.setEndpoint(URI.create("https://remotehost:443/mypath"));
Multimap<String, String> headers = HashMultimap.create();
@ -57,7 +64,6 @@ public class TransformingHttpCommandImplTest {
replay(request);
command.changeSchemeHostAndPortTo("https", "remotehost", 443);
assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost"));
}
@Test

View File

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

View File

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

View File

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

View File

@ -41,6 +41,7 @@ import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Qualifier;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
@ -55,8 +56,9 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
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.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService;
@ -106,6 +108,12 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
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.inject.AbstractModule;
import com.google.inject.Guice;
@ -121,6 +129,15 @@ import com.google.inject.util.Types;
*/
@Test(groups = "unit", testName = "jaxrs.JaxrsUtilTest")
public class RestAnnotationProcessorTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
@Target( { ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@javax.ws.rs.HttpMethod("FOO")
@ -164,7 +181,8 @@ public class RestAnnotationProcessorTest {
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");
URI value = RestAnnotationProcessor.replaceQuery(start, start.getQuery(), null, '/', ':');
URI value = RestAnnotationProcessor.replaceQuery(uriBuilderProvider, start, start.getQuery(),
null, '/', ':');
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().contains("v") : "Expected v to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") :
"Expected the value for 'v' to be '1.3', found: " + valueForV;
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
}
@Test
public void testParseQueryToMapMultiParam() {
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("sig") : "Expected sig to be a part of the keys";
String valueForV = Iterables.getOnlyElement(parsedMap.get("v"));
assert valueForV.equals("1.3") :
"Expected the value for 'v' to be '1.3', found: " + valueForV;
assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: "
+ valueForV;
String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig"));
assert valueForSig.equals("123") :
"Expected the value for 'v' to be '123', found: " + valueForSig;
assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: "
+ valueForSig;
}
@Endpoint(Localhost.class)
@ -1139,7 +1158,8 @@ public class RestAnnotationProcessorTest {
RestAnnotationProcessor<TestTransformers> processor = factory(TestTransformers.class);
Method method = TestTransformers.class.getMethod("oneTransformerWithContext");
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);
assertEquals(transformer.getClass(), ReturnStringIf200Context.class);
assertEquals(((ReturnStringIf200Context) transformer).request, request);
@ -1547,8 +1567,9 @@ public class RestAnnotationProcessorTest {
public void testPut() throws SecurityException, NoSuchMethodException {
RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("put", String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("GET", URI
.create("http://localhost"), processor, TestPayload.class, method, "test");
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>(
uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestPayload.class, method, "test");
processor.decorateRequest(request);
assertEquals(request.getPayload().toString(), "test");
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
@ -1564,8 +1585,9 @@ public class RestAnnotationProcessorTest {
RestAnnotationProcessor<TestPayload> processor = factory(TestPayload.class);
Method method = TestPayload.class.getMethod("putWithPath", String.class, String.class);
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>("GET", URI
.create("http://localhost"), processor, TestPayload.class, method, "rabble", "test");
GeneratedHttpRequest<TestPayload> request = new GeneratedHttpRequest<TestPayload>(
uriBuilderProvider, "GET", URI.create("http://localhost"), processor,
TestPayload.class, method, "rabble", "test");
processor.decorateRequest(request);
assertEquals(request.getPayload().toString(), "test");
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.concurrent.ExecutorService;
import javax.ws.rs.core.UriBuilder;
import org.jboss.resteasy.specimpl.UriBuilderImpl;
import org.jclouds.Constants;
import org.jclouds.PropertiesBuilder;
import org.jclouds.gae.GaeHttpCommandExecutorService;
@ -63,6 +66,7 @@ public class GoogleAppEngineConfigurationModuleTest {
return Logger.NULL;
}
});
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure();
}
});

View File

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

View File

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

View File

@ -23,6 +23,9 @@ import static org.testng.Assert.assertEquals;
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.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.config.ParserModule;
@ -57,6 +60,7 @@ public class PCSContextModuleTest {
return Logger.NULL;
}
});
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure();
}
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),

View File

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

View File

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

View File

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

View File

@ -107,9 +107,13 @@
<id>jclouds-googlecode-deploy</id>
<url>svn:https://jclouds.googlecode.com/svn/repo</url>
</repository>
<snapshotRepository>
<!--snapshotRepository>
<id>jclouds-rimu-snapshots</id>
<url>dav:http://jclouds.rimuhosting.com/maven2/snapshots/</url>
</snapshotRepository-->
<snapshotRepository>
<id>jclouds-rimu-snapshots-nexus</id>
<url>http://jclouds.rimuhosting.com:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<site>
<id>website</id>
@ -272,7 +276,7 @@
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<executions>
<execution>
<id>test-clojure</id>

View File

@ -21,6 +21,9 @@ package org.jclouds.rimuhosting.miro.config;
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
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.http.HttpRetryHandler;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -58,6 +61,7 @@ public class RimuHostingContextModuleTest {
return Logger.NULL;
}
});
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure();
}
}, 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 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.http.HttpRetryHandler;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
@ -57,6 +60,7 @@ public class TwitterContextModuleTest {
return Logger.NULL;
}
});
bind(UriBuilder.class).to(UriBuilderImpl.class);
super.configure();
}
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),

View File

@ -32,6 +32,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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.functions.config.ParserModule;
import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler;
@ -68,6 +71,7 @@ public class VCloudRestClientModuleTest {
"http://localhost");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL))
.to("2");
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
}