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

View File

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

View File

@ -23,6 +23,7 @@
*/ */
package org.jclouds.aws.s3.commands; package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -34,7 +35,6 @@ import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; 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 * 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> { public class DeleteBucket extends S3FutureCommand<Boolean> {
@Inject @Inject
public DeleteBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable, public DeleteBucket(URI endPoint, ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
@Assisted String s3Bucket) { super(endPoint, HttpMethod.DELETE, "/", callable, s3Bucket);
super(HttpMethod.DELETE, "/", callable, amazonHost, s3Bucket);
} }
@Override @Override

View File

@ -25,12 +25,13 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.http.HttpMethod; import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx; import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; 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 * 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> { public class DeleteObject extends S3FutureCommand<Boolean> {
@Inject @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) { @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; package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -35,7 +36,6 @@ import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; 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 * 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> { public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
@Inject @Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost, public GetAccessControlList(URI endPoint, ParseSax<AccessControlList> accessControlListParser,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket) { @Assisted("bucketName") String bucket) {
super(HttpMethod.GET, "/?acl", accessControlListParser, amazonHost, bucket); super(endPoint, HttpMethod.GET, "/?acl", accessControlListParser, bucket);
} }
@Inject @Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost, public GetAccessControlList(URI endPoint, ParseSax<AccessControlList> accessControlListParser,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) { @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 @Override

View File

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

View File

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

View File

@ -23,6 +23,7 @@
*/ */
package org.jclouds.aws.s3.commands; package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -37,7 +38,6 @@ import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; 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. * 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> { public class ListBucket extends S3FutureCommand<S3Bucket> {
@Inject @Inject
public ListBucket(@Named("jclouds.http.address") String amazonHost, public ListBucket(URI endPoint, ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
@Assisted ListBucketOptions options) { @Assisted ListBucketOptions options) {
super(HttpMethod.GET, "/" + options.buildQueryString(), bucketParser, amazonHost, bucket); super(endPoint, HttpMethod.GET, "/" + options.buildQueryString(), bucketParser, bucket);
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler(); ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
handler.setBucketName(bucket); handler.setBucketName(bucket);
} }

View File

@ -23,6 +23,7 @@
*/ */
package org.jclouds.aws.s3.commands; package org.jclouds.aws.s3.commands;
import java.net.URI;
import java.util.List; import java.util.List;
import org.jclouds.aws.s3.domain.S3Bucket; 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 org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.inject.Inject; 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. * 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>> { public class ListOwnedBuckets extends S3FutureCommand<List<S3Bucket.Metadata>> {
@Inject @Inject
public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost, public ListOwnedBuckets(URI endPoint, ParseSax<List<S3Bucket.Metadata>> callable) {
ParseSax<List<S3Bucket.Metadata>> callable) { super(endPoint, HttpMethod.GET, "/", callable);
super(HttpMethod.GET, "/", callable, amazonHost);
} }
} }

View File

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

View File

@ -23,6 +23,8 @@
*/ */
package org.jclouds.aws.s3.commands; package org.jclouds.aws.s3.commands;
import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.jclouds.aws.s3.domain.AccessControlList; 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.Inject;
import com.google.inject.assistedinject.Assisted; 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 * 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; protected Logger logger = Logger.NULL;
@Inject @Inject
public PutBucketAccessControlList(@Named("jclouds.http.address") String amazonHost, public PutBucketAccessControlList(URI endPoint, ReturnTrueIf2xx callable,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket, @Assisted("bucketName") String bucket, @Assisted AccessControlList acl) {
@Assisted AccessControlList acl) { super(endPoint, HttpMethod.PUT, "/?acl", callable, bucket);
super(HttpMethod.PUT, "/?acl", callable, amazonHost, bucket);
String aclPayload = ""; String aclPayload = "";
try { 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.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; 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.callables.ParseMd5FromETagHeader;
import org.jclouds.aws.s3.commands.options.PutObjectOptions; import org.jclouds.aws.s3.commands.options.PutObjectOptions;
import org.jclouds.aws.s3.domain.S3Object; 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.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/** /**
* Store data by creating or overwriting an object. * Store data by creating or overwriting an object.
@ -56,10 +57,9 @@ import com.google.inject.name.Named;
public class PutObject extends S3FutureCommand<byte[]> { public class PutObject extends S3FutureCommand<byte[]> {
@Inject @Inject
public PutObject(@Named("jclouds.http.address") String amazonHost, public PutObject(URI endPoint, ParseMd5FromETagHeader callable, @Assisted String s3Bucket,
ParseMd5FromETagHeader callable, @Assisted String s3Bucket, @Assisted S3Object object, @Assisted S3Object object, @Assisted PutObjectOptions options) {
@Assisted PutObjectOptions options) { super(endPoint, HttpMethod.PUT, "/" + checkNotNull(object.getKey()), callable, s3Bucket);
super(HttpMethod.PUT, "/" + checkNotNull(object.getKey()), callable, amazonHost, s3Bucket);
checkArgument(object.getMetadata().getSize() >= 0, "size must be set"); checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
getRequest().setPayload(checkNotNull(object.getData(), "object.getContent()")); getRequest().setPayload(checkNotNull(object.getData(), "object.getContent()"));

View File

@ -23,6 +23,8 @@
*/ */
package org.jclouds.aws.s3.commands; package org.jclouds.aws.s3.commands;
import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.jclouds.aws.s3.domain.AccessControlList; 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.Inject;
import com.google.inject.assistedinject.Assisted; 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 * 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; protected Logger logger = Logger.NULL;
@Inject @Inject
public PutObjectAccessControlList(@Named("jclouds.http.address") String amazonHost, public PutObjectAccessControlList(URI endPoint, ReturnTrueIf2xx callable,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket, @Assisted("bucketName") String bucket, @Assisted("key") String objectKey,
@Assisted("key") String objectKey, @Assisted AccessControlList acl) { @Assisted AccessControlList acl) {
super(HttpMethod.PUT, "/" + objectKey + "?acl", callable, amazonHost, bucket); super(endPoint, HttpMethod.PUT, "/" + objectKey + "?acl", callable, bucket);
String aclPayload = ""; String aclPayload = "";
try { try {

View File

@ -23,6 +23,8 @@
*/ */
package org.jclouds.aws.s3.commands; 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.CopyObjectOptions;
import org.jclouds.aws.s3.commands.options.GetObjectOptions; import org.jclouds.aws.s3.commands.options.GetObjectOptions;
import org.jclouds.aws.s3.commands.options.ListBucketOptions; 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.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/** /**
* Assembles the command objects for S3. * Assembles the command objects for S3.
@ -124,58 +125,53 @@ public class S3CommandFactory {
} }
@Inject @Inject
@Named("jclouds.http.address") URI endPoint;
String amazonHost;
public ListOwnedBuckets createGetMetadataForOwnedBuckets() { public ListOwnedBuckets createGetMetadataForOwnedBuckets() {
return new ListOwnedBuckets(amazonHost, parserFactory.createListBucketsParser()); return new ListOwnedBuckets(endPoint, parserFactory.createListBucketsParser());
} }
public ListBucket createListBucket(String bucket, ListBucketOptions options) { 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, public CopyObject createCopyObject(String sourceBucket, String sourceObject,
String destinationBucket, String destinationObject, CopyObjectOptions options) { String destinationBucket, String destinationObject, CopyObjectOptions options) {
return new CopyObject(amazonHost, parserFactory.createCopyObjectParser(), sourceBucket, return new CopyObject(endPoint, parserFactory.createCopyObjectParser(), sourceBucket,
sourceObject, destinationBucket, destinationObject, options); sourceObject, destinationBucket, destinationObject, options);
} }
public GetAccessControlList createGetBucketACL(String bucket) { public GetAccessControlList createGetBucketACL(String bucket) {
return new GetAccessControlList( return new GetAccessControlList(endPoint, parserFactory.createAccessControlListParser(),
amazonHost, parserFactory.createAccessControlListParser(), bucket); bucket);
} }
public GetAccessControlList createGetObjectACL(String bucket, String objectKey) { public GetAccessControlList createGetObjectACL(String bucket, String objectKey) {
return new GetAccessControlList( return new GetAccessControlList(endPoint, parserFactory.createAccessControlListParser(),
amazonHost, parserFactory.createAccessControlListParser(), bucket, objectKey); bucket, objectKey);
} }
@Inject @Inject
private PutBucketAccessControlListFactory putBucketAccessControlListFactory; private PutBucketAccessControlListFactory putBucketAccessControlListFactory;
public static interface PutBucketAccessControlListFactory { public static interface PutBucketAccessControlListFactory {
PutBucketAccessControlList create(@Assisted("bucketName") String bucket, PutBucketAccessControlList create(@Assisted("bucketName") String bucket, AccessControlList acl);
AccessControlList acl);
} }
public PutBucketAccessControlList createPutBucketACL(String bucket, AccessControlList acl) { public PutBucketAccessControlList createPutBucketACL(String bucket, AccessControlList acl) {
return putBucketAccessControlListFactory.create(bucket, acl); return putBucketAccessControlListFactory.create(bucket, acl);
} }
@Inject @Inject
private PutObjectAccessControlListFactory putObjectAccessControlListFactory; private PutObjectAccessControlListFactory putObjectAccessControlListFactory;
public static interface PutObjectAccessControlListFactory { public static interface PutObjectAccessControlListFactory {
PutObjectAccessControlList create(@Assisted("bucketName") String bucket, PutObjectAccessControlList create(@Assisted("bucketName") String bucket,
@Assisted("key") String objectKey, AccessControlList acl); @Assisted("key") String objectKey, AccessControlList acl);
} }
public PutObjectAccessControlList createPutObjectACL(String bucket, String objectKey, public PutObjectAccessControlList createPutObjectACL(String bucket, String objectKey,
AccessControlList acl) AccessControlList acl) {
{
return putObjectAccessControlListFactory.create(bucket, objectKey, 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 static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod; import org.jclouds.http.HttpMethod;
@ -37,16 +39,16 @@ import org.jclouds.http.HttpMethod;
*/ */
public class S3FutureCommand<T> extends HttpFutureCommand<T> { public class S3FutureCommand<T> extends HttpFutureCommand<T> {
public S3FutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable, public S3FutureCommand(URI endPoint, HttpMethod method, String uri,
String amazonHost, String bucketName) { ResponseCallable<T> responseCallable, String bucketName) {
super(method, uri, responseCallable); super(endPoint, method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull(bucketName, "bucketName")); addHostHeader(endPoint.getHost(), checkNotNull(bucketName, "bucketName"));
} }
public S3FutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable, public S3FutureCommand(URI endPoint, HttpMethod method, String uri,
String amazonHost) { ResponseCallable<T> responseCallable) {
super(method, uri, responseCallable); super(endPoint, method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost")); addHostHeader(endPoint.getHost());
} }
protected void addHostHeader(String amazonHost, String bucketName) { 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.createMock;
import static org.easymock.classextension.EasyMock.replay; 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.config.S3CommandsModule;
import org.jclouds.aws.s3.commands.options.CopyObjectOptions; import org.jclouds.aws.s3.commands.options.CopyObjectOptions;
import org.jclouds.aws.s3.commands.options.GetObjectOptions; 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.common.collect.Multimap;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.name.Names;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -60,7 +61,7 @@ public class S3CommandFactoryTest {
injector = Guice.createInjector(new S3ParserModule(), new S3CommandsModule() { injector = Guice.createInjector(new S3ParserModule(), new S3CommandsModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Names.named("jclouds.http.address")).to("localhost"); bind(URI.class).toInstance(URI.create("http://localhost:8080"));
super.configure(); super.configure();
} }
}); });

View File

@ -23,6 +23,8 @@
*/ */
package org.jclouds.aws.s3.config; package org.jclouds.aws.s3.config;
import java.net.URI;
import org.jclouds.aws.s3.S3Connection; import org.jclouds.aws.s3.S3Connection;
import org.jclouds.aws.s3.StubS3Connection; import org.jclouds.aws.s3.StubS3Connection;
@ -37,5 +39,6 @@ import com.google.inject.AbstractModule;
public class StubS3ConnectionModule extends AbstractModule { public class StubS3ConnectionModule extends AbstractModule {
protected void configure() { protected void configure() {
bind(S3Connection.class).to(StubS3Connection.class); 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 static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.commons.io.IOUtils; 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 class HttpFutureCommand<T> extends FutureCommand<HttpRequest, HttpResponse, T> {
public HttpFutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable) { public HttpFutureCommand(URI endPoint, HttpMethod method, String uri,
super(new HttpRequest(checkNotNull(method, "method"), checkNotNull(uri, "uri")), ResponseCallable<T> responseCallable) {
responseCallable); super(new HttpRequest(checkNotNull(endPoint, "endPoint"), checkNotNull(method, "method"),
checkNotNull(uri, "uri")), responseCallable);
} }
protected void addHostHeader(String host) { protected void addHostHeader(String host) {
getRequest().getHeaders().put("Host", host); getRequest().getHeaders().put(HttpHeaders.HOST, host);
} }
@Override @Override

View File

@ -26,6 +26,7 @@ package org.jclouds.http;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -39,6 +40,7 @@ import org.jclouds.util.Utils;
*/ */
public class HttpRequest extends HttpMessage { public class HttpRequest extends HttpMessage {
private URI endPoint;
private final HttpMethod method; private final HttpMethod method;
private final String uri; private final String uri;
Object payload; Object payload;
@ -46,7 +48,16 @@ public class HttpRequest extends HttpMessage {
@Resource @Resource
protected Logger logger = Logger.NULL; 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.method = checkNotNull(method, "method");
this.uri = Utils.encodeUriPath(checkNotNull(uri, "uri")); this.uri = Utils.encodeUriPath(checkNotNull(uri, "uri"));
} }
@ -55,7 +66,8 @@ public class HttpRequest extends HttpMessage {
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("HttpRequest"); 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(", uri='").append(uri).append('\'');
sb.append(", headers=").append(headers); sb.append(", headers=").append(headers);
sb.append(", payload set=").append(payload != null); sb.append(", payload set=").append(payload != null);
@ -88,4 +100,12 @@ public class HttpRequest extends HttpMessage {
this.payload = content; 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); 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) { public GetAndParseSax<?> createGetAndParseSax(String uri, ParseSax.HandlerWithResult<?> handler) {
return new GetAndParseSax(uri, parseSaxFactory.create(handler)); return getAndParseSaxFactory.create(uri, parseSaxFactory.create(handler));
} }
@Inject @Inject

View File

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

View File

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

View File

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

View File

@ -24,6 +24,7 @@
package org.jclouds.http.commands.config; package org.jclouds.http.commands.config;
import org.jclouds.http.commands.CommandFactory; import org.jclouds.http.commands.CommandFactory;
import org.jclouds.http.commands.GetAndParseSax;
import org.jclouds.http.commands.GetString; import org.jclouds.http.commands.GetString;
import org.jclouds.http.commands.Head; import org.jclouds.http.commands.Head;
import org.jclouds.http.commands.Put; import org.jclouds.http.commands.Put;
@ -54,6 +55,10 @@ public class HttpCommandsModule extends AbstractModule {
FactoryProvider.newFactory(new TypeLiteral<CommandFactory.ParseSaxFactory>() { FactoryProvider.newFactory(new TypeLiteral<CommandFactory.ParseSaxFactory>() {
}, new TypeLiteral<ParseSax<?>>() { }, 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; package org.jclouds.http.config;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URI;
import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpConstants;
import org.jclouds.http.HttpFutureCommandClient; import org.jclouds.http.HttpFutureCommandClient;
@ -43,26 +43,25 @@ import com.google.inject.name.Named;
@HttpFutureCommandClientModule @HttpFutureCommandClientModule
public class JavaUrlHttpFutureCommandClientModule extends AbstractModule { public class JavaUrlHttpFutureCommandClientModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
bindClient(); bindClient();
} }
protected void bindClient() { protected void bindClient() {
// note this is not threadsafe, so it cannot be singleton // note this is not threadsafe, so it cannot be singleton
bind(HttpFutureCommandClient.class).to( bind(HttpFutureCommandClient.class).to(JavaUrlHttpFutureCommandClient.class);
JavaUrlHttpFutureCommandClient.class); }
}
@Singleton @Singleton
@Provides @Provides
protected URL provideAddress( protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address, @Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port, @Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure) throws MalformedURLException {
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; package org.jclouds.http.internal;
import com.google.inject.Inject; import java.net.URI;
import org.jclouds.http.*; 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.ClientErrorHandler;
import org.jclouds.http.annotation.RedirectHandler; import org.jclouds.http.annotation.RedirectHandler;
import org.jclouds.http.annotation.RetryHandler; 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.http.handlers.CloseContentAndSetExceptionHandler;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import javax.annotation.Resource; import com.google.inject.Inject;
import java.net.URL;
import java.util.Collections;
import java.util.List;
public abstract class BaseHttpFutureCommandClient implements HttpFutureCommandClient { public abstract class BaseHttpFutureCommandClient implements HttpFutureCommandClient {
protected final URL target; protected final URI target;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -62,7 +69,7 @@ public abstract class BaseHttpFutureCommandClient implements HttpFutureCommandCl
protected HttpRetryHandler httpRetryHandler = new BackoffLimitedRetryHandler(5); protected HttpRetryHandler httpRetryHandler = new BackoffLimitedRetryHandler(5);
@Inject @Inject
public BaseHttpFutureCommandClient(URL target) { public BaseHttpFutureCommandClient(URI target) {
this.target = target; this.target = target;
} }

View File

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

View File

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

View File

@ -23,11 +23,14 @@
*/ */
package org.jclouds.http.commands.config; package org.jclouds.http.commands.config;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.commands.CommandFactory; import org.jclouds.http.commands.CommandFactory;
import org.jclouds.http.commands.callables.xml.ParseSax; import org.jclouds.http.commands.callables.xml.ParseSax;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -39,32 +42,44 @@ import com.google.inject.Injector;
@Test @Test
public class HttpCommandsModuleTest { public class HttpCommandsModuleTest {
public void testGetString() { public void testGetString() {
Injector i = Guice.createInjector(new HttpCommandsModule()); Injector i = createInjector();
CommandFactory factory = i.getInstance(CommandFactory.class); CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<String> get = factory.createGetString("/index.html"); HttpFutureCommand<String> get = factory.createGetString("/index.html");
assert get != null; assert get != null;
assert get.getResponseFuture() != null; assert get.getResponseFuture() != null;
} }
public void testHead() { private Injector createInjector() {
Injector i = Guice.createInjector(new HttpCommandsModule()); Injector i = Guice.createInjector(new HttpCommandsModule(), new AbstractModule() {
CommandFactory factory = i.getInstance(CommandFactory.class);
HttpFutureCommand<Boolean> Head = factory.createHead("/index.html");
assert Head != null;
assert Head.getResponseFuture() != null;
}
public void testGetAndParseXml() { @Override
Injector i = Guice.createInjector(new HttpCommandsModule()); protected void configure() {
CommandFactory factory = i.getInstance(CommandFactory.class); bind(URI.class).toInstance(URI.create("http://localhost:8080"));
HttpFutureCommand<?> GetAndParseXml = factory.createGetAndParseSax( }
"/index.html", new ParseSax.HandlerWithResult<String>() {
public String getResult() { });
return "hello"; return i;
} }
});
assert GetAndParseXml != null; public void testHead() {
assert GetAndParseXml.getResponseFuture() != null; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod; import org.jclouds.http.HttpMethod;
@ -37,6 +38,7 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "core.BackoffLimitedRetryHandler") @Test(groups = "unit", testName = "core.BackoffLimitedRetryHandler")
public class BackoffLimitedRetryHandlerTest { public class BackoffLimitedRetryHandlerTest {
private static final URI END_POINT = URI.create("http://localhost:8080");
BackoffLimitedRetryHandler handler = new BackoffLimitedRetryHandler(5); BackoffLimitedRetryHandler handler = new BackoffLimitedRetryHandler(5);
@ -77,8 +79,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test @Test
void testClosesInputStream() throws InterruptedException, IOException { void testClosesInputStream() throws InterruptedException, IOException {
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri", HttpFutureCommand<String> command = new HttpFutureCommand<String>(END_POINT, HttpMethod.HEAD,
new ReturnStringIf200()); "uri", new ReturnStringIf200());
HttpResponse response = new HttpResponse(); HttpResponse response = new HttpResponse();
InputStream inputStream = new InputStream() { InputStream inputStream = new InputStream() {
boolean isOpen = true; boolean isOpen = true;
@ -117,8 +119,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test @Test
void testIncrementsFailureCount() throws InterruptedException { void testIncrementsFailureCount() throws InterruptedException {
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri", HttpFutureCommand<String> command = new HttpFutureCommand<String>(END_POINT, HttpMethod.HEAD,
new ReturnStringIf200()); "uri", new ReturnStringIf200());
HttpResponse response = new HttpResponse(); HttpResponse response = new HttpResponse();
handler.retryRequest(command, response); handler.retryRequest(command, response);
@ -133,8 +135,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test @Test
void testDisallowsExcessiveRetries() throws InterruptedException { void testDisallowsExcessiveRetries() throws InterruptedException {
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri", HttpFutureCommand<String> command = new HttpFutureCommand<String>(END_POINT, HttpMethod.HEAD,
new ReturnStringIf200()); "uri", new ReturnStringIf200());
HttpResponse response = new HttpResponse(); HttpResponse response = new HttpResponse();
assertEquals(handler.retryRequest(command, response), true); // Failure 1 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.List; 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.appengine.api.urlfetch.URLFetchService;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.name.Named;
/** /**
* Google App Engine version of {@link HttpFutureCommandClient} * Google App Engine version of {@link HttpFutureCommandClient}
@ -64,13 +64,12 @@ public class URLFetchServiceClient extends BaseHttpFutureCommandClient {
private final boolean isSecure; private final boolean isSecure;
@Inject @Inject
public URLFetchServiceClient(@Named(HttpConstants.PROPERTY_HTTP_PORT) int port, public URLFetchServiceClient(URI target, URLFetchService urlFetchService)
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure, URL target, throws MalformedURLException {
URLFetchService urlFetchService) throws MalformedURLException {
super(target); super(target);
this.urlFetchService = urlFetchService; this.urlFetchService = urlFetchService;
this.port = port; this.port = target.getPort();
this.isSecure = isSecure; this.isSecure = target.getScheme().equals("https");
} }
public void submit(HttpFutureCommand<?> command) { 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 url = new URL(new URL(isSecure ? "https" : "http", hostHeader, port, "/"), request
.getUri()); .getUri());
} else { } else {
url = new URL(target, request.getUri()); url = new URL(target.toURL(), request.getUri());
} }
FetchOptions options = disallowTruncate(); FetchOptions options = disallowTruncate();

View File

@ -24,7 +24,7 @@
package org.jclouds.gae.config; package org.jclouds.gae.config;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URI;
import org.jclouds.gae.URLFetchServiceClient; import org.jclouds.gae.URLFetchServiceClient;
import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpConstants;
@ -54,13 +54,13 @@ public class URLFetchServiceClientModule extends AbstractModule {
@Singleton @Singleton
@Provides @Provides
protected URL provideAddress( protected URI provideAddress(@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address,
@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address, @Named(HttpConstants.PROPERTY_HTTP_PORT) int port,
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port, @Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure)
@Named(HttpConstants.PROPERTY_HTTP_SECURE) boolean isSecure) throws MalformedURLException {
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 @Provides

View File

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

View File

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

View File

@ -24,6 +24,8 @@
package org.jclouds.http.httpnio.config; package org.jclouds.http.httpnio.config;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URI;
import org.jclouds.http.HttpConstants; import org.jclouds.http.HttpConstants;
import org.jclouds.http.HttpFutureCommandClient; import org.jclouds.http.HttpFutureCommandClient;
@ -45,26 +47,33 @@ import com.google.inject.name.Named;
@HttpFutureCommandClientModule @HttpFutureCommandClientModule
public class HttpNioConnectionPoolClientModule extends AbstractModule { public class HttpNioConnectionPoolClientModule extends AbstractModule {
@Named(HttpConstants.PROPERTY_HTTP_SECURE) @Named(HttpConstants.PROPERTY_HTTP_SECURE)
boolean isSecure; boolean isSecure;
@Override @Override
protected void configure() { protected void configure() {
requestInjection(this); requestInjection(this);
if (isSecure) if (isSecure)
install(new SSLHttpNioConnectionPoolClientModule()); install(new SSLHttpNioConnectionPoolClientModule());
else else
install(new NonSSLHttpNioConnectionPoolClientModule()); install(new NonSSLHttpNioConnectionPoolClientModule());
bind(HttpFutureCommandClient.class).to( bind(HttpFutureCommandClient.class).to(HttpNioConnectionPoolClient.class);
HttpNioConnectionPoolClient.class); }
}
@Singleton @Singleton
@Provides @Provides
protected InetSocketAddress provideAddress( protected InetSocketAddress provideAddress(URI endPoint) {
@Named(HttpConstants.PROPERTY_HTTP_ADDRESS) String address, return new InetSocketAddress(endPoint.getHost(), endPoint.getPort());
@Named(HttpConstants.PROPERTY_HTTP_PORT) int port) { }
return new InetSocketAddress(address, port);
}
@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));
}
} }