Issue 68 expose endPoint URI in HttpRequest

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1453 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-21 01:45:34 +00:00
parent 8ea84a656a
commit 1557173695
36 changed files with 323 additions and 248 deletions

View File

@ -25,6 +25,7 @@ package org.jclouds.aws.s3.commands;
import static org.jclouds.aws.s3.commands.options.ListBucketOptions.Builder.maxResults;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -36,7 +37,6 @@ import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* Issues a HEAD command to determine if the bucket exists or not.
@ -47,9 +47,8 @@ import com.google.inject.name.Named;
public class BucketExists extends S3FutureCommand<Boolean> {
@Inject
public BucketExists(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String s3Bucket) {
super(HttpMethod.HEAD, "/" + maxResults(0).buildQueryString(), callable, amazonHost, s3Bucket);
public BucketExists(URI endPoint, ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super(endPoint, HttpMethod.HEAD, "/" + maxResults(0).buildQueryString(), callable, s3Bucket);
}
@Override

View File

@ -25,6 +25,8 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.aws.s3.commands.options.CopyObjectOptions;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.xml.CopyObjectHandler;
@ -34,20 +36,19 @@ import org.jclouds.util.Utils;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* The copy operation creates a copy of an object that is already storedin
* Amazon S3.
* The copy operation creates a copy of an object that is already storedin Amazon S3.
* <p/>
* When copying an object, you can preserve all metadata (default) or
* {@link CopyObjectOptions#overrideMetadataWith(com.google.common.collect.Multimap)
* specify new metadata}. However, the ACL is not preserved and is set to
* private for the user making the request. To override the default ACL setting,
* {@link CopyObjectOptions#overrideAcl(org.jclouds.aws.s3.domain.acl.CannedAccessPolicy)
* specify a new ACL} when generating a copy request.
* {@link CopyObjectOptions#overrideMetadataWith(com.google.common.collect.Multimap) specify new
* metadata}. However, the ACL is not preserved and is set to private for the user making the
* request. To override the default ACL setting,
* {@link CopyObjectOptions#overrideAcl(org.jclouds.aws.s3.domain.acl.CannedAccessPolicy) specify a
* new ACL} when generating a copy request.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectCOPY.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectCOPY.html"
* />
* @see CopyObjectOptions
* @see org.jclouds.aws.s3.domain.acl.CannedAccessPolicy
@ -57,23 +58,20 @@ import com.google.inject.name.Named;
public class CopyObject extends S3FutureCommand<S3Object.Metadata> {
@Inject
public CopyObject(@Named("jclouds.http.address") String amazonHost,
ParseSax<S3Object.Metadata> callable, @Assisted("sourceBucket") String sourceBucket,
@Assisted("sourceObject") String sourceObject,
@Assisted("destinationBucket") String destinationBucket,
@Assisted("destinationObject") String destinationObject,
@Assisted CopyObjectOptions options)
{
super(HttpMethod.PUT,
"/" + checkNotNull(destinationObject, "destinationObject"),
callable, amazonHost, destinationBucket);
public CopyObject(URI endPoint, ParseSax<S3Object.Metadata> callable,
@Assisted("sourceBucket") String sourceBucket,
@Assisted("sourceObject") String sourceObject,
@Assisted("destinationBucket") String destinationBucket,
@Assisted("destinationObject") String destinationObject,
@Assisted CopyObjectOptions options) {
super(endPoint, HttpMethod.PUT, "/" + checkNotNull(destinationObject, "destinationObject"),
callable, destinationBucket);
CopyObjectHandler handler = (CopyObjectHandler) callable.getHandler();
handler.setKey(destinationObject);
getRequest().getHeaders().put(
"x-amz-copy-source",
String.format("/%1$s/%2$s",
checkNotNull(sourceBucket, "sourceBucket"),
Utils.encodeUriPath(checkNotNull(sourceObject, "sourceObject"))));
"x-amz-copy-source",
String.format("/%1$s/%2$s", checkNotNull(sourceBucket, "sourceBucket"), Utils
.encodeUriPath(checkNotNull(sourceObject, "sourceObject"))));
getRequest().getHeaders().putAll(options.buildRequestHeaders());
}
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -34,7 +35,6 @@ import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* The DELETE request operation deletes the bucket named in the URI. All objects in the bucket must
@ -50,9 +50,8 @@ import com.google.inject.name.Named;
public class DeleteBucket extends S3FutureCommand<Boolean> {
@Inject
public DeleteBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String s3Bucket) {
super(HttpMethod.DELETE, "/", callable, amazonHost, s3Bucket);
public DeleteBucket(URI endPoint, ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super(endPoint, HttpMethod.DELETE, "/", callable, s3Bucket);
}
@Override

View File

@ -25,12 +25,13 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* The DELETE request operation removes the specified object from Amazon S3. Once deleted, there is
@ -43,8 +44,8 @@ import com.google.inject.name.Named;
public class DeleteObject extends S3FutureCommand<Boolean> {
@Inject
public DeleteObject(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
public DeleteObject(URI endPoint, ReturnTrueIf2xx callable,
@Assisted("bucketName") String bucket, @Assisted("key") String key) {
super(HttpMethod.DELETE, "/" + checkNotNull(key), callable, amazonHost, bucket);
super(endPoint, HttpMethod.DELETE, "/" + checkNotNull(key), callable, bucket);
}
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -35,7 +36,6 @@ import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* A GET request operation directed at an object or bucket URI with the "acl" parameter retrieves
@ -49,17 +49,15 @@ import com.google.inject.name.Named;
public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
@Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
public GetAccessControlList(URI endPoint, ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket) {
super(HttpMethod.GET, "/?acl", accessControlListParser, amazonHost, bucket);
super(endPoint, HttpMethod.GET, "/?acl", accessControlListParser, bucket);
}
@Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
public GetAccessControlList(URI endPoint, ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
super(HttpMethod.GET, "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
super(endPoint, HttpMethod.GET, "/" + objectKey + "?acl", accessControlListParser, bucket);
}
@Override

View File

@ -25,6 +25,7 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -38,7 +39,6 @@ import org.jclouds.http.HttpMethod;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* Retrieves the S3Object associated with the Key or {@link S3Object#NOT_FOUND} if not available;
@ -66,10 +66,10 @@ import com.google.inject.name.Named;
public class GetObject extends S3FutureCommand<S3Object> {
@Inject
public GetObject(@Named("jclouds.http.address") String amazonHost,
ParseObjectFromHeadersAndHttpContent callable, @Assisted("bucketName") String s3Bucket,
@Assisted("key") String key, @Assisted GetObjectOptions options) {
super(HttpMethod.GET, "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
public GetObject(URI endPoint, ParseObjectFromHeadersAndHttpContent callable,
@Assisted("bucketName") String s3Bucket, @Assisted("key") String key,
@Assisted GetObjectOptions options) {
super(endPoint, HttpMethod.GET, "/" + checkNotNull(key), callable, s3Bucket);
this.getRequest().getHeaders().putAll(options.buildRequestHeaders());
callable.setKey(key);
}

View File

@ -25,6 +25,7 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -37,7 +38,6 @@ import org.jclouds.http.HttpResponseException;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* Retrieves the metadata associated with the Key or
@ -58,10 +58,9 @@ import com.google.inject.name.Named;
public class HeadObject extends S3FutureCommand<S3Object.Metadata> {
@Inject
public HeadObject(@Named("jclouds.http.address") String amazonHost,
ParseMetadataFromHeaders callable, @Assisted("bucketName") String bucket,
@Assisted("key") String key) {
super(HttpMethod.HEAD, "/" + checkNotNull(key), callable, amazonHost, bucket);
public HeadObject(URI endPoint, ParseMetadataFromHeaders callable,
@Assisted("bucketName") String bucket, @Assisted("key") String key) {
super(endPoint, HttpMethod.HEAD, "/" + checkNotNull(key), callable, bucket);
callable.setKey(key);
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -37,7 +38,6 @@ import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* A GET request operation using a bucket URI lists information about the objects in the bucket.
@ -56,10 +56,9 @@ import com.google.inject.name.Named;
public class ListBucket extends S3FutureCommand<S3Bucket> {
@Inject
public ListBucket(@Named("jclouds.http.address") String amazonHost,
ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
public ListBucket(URI endPoint, ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
@Assisted ListBucketOptions options) {
super(HttpMethod.GET, "/" + options.buildQueryString(), bucketParser, amazonHost, bucket);
super(endPoint, HttpMethod.GET, "/" + options.buildQueryString(), bucketParser, bucket);
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
handler.setBucketName(bucket);
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.List;
import org.jclouds.aws.s3.domain.S3Bucket;
@ -30,7 +31,6 @@ import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.inject.Inject;
import com.google.inject.name.Named;
/**
* Returns a list of all of the buckets owned by the authenticated sender of the request.
@ -44,9 +44,8 @@ import com.google.inject.name.Named;
public class ListOwnedBuckets extends S3FutureCommand<List<S3Bucket.Metadata>> {
@Inject
public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost,
ParseSax<List<S3Bucket.Metadata>> callable) {
super(HttpMethod.GET, "/", callable, amazonHost);
public ListOwnedBuckets(URI endPoint, ParseSax<List<S3Bucket.Metadata>> callable) {
super(endPoint, HttpMethod.GET, "/", callable);
}
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@ -37,7 +38,6 @@ import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* Create and name your own bucket in which to store your objects.
@ -57,9 +57,9 @@ import com.google.inject.name.Named;
public class PutBucket extends S3FutureCommand<Boolean> {
@Inject
public PutBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String bucketName, @Assisted PutBucketOptions options) {
super(HttpMethod.PUT, "/", callable, amazonHost, S3Utils.validateBucketName(bucketName));
public PutBucket(URI endPoint, ReturnTrueIf2xx callable, @Assisted String bucketName,
@Assisted PutBucketOptions options) {
super(endPoint, HttpMethod.PUT, "/", callable, S3Utils.validateBucketName(bucketName));
getRequest().getHeaders().putAll(options.buildRequestHeaders());
String payload = options.buildPayload();
if (payload != null) {

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import javax.annotation.Resource;
import org.jclouds.aws.s3.domain.AccessControlList;
@ -34,7 +36,6 @@ import org.jclouds.logging.Logger;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* A PUT request operation directed at a bucket URI with the "acl" parameter sets the Access Control
@ -50,10 +51,9 @@ public class PutBucketAccessControlList extends S3FutureCommand<Boolean> {
protected Logger logger = Logger.NULL;
@Inject
public PutBucketAccessControlList(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted AccessControlList acl) {
super(HttpMethod.PUT, "/?acl", callable, amazonHost, bucket);
public PutBucketAccessControlList(URI endPoint, ReturnTrueIf2xx callable,
@Assisted("bucketName") String bucket, @Assisted AccessControlList acl) {
super(endPoint, HttpMethod.PUT, "/?acl", callable, bucket);
String aclPayload = "";
try {

View File

@ -26,6 +26,8 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.aws.s3.commands.callables.ParseMd5FromETagHeader;
import org.jclouds.aws.s3.commands.options.PutObjectOptions;
import org.jclouds.aws.s3.domain.S3Object;
@ -35,7 +37,6 @@ import org.jclouds.http.HttpMethod;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* Store data by creating or overwriting an object.
@ -56,10 +57,9 @@ import com.google.inject.name.Named;
public class PutObject extends S3FutureCommand<byte[]> {
@Inject
public PutObject(@Named("jclouds.http.address") String amazonHost,
ParseMd5FromETagHeader callable, @Assisted String s3Bucket, @Assisted S3Object object,
@Assisted PutObjectOptions options) {
super(HttpMethod.PUT, "/" + checkNotNull(object.getKey()), callable, amazonHost, s3Bucket);
public PutObject(URI endPoint, ParseMd5FromETagHeader callable, @Assisted String s3Bucket,
@Assisted S3Object object, @Assisted PutObjectOptions options) {
super(endPoint, HttpMethod.PUT, "/" + checkNotNull(object.getKey()), callable, s3Bucket);
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
getRequest().setPayload(checkNotNull(object.getData(), "object.getContent()"));

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import javax.annotation.Resource;
import org.jclouds.aws.s3.domain.AccessControlList;
@ -34,7 +36,6 @@ import org.jclouds.logging.Logger;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* A PUT request operation directed at an object URI with the "acl" parameter sets the Access
@ -50,10 +51,10 @@ public class PutObjectAccessControlList extends S3FutureCommand<Boolean> {
protected Logger logger = Logger.NULL;
@Inject
public PutObjectAccessControlList(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted("key") String objectKey, @Assisted AccessControlList acl) {
super(HttpMethod.PUT, "/" + objectKey + "?acl", callable, amazonHost, bucket);
public PutObjectAccessControlList(URI endPoint, ReturnTrueIf2xx callable,
@Assisted("bucketName") String bucket, @Assisted("key") String objectKey,
@Assisted AccessControlList acl) {
super(endPoint, HttpMethod.PUT, "/" + objectKey + "?acl", callable, bucket);
String aclPayload = "";
try {

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.aws.s3.commands;
import java.net.URI;
import org.jclouds.aws.s3.commands.options.CopyObjectOptions;
import org.jclouds.aws.s3.commands.options.GetObjectOptions;
import org.jclouds.aws.s3.commands.options.ListBucketOptions;
@ -34,7 +36,6 @@ import org.jclouds.aws.s3.xml.S3ParserFactory;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* Assembles the command objects for S3.
@ -124,58 +125,53 @@ public class S3CommandFactory {
}
@Inject
@Named("jclouds.http.address")
String amazonHost;
URI endPoint;
public ListOwnedBuckets createGetMetadataForOwnedBuckets() {
return new ListOwnedBuckets(amazonHost, parserFactory.createListBucketsParser());
return new ListOwnedBuckets(endPoint, parserFactory.createListBucketsParser());
}
public ListBucket createListBucket(String bucket, ListBucketOptions options) {
return new ListBucket(amazonHost, parserFactory.createListBucketParser(), bucket, options);
return new ListBucket(endPoint, parserFactory.createListBucketParser(), bucket, options);
}
public CopyObject createCopyObject(String sourceBucket, String sourceObject,
String destinationBucket, String destinationObject, CopyObjectOptions options) {
return new CopyObject(amazonHost, parserFactory.createCopyObjectParser(), sourceBucket,
return new CopyObject(endPoint, parserFactory.createCopyObjectParser(), sourceBucket,
sourceObject, destinationBucket, destinationObject, options);
}
public GetAccessControlList createGetBucketACL(String bucket) {
return new GetAccessControlList(
amazonHost, parserFactory.createAccessControlListParser(), bucket);
return new GetAccessControlList(endPoint, parserFactory.createAccessControlListParser(),
bucket);
}
public GetAccessControlList createGetObjectACL(String bucket, String objectKey) {
return new GetAccessControlList(
amazonHost, parserFactory.createAccessControlListParser(), bucket, objectKey);
return new GetAccessControlList(endPoint, parserFactory.createAccessControlListParser(),
bucket, objectKey);
}
@Inject
private PutBucketAccessControlListFactory putBucketAccessControlListFactory;
public static interface PutBucketAccessControlListFactory {
PutBucketAccessControlList create(@Assisted("bucketName") String bucket,
AccessControlList acl);
PutBucketAccessControlList create(@Assisted("bucketName") String bucket, AccessControlList acl);
}
public PutBucketAccessControlList createPutBucketACL(String bucket, AccessControlList acl) {
return putBucketAccessControlListFactory.create(bucket, acl);
}
@Inject
private PutObjectAccessControlListFactory putObjectAccessControlListFactory;
public static interface PutObjectAccessControlListFactory {
PutObjectAccessControlList create(@Assisted("bucketName") String bucket,
@Assisted("key") String objectKey, AccessControlList acl);
PutObjectAccessControlList create(@Assisted("bucketName") String bucket,
@Assisted("key") String objectKey, AccessControlList acl);
}
public PutObjectAccessControlList createPutObjectACL(String bucket, String objectKey,
AccessControlList acl)
{
AccessControlList acl) {
return putObjectAccessControlListFactory.create(bucket, objectKey, acl);
}

View File

@ -25,6 +25,8 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
@ -37,16 +39,16 @@ import org.jclouds.http.HttpMethod;
*/
public class S3FutureCommand<T> extends HttpFutureCommand<T> {
public S3FutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable,
String amazonHost, String bucketName) {
super(method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull(bucketName, "bucketName"));
public S3FutureCommand(URI endPoint, HttpMethod method, String uri,
ResponseCallable<T> responseCallable, String bucketName) {
super(endPoint, method, uri, responseCallable);
addHostHeader(endPoint.getHost(), checkNotNull(bucketName, "bucketName"));
}
public S3FutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable,
String amazonHost) {
super(method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"));
public S3FutureCommand(URI endPoint, HttpMethod method, String uri,
ResponseCallable<T> responseCallable) {
super(endPoint, method, uri, responseCallable);
addHostHeader(endPoint.getHost());
}
protected void addHostHeader(String amazonHost, String bucketName) {

View File

@ -27,6 +27,8 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import java.net.URI;
import org.jclouds.aws.s3.commands.config.S3CommandsModule;
import org.jclouds.aws.s3.commands.options.CopyObjectOptions;
import org.jclouds.aws.s3.commands.options.GetObjectOptions;
@ -44,7 +46,6 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
/**
* @author Adrian Cole
@ -60,7 +61,7 @@ public class S3CommandFactoryTest {
injector = Guice.createInjector(new S3ParserModule(), new S3CommandsModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named("jclouds.http.address")).to("localhost");
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
super.configure();
}
});

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.aws.s3.config;
import java.net.URI;
import org.jclouds.aws.s3.S3Connection;
import org.jclouds.aws.s3.StubS3Connection;
@ -37,5 +39,6 @@ import com.google.inject.AbstractModule;
public class StubS3ConnectionModule extends AbstractModule {
protected void configure() {
bind(S3Connection.class).to(StubS3Connection.class);
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
}
}

View File

@ -25,6 +25,8 @@ package org.jclouds.http;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.annotation.Resource;
import org.apache.commons.io.IOUtils;
@ -39,13 +41,14 @@ import org.jclouds.logging.Logger;
*/
public class HttpFutureCommand<T> extends FutureCommand<HttpRequest, HttpResponse, T> {
public HttpFutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable) {
super(new HttpRequest(checkNotNull(method, "method"), checkNotNull(uri, "uri")),
responseCallable);
public HttpFutureCommand(URI endPoint, HttpMethod method, String uri,
ResponseCallable<T> responseCallable) {
super(new HttpRequest(checkNotNull(endPoint, "endPoint"), checkNotNull(method, "method"),
checkNotNull(uri, "uri")), responseCallable);
}
protected void addHostHeader(String host) {
getRequest().getHeaders().put("Host", host);
getRequest().getHeaders().put(HttpHeaders.HOST, host);
}
@Override

View File

@ -26,6 +26,7 @@ package org.jclouds.http;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.InputStream;
import java.net.URI;
import javax.annotation.Resource;
@ -39,6 +40,7 @@ import org.jclouds.util.Utils;
*/
public class HttpRequest extends HttpMessage {
private URI endPoint;
private final HttpMethod method;
private final String uri;
Object payload;
@ -46,7 +48,16 @@ public class HttpRequest extends HttpMessage {
@Resource
protected Logger logger = Logger.NULL;
public HttpRequest(HttpMethod method, String uri) {
/**
*
* @param endPoint
* initial endPoint (ex. http://host:port ). This may change over the life of the
* request due to redirects.
* @param method
* @param uri
*/
public HttpRequest(URI endPoint, HttpMethod method, String uri) {
this.endPoint = checkNotNull(endPoint, "endPoint");
this.method = checkNotNull(method, "method");
this.uri = Utils.encodeUriPath(checkNotNull(uri, "uri"));
}
@ -55,7 +66,8 @@ public class HttpRequest extends HttpMessage {
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("HttpRequest");
sb.append("{method='").append(method).append('\'');
sb.append("{endPoint='").append(endPoint).append('\'');
sb.append(", method='").append(method).append('\'');
sb.append(", uri='").append(uri).append('\'');
sb.append(", headers=").append(headers);
sb.append(", payload set=").append(payload != null);
@ -88,4 +100,12 @@ public class HttpRequest extends HttpMessage {
this.payload = content;
}
public void setEndPoint(URI endPoint) {
this.endPoint = endPoint;
}
public URI getEndPoint() {
return endPoint;
}
}

View File

@ -44,9 +44,15 @@ public class CommandFactory {
ParseSax<?> create(ParseSax.HandlerWithResult<?> handler);
}
@SuppressWarnings("unchecked")
@Inject
private GetAndParseSaxFactory getAndParseSaxFactory;
public static interface GetAndParseSaxFactory {
GetAndParseSax<?> create(String uri, ParseSax<?> callable);
}
public GetAndParseSax<?> createGetAndParseSax(String uri, ParseSax.HandlerWithResult<?> handler) {
return new GetAndParseSax(uri, parseSaxFactory.create(handler));
return getAndParseSaxFactory.create(uri, parseSaxFactory.create(handler));
}
@Inject

View File

@ -23,10 +23,15 @@
*/
package org.jclouds.http.commands;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
/**
* // TODO: Adrian: Document this!
*
@ -34,7 +39,8 @@ import org.jclouds.http.commands.callables.xml.ParseSax;
*/
public class GetAndParseSax<T> extends HttpFutureCommand<T> {
public GetAndParseSax(String uri, ParseSax<T> callable) {
super(HttpMethod.GET, uri, callable);
@Inject
public GetAndParseSax(URI endPoint, @Assisted String uri, @Assisted ParseSax<T> callable) {
super(endPoint, HttpMethod.GET, uri, callable);
}
}

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.http.commands;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnStringIf200;
@ -38,7 +40,7 @@ import com.google.inject.assistedinject.Assisted;
public class GetString extends HttpFutureCommand<String> {
@Inject
public GetString(ReturnStringIf200 callable, @Assisted String uri) {
super(HttpMethod.GET, uri, callable);
public GetString(URI endPoint, ReturnStringIf200 callable, @Assisted String uri) {
super(endPoint, HttpMethod.GET, uri, callable);
}
}

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.http.commands;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
@ -38,7 +40,7 @@ import com.google.inject.assistedinject.Assisted;
public class Head extends HttpFutureCommand<Boolean> {
@Inject
public Head(ReturnTrueIf2xx callable, @Assisted String uri) {
super(HttpMethod.HEAD, uri, callable);
public Head(URI endPoint, ReturnTrueIf2xx callable, @Assisted String uri) {
super(endPoint, HttpMethod.HEAD, uri, callable);
}
}

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.http.commands;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
@ -38,9 +40,9 @@ import com.google.inject.assistedinject.Assisted;
public class Put extends HttpFutureCommand<Boolean> {
@Inject
public Put(ReturnTrueIf2xx callable, @Assisted("uri") String uri,
public Put(URI endPoint, ReturnTrueIf2xx callable, @Assisted("uri") String uri,
@Assisted("payload") String payload) {
super(HttpMethod.PUT, uri, callable);
super(endPoint, HttpMethod.PUT, uri, callable);
this.getRequest().setPayload(payload);
}
}

View File

@ -24,6 +24,7 @@
package org.jclouds.http.commands.config;
import org.jclouds.http.commands.CommandFactory;
import org.jclouds.http.commands.GetAndParseSax;
import org.jclouds.http.commands.GetString;
import org.jclouds.http.commands.Head;
import org.jclouds.http.commands.Put;
@ -54,6 +55,10 @@ public class HttpCommandsModule extends AbstractModule {
FactoryProvider.newFactory(new TypeLiteral<CommandFactory.ParseSaxFactory>() {
}, new TypeLiteral<ParseSax<?>>() {
}));
bind(CommandFactory.GetAndParseSaxFactory.class).toProvider(
FactoryProvider.newFactory(new TypeLiteral<CommandFactory.GetAndParseSaxFactory>() {
}, new TypeLiteral<GetAndParseSax<?>>() {
}));
}

View File

@ -24,7 +24,7 @@
package org.jclouds.http.config;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import org.jclouds.http.HttpConstants;
import org.jclouds.http.HttpFutureCommandClient;
@ -43,26 +43,25 @@ import com.google.inject.name.Named;
@HttpFutureCommandClientModule
public class JavaUrlHttpFutureCommandClientModule extends AbstractModule {
@Override
protected void configure() {
bindClient();
}
@Override
protected void configure() {
bindClient();
}
protected void bindClient() {
// note this is not threadsafe, so it cannot be singleton
bind(HttpFutureCommandClient.class).to(
JavaUrlHttpFutureCommandClient.class);
}
protected void bindClient() {
// note this is not threadsafe, so it cannot be singleton
bind(HttpFutureCommandClient.class).to(JavaUrlHttpFutureCommandClient.class);
}
@Singleton
@Provides
protected URL provideAddress(
@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
throws MalformedURLException {
@Singleton
@Provides
protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
throws MalformedURLException {
return new URL(isSecure ? "https" : "http", address, port, "/");
}
return URI.create(String.format("%1$s://%2$s:%3$s", isSecure ? "https" : "http", address,
port));
}
}

View File

@ -23,8 +23,18 @@
*/
package org.jclouds.http.internal;
import com.google.inject.Inject;
import org.jclouds.http.*;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import javax.annotation.Resource;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpFutureCommandClient;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.annotation.ClientErrorHandler;
import org.jclouds.http.annotation.RedirectHandler;
import org.jclouds.http.annotation.RetryHandler;
@ -33,14 +43,11 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.http.handlers.CloseContentAndSetExceptionHandler;
import org.jclouds.logging.Logger;
import javax.annotation.Resource;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import com.google.inject.Inject;
public abstract class BaseHttpFutureCommandClient implements HttpFutureCommandClient {
protected final URL target;
protected final URI target;
@Resource
protected Logger logger = Logger.NULL;
@ -62,7 +69,7 @@ public abstract class BaseHttpFutureCommandClient implements HttpFutureCommandCl
protected HttpRetryHandler httpRetryHandler = new BackoffLimitedRetryHandler(5);
@Inject
public BaseHttpFutureCommandClient(URL target) {
public BaseHttpFutureCommandClient(URI target) {
this.target = target;
}

View File

@ -31,6 +31,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import org.apache.commons.io.IOUtils;
@ -52,7 +53,7 @@ import com.google.inject.Inject;
public class JavaUrlHttpFutureCommandClient extends BaseHttpFutureCommandClient {
@Inject
public JavaUrlHttpFutureCommandClient(URL target) throws MalformedURLException {
public JavaUrlHttpFutureCommandClient(URI target) throws MalformedURLException {
super(target);
}
@ -106,7 +107,7 @@ public class JavaUrlHttpFutureCommandClient extends BaseHttpFutureCommandClient
}
protected HttpURLConnection openJavaConnection(HttpRequest request) throws IOException {
URL url = new URL(target, request.getUri());
URL url = new URL(target.toURL(), request.getUri());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setAllowUserInteraction(false);

View File

@ -23,6 +23,8 @@
*/
package org.jclouds.http.commands;
import java.net.URI;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnStringIf200;
import org.testng.annotations.AfterMethod;
@ -37,6 +39,7 @@ import org.testng.annotations.Test;
@Test
public class GetStringTest {
private static final String GOOD_PATH = "/index.html";
private static final URI END_POINT = URI.create("http://localhost:8080");
private GetString get = null;
private ReturnStringIf200 callable = null;
@ -44,7 +47,7 @@ public class GetStringTest {
@BeforeMethod
void setUp() {
callable = new ReturnStringIf200();
get = new GetString(callable, GOOD_PATH);
get = new GetString(END_POINT, callable, GOOD_PATH);
}
@AfterMethod
@ -56,6 +59,7 @@ public class GetStringTest {
@Test
public void testConstructor() {
assert get.getResponseFuture() != null;
assert get.getRequest().getEndPoint().equals(END_POINT);
assert get.getRequest().getUri().equals(GOOD_PATH);
assert get.getRequest().getMethod().equals(HttpMethod.GET);
}

View File

@ -23,11 +23,14 @@
*/
package org.jclouds.http.commands.config;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.commands.CommandFactory;
import org.jclouds.http.commands.callables.xml.ParseSax;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -39,32 +42,44 @@ import com.google.inject.Injector;
@Test
public class HttpCommandsModuleTest {
public void testGetString() {
Injector i = Guice.createInjector(new HttpCommandsModule());
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<String> get = factory.createGetString("/index.html");
assert get != null;
assert get.getResponseFuture() != null;
}
public void testGetString() {
Injector i = createInjector();
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<String> get = factory.createGetString("/index.html");
assert get != null;
assert get.getResponseFuture() != null;
}
public void testHead() {
Injector i = Guice.createInjector(new HttpCommandsModule());
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<Boolean> Head = factory.createHead("/index.html");
assert Head != null;
assert Head.getResponseFuture() != null;
}
private Injector createInjector() {
Injector i = Guice.createInjector(new HttpCommandsModule(), new AbstractModule() {
public void testGetAndParseXml() {
Injector i = Guice.createInjector(new HttpCommandsModule());
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<?> GetAndParseXml = factory.createGetAndParseSax(
"/index.html", new ParseSax.HandlerWithResult<String>() {
public String getResult() {
return "hello";
}
});
assert GetAndParseXml != null;
assert GetAndParseXml.getResponseFuture() != null;
}
@Override
protected void configure() {
bind(URI.class).toInstance(URI.create("http://localhost:8080"));
}
});
return i;
}
public void testHead() {
Injector i = createInjector();
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<Boolean> Head = factory.createHead("/index.html");
assert Head != null;
assert Head.getResponseFuture() != null;
}
public void testGetAndParseXml() {
Injector i = createInjector();
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<?> GetAndParseXml = factory.createGetAndParseSax("/index.html",
new ParseSax.HandlerWithResult<String>() {
public String getResult() {
return "hello";
}
});
assert GetAndParseXml != null;
assert GetAndParseXml.getResponseFuture() != null;
}
}

View File

@ -28,6 +28,7 @@ import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
@ -37,6 +38,7 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "core.BackoffLimitedRetryHandler")
public class BackoffLimitedRetryHandlerTest {
private static final URI END_POINT = URI.create("http://localhost:8080");
BackoffLimitedRetryHandler handler = new BackoffLimitedRetryHandler(5);
@ -77,8 +79,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testClosesInputStream() throws InterruptedException, IOException {
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri",
new ReturnStringIf200());
HttpFutureCommand<String> command = new HttpFutureCommand<String>(END_POINT, HttpMethod.HEAD,
"uri", new ReturnStringIf200());
HttpResponse response = new HttpResponse();
InputStream inputStream = new InputStream() {
boolean isOpen = true;
@ -117,8 +119,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testIncrementsFailureCount() throws InterruptedException {
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri",
new ReturnStringIf200());
HttpFutureCommand<String> command = new HttpFutureCommand<String>(END_POINT, HttpMethod.HEAD,
"uri", new ReturnStringIf200());
HttpResponse response = new HttpResponse();
handler.retryRequest(command, response);
@ -133,8 +135,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testDisallowsExcessiveRetries() throws InterruptedException {
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri",
new ReturnStringIf200());
HttpFutureCommand<String> command = new HttpFutureCommand<String>(END_POINT, HttpMethod.HEAD,
"uri", new ReturnStringIf200());
HttpResponse response = new HttpResponse();
assertEquals(handler.retryRequest(command, response), true); // Failure 1

View File

@ -31,6 +31,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List;
@ -51,7 +52,6 @@ import com.google.appengine.api.urlfetch.HTTPResponse;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.name.Named;
/**
* Google App Engine version of {@link HttpFutureCommandClient}
@ -64,13 +64,12 @@ public class URLFetchServiceClient extends BaseHttpFutureCommandClient {
private final boolean isSecure;
@Inject
public URLFetchServiceClient(@Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure, URL target,
URLFetchService urlFetchService) throws MalformedURLException {
public URLFetchServiceClient(URI target, URLFetchService urlFetchService)
throws MalformedURLException {
super(target);
this.urlFetchService = urlFetchService;
this.port = port;
this.isSecure = isSecure;
this.port = target.getPort();
this.isSecure = target.getScheme().equals("https");
}
public void submit(HttpFutureCommand<?> command) {
@ -165,7 +164,7 @@ public class URLFetchServiceClient extends BaseHttpFutureCommandClient {
url = new URL(new URL(isSecure ? "https" : "http", hostHeader, port, "/"), request
.getUri());
} else {
url = new URL(target, request.getUri());
url = new URL(target.toURL(), request.getUri());
}
FetchOptions options = disallowTruncate();

View File

@ -24,7 +24,7 @@
package org.jclouds.gae.config;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import org.jclouds.gae.URLFetchServiceClient;
import org.jclouds.http.HttpConstants;
@ -54,13 +54,13 @@ public class URLFetchServiceClientModule extends AbstractModule {
@Singleton
@Provides
protected URL provideAddress(
@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
throws MalformedURLException {
protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
throws MalformedURLException {
return new URL(isSecure ? "https" : "http", address, port, "/");
return URI.create(String.format("%1$s://%2$s:%3$s", isSecure ? "https" : "http", address,
port));
}
@Provides

View File

@ -33,7 +33,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -59,12 +59,12 @@ import com.google.appengine.api.urlfetch.URLFetchService;
@Test
public class URLFetchServiceClientTest {
URLFetchServiceClient client;
URL url;
URI endPoint;
@BeforeTest
void setupClient() throws MalformedURLException {
url = new URL("http://localhost:80");
client = new URLFetchServiceClient(80, false, url, createNiceMock(URLFetchService.class));
endPoint = URI.create("http://localhost:80");
client = new URLFetchServiceClient(endPoint, createNiceMock(URLFetchService.class));
}
@Test
@ -101,21 +101,21 @@ public class URLFetchServiceClientTest {
@Test
void testConvertRequestGetsTargetAndUri() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
HTTPRequest gaeRequest = client.convert(request);
assertEquals(gaeRequest.getURL().getPath(), "/foo");
}
@Test
void testConvertRequestSetsFetchOptions() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
HTTPRequest gaeRequest = client.convert(request);
assert gaeRequest.getFetchOptions() != null;
}
@Test
void testConvertRequestSetsHeaders() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
request.getHeaders().put("foo", "bar");
HTTPRequest gaeRequest = client.convert(request);
assertEquals(gaeRequest.getHeaders().get(0).getName(), "foo");
@ -124,7 +124,7 @@ public class URLFetchServiceClientTest {
@Test
void testConvertRequestNoContent() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
HTTPRequest gaeRequest = client.convert(request);
assert gaeRequest.getPayload() == null;
assertEquals(gaeRequest.getHeaders().size(), 1);// content length
@ -132,28 +132,28 @@ public class URLFetchServiceClientTest {
@Test
void testConvertRequestStringContent() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
request.setPayload("hoot!");
testHoot(request);
}
@Test
void testConvertRequestInputStreamContent() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
request.setPayload(IOUtils.toInputStream("hoot!"));
testHoot(request);
}
@Test
void testConvertRequestBytesContent() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
request.setPayload("hoot!".getBytes());
testHoot(request);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
void testConvertRequestBadContent() throws IOException {
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
request.setPayload(new Date());
client.convert(request);
@ -165,7 +165,7 @@ public class URLFetchServiceClientTest {
File file = new File(basedir, "target/testfiles/hoot");
file.getParentFile().mkdirs();
IOUtils.write("hoot!", new FileOutputStream(file));
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HttpRequest request = new HttpRequest(endPoint, HttpMethod.GET, "foo");
request.setPayload(file);
testHoot(request);
}

View File

@ -26,7 +26,6 @@ package org.jclouds.gae.config;
import java.util.Properties;
import org.jclouds.gae.URLFetchServiceClient;
import org.jclouds.gae.config.URLFetchServiceClientModule;
import org.jclouds.http.HttpConstants;
import org.jclouds.http.HttpFutureCommandClient;
import org.testng.annotations.Test;
@ -43,21 +42,20 @@ import com.google.inject.name.Names;
@Test
public class URLFetchServiceClientModuleTest {
public void testConfigureBindsClient() {
final Properties properties = new Properties();
properties.put(HttpConstants.PROPERTY_HTTP_ADDRESS, "localhost");
properties.put(HttpConstants.PROPERTY_HTTP_PORT, "8088");
properties.put(HttpConstants.PROPERTY_HTTP_SECURE, "false");
public void testConfigureBindsClient() {
final Properties properties = new Properties();
properties.put(HttpConstants.PROPERTY_HTTP_ADDRESS, "localhost");
properties.put(HttpConstants.PROPERTY_HTTP_PORT, "8088");
properties.put(HttpConstants.PROPERTY_HTTP_SECURE, "false");
Injector i = Guice.createInjector(new URLFetchServiceClientModule() {
@Override
protected void configure() {
Names.bindProperties(binder(), properties);
super.configure();
}
});
HttpFutureCommandClient client = i
.getInstance(HttpFutureCommandClient.class);
assert client instanceof URLFetchServiceClient;
}
Injector i = Guice.createInjector(new URLFetchServiceClientModule() {
@Override
protected void configure() {
Names.bindProperties(binder(), properties);
super.configure();
}
});
HttpFutureCommandClient client = i.getInstance(HttpFutureCommandClient.class);
assert client instanceof URLFetchServiceClient;
}
}

View File

@ -24,6 +24,8 @@
package org.jclouds.http.httpnio.config;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URI;
import org.jclouds.http.HttpConstants;
import org.jclouds.http.HttpFutureCommandClient;
@ -45,26 +47,33 @@ import com.google.inject.name.Named;
@HttpFutureCommandClientModule
public class HttpNioConnectionPoolClientModule extends AbstractModule {
@Named(HttpConstants.PROPERTY_HTTP_SECURE)
boolean isSecure;
@Named(HttpConstants.PROPERTY_HTTP_SECURE)
boolean isSecure;
@Override
protected void configure() {
requestInjection(this);
if (isSecure)
install(new SSLHttpNioConnectionPoolClientModule());
else
install(new NonSSLHttpNioConnectionPoolClientModule());
bind(HttpFutureCommandClient.class).to(
HttpNioConnectionPoolClient.class);
}
@Override
protected void configure() {
requestInjection(this);
if (isSecure)
install(new SSLHttpNioConnectionPoolClientModule());
else
install(new NonSSLHttpNioConnectionPoolClientModule());
bind(HttpFutureCommandClient.class).to(HttpNioConnectionPoolClient.class);
}
@Singleton
@Provides
protected InetSocketAddress provideAddress(
@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port) {
return new InetSocketAddress(address, port);
}
@Singleton
@Provides
protected InetSocketAddress provideAddress(URI endPoint) {
return new InetSocketAddress(endPoint.getHost(), endPoint.getPort());
}
@Singleton
@Provides
protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
throws MalformedURLException {
return URI.create(String.format("%1$s://%2$s:%3$s", isSecure ? "https" : "http", address,
port));
}
}