Issue 58 switch to path requests

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1084 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-07 11:18:11 +00:00
parent 0c9b3accda
commit c6da1b86b7
14 changed files with 224 additions and 272 deletions

View File

@ -35,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;
/**
* Issues a HEAD command to determine if the bucket exists or not.
@ -45,42 +44,38 @@ 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("HEAD", "/" + maxResults(0).buildQueryString(), callable,
amazonHost, s3Bucket);
}
@Inject
public BucketExists(ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super("HEAD", "/" + maxResults(0).buildQueryString(), callable, s3Bucket);
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null
&& e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e
.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return false;
}
}
throw e;
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return false;
}
}
throw e;
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
}

View File

@ -33,20 +33,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
@ -56,23 +55,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("PUT",
"/" + checkNotNull(destinationObject, "destinationObject"),
callable, amazonHost, destinationBucket);
public CopyObject(ParseSax<S3Object.Metadata> callable,
@Assisted("sourceBucket") String sourceBucket,
@Assisted("sourceObject") String sourceObject,
@Assisted("destinationBucket") String destinationBucket,
@Assisted("destinationObject") String destinationObject,
@Assisted CopyObjectOptions options) {
super("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

@ -34,59 +34,54 @@ 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 be deleted before the bucket itself can be deleted.
* The DELETE request operation deletes the bucket named in the URI. All objects in the bucket must
* be deleted before the bucket itself can be deleted.
* <p />
* Only the owner of a bucket can delete it, regardless of the bucket's access
* control policy.
* Only the owner of a bucket can delete it, regardless of the bucket's access control policy.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketDELETE.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketDELETE.html"
* />
* @author Adrian Cole
*/
public class DeleteBucket extends S3FutureCommand<Boolean> {
@Inject
public DeleteBucket(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super("DELETE", "/", callable, amazonHost, s3Bucket);
}
@Inject
public DeleteBucket(ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super("DELETE", "/", callable, s3Bucket);
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null
&& e.getCause() instanceof HttpResponseException) {
AWSResponseException responseException = (AWSResponseException) e
.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return true;
} else if ("BucketNotEmpty".equals(responseException.getError()
.getCode())) {
return false;
}
}
throw e;
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return true;
} else if ("BucketNotEmpty".equals(responseException.getError().getCode())) {
return false;
}
}
throw e;
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
}

View File

@ -29,11 +29,10 @@ 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 no method to restore or undelete an object.
* The DELETE request operation removes the specified object from Amazon S3. Once deleted, there is
* no method to restore or undelete an object.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?
* RESTObjectDELETE.html" />
@ -41,10 +40,9 @@ import com.google.inject.name.Named;
*/
public class DeleteObject extends S3FutureCommand<Boolean> {
@Inject
public DeleteObject(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted("key") String key) {
super("DELETE", "/" + checkNotNull(key), callable, amazonHost, bucket);
}
@Inject
public DeleteObject(ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted("key") String key) {
super("DELETE", "/" + checkNotNull(key), callable, bucket);
}
}

View File

@ -35,7 +35,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,20 +48,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,
@Assisted("bucketName") String bucket)
{
super("GET", "/?acl", accessControlListParser, amazonHost, bucket);
public GetAccessControlList(ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket) {
super("GET", "/?acl", accessControlListParser, bucket);
}
@Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket,
@Assisted("objectKey") String objectKey)
{
super("GET", "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
public GetAccessControlList(ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
super("GET", "/" + objectKey + "?acl", accessControlListParser, bucket);
}
@Override
@ -79,8 +73,7 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause();
if ("NoSuchBucket".equals(responseException.getError().getCode())
|| "NoSuchObject".equals(responseException.getError().getCode()))
{
|| "NoSuchObject".equals(responseException.getError().getCode())) {
return AccessControlList.NOT_FOUND;
}
}
@ -88,8 +81,8 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
}
@Override
public AccessControlList get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
public AccessControlList get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {

View File

@ -37,7 +37,6 @@ import org.jclouds.aws.s3.domain.S3Object;
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;
@ -65,10 +64,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("GET", "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
public GetObject(ParseObjectFromHeadersAndHttpContent callable,
@Assisted("bucketName") String s3Bucket, @Assisted("key") String key,
@Assisted GetObjectOptions options) {
super("GET", "/" + checkNotNull(key), callable, s3Bucket);
this.getRequest().getHeaders().putAll(options.buildRequestHeaders());
callable.setKey(key);
}

View File

@ -36,65 +36,59 @@ 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
* {@link org.jclouds.aws.s3.domain.S3Object.Metadata#NOT_FOUND} if not available.
*
* <p/>
* The HEAD operation is used to retrieve information about a specific object or
* object size, without actually fetching the object itself. This is useful if
* you're only interested in the object metadata, and don't want to waste
* bandwidth on the object data.
* The HEAD operation is used to retrieve information about a specific object or object size,
* without actually fetching the object itself. This is useful if you're only interested in the
* object metadata, and don't want to waste bandwidth on the object data.
*
* @see GetObject
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectHEAD.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectHEAD.html"
* />
* @author Adrian Cole
*
*/
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("HEAD", "/" + checkNotNull(key), callable, amazonHost, bucket);
callable.setKey(key);
}
@Inject
public HeadObject(ParseMetadataFromHeaders callable, @Assisted("bucketName") String bucket,
@Assisted("key") String key) {
super("HEAD", "/" + checkNotNull(key), callable, bucket);
callable.setKey(key);
}
@Override
public S3Object.Metadata get() throws InterruptedException,
ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public S3Object.Metadata get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@VisibleForTesting
S3Object.Metadata attemptNotFound(ExecutionException e)
throws ExecutionException {
if (e.getCause() != null
&& e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e
.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return S3Object.Metadata.NOT_FOUND;
}
}
throw e;
}
@VisibleForTesting
S3Object.Metadata attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return S3Object.Metadata.NOT_FOUND;
}
}
throw e;
}
@Override
public S3Object.Metadata get(long l, TimeUnit timeUnit)
throws InterruptedException, ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public S3Object.Metadata get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
}

View File

@ -37,7 +37,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 +55,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(ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
@Assisted ListBucketOptions options) {
super("GET", "/" + options.buildQueryString(), bucketParser, amazonHost, bucket);
super("GET", "/" + options.buildQueryString(), bucketParser, bucket);
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
handler.setBucketName(bucket);
}

View File

@ -29,23 +29,21 @@ import org.jclouds.aws.s3.domain.S3Bucket;
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.
* Returns a list of all of the buckets owned by the authenticated sender of the request.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* />
* @author Adrian Cole
*
*/
public class ListOwnedBuckets extends S3FutureCommand<List<S3Bucket.Metadata>> {
@Inject
public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost,
ParseSax<List<S3Bucket.Metadata>> callable) {
super("GET", "/", callable, amazonHost);
}
@Inject
public ListOwnedBuckets(ParseSax<List<S3Bucket.Metadata>> callable) {
super("GET", "/", callable);
}
}

View File

@ -30,36 +30,35 @@ import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
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.
* <p/>
* The PUT request operation with a bucket URI creates a new bucket. Depending
* on your latency and legal requirements, you can specify a location constraint
* that will affect where your data physically resides. You can currently
* specify a Europe (EU) location constraint via {@link PutBucketOptions}.
* The PUT request operation with a bucket URI creates a new bucket. Depending on your latency and
* legal requirements, you can specify a location constraint that will affect where your data
* physically resides. You can currently specify a Europe (EU) location constraint via
* {@link PutBucketOptions}.
*
* @see PutBucketOptions
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketPUT.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTBucketPUT.html"
* />
* @author Adrian Cole
*
*/
public class PutBucket extends S3FutureCommand<Boolean> {
@Inject
public PutBucket(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted String bucketName,
@Assisted PutBucketOptions options) {
super("PUT", "/", callable, amazonHost, S3Utils
.validateBucketName(bucketName));
getRequest().getHeaders().putAll(options.buildRequestHeaders());
String payload = options.buildPayload();
if (payload != null) {
getRequest().setPayload(payload);
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH,
payload.getBytes().length + "");
}
}
@Inject
public PutBucket(ReturnTrueIf2xx callable, @Assisted String bucketName,
@Assisted PutBucketOptions options) {
super("PUT", "/", callable, S3Utils.validateBucketName(bucketName));
getRequest().getHeaders().putAll(options.buildRequestHeaders());
String payload = options.buildPayload();
if (payload != null) {
getRequest().setPayload(payload);
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, payload.getBytes().length + "");
} else {
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, "0");
}
}
}

View File

@ -34,7 +34,6 @@ import org.jclouds.http.HttpHeaders;
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.
@ -43,56 +42,53 @@ import com.google.inject.name.Named;
* This returns a byte[] of the md5 hash of what Amazon S3 received
* <p />
* <p/>
* This command allows you to specify {@link PutObjectOptions} to control
* delivery of content.
* This command allows you to specify {@link PutObjectOptions} to control delivery of content.
*
*
* @see PutObjectOptions
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectPUT.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectPUT.html"
* />
* @author Adrian Cole
*/
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("PUT", "/" + checkNotNull(object.getKey()), callable, amazonHost,
s3Bucket);
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
@Inject
public PutObject(ParseMd5FromETagHeader callable, @Assisted String s3Bucket,
@Assisted S3Object object, @Assisted PutObjectOptions options) {
super("PUT", "/" + checkNotNull(object.getKey()), callable, s3Bucket);
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
getRequest().setPayload(
checkNotNull(object.getData(), "object.getContent()"));
getRequest().setPayload(checkNotNull(object.getData(), "object.getContent()"));
getRequest().getHeaders().put(
HttpHeaders.CONTENT_TYPE,
checkNotNull(object.getMetadata().getContentType(),
"object.metadata.contentType()"));
getRequest().getHeaders()
.put(
HttpHeaders.CONTENT_TYPE,
checkNotNull(object.getMetadata().getContentType(),
"object.metadata.contentType()"));
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH,
object.getMetadata().getSize() + "");
getRequest().getHeaders()
.put(HttpHeaders.CONTENT_LENGTH, object.getMetadata().getSize() + "");
if (object.getMetadata().getCacheControl() != null) {
getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL,
object.getMetadata().getCacheControl());
}
if (object.getMetadata().getContentDisposition() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_DISPOSITION,
object.getMetadata().getContentDisposition());
}
if (object.getMetadata().getContentEncoding() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_ENCODING,
object.getMetadata().getContentEncoding());
}
if (object.getMetadata().getCacheControl() != null) {
getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL,
object.getMetadata().getCacheControl());
}
if (object.getMetadata().getContentDisposition() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_DISPOSITION,
object.getMetadata().getContentDisposition());
}
if (object.getMetadata().getContentEncoding() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_ENCODING,
object.getMetadata().getContentEncoding());
}
if (object.getMetadata().getMd5() != null)
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
S3Utils.toBase64String(object.getMetadata().getMd5()));
if (object.getMetadata().getMd5() != null)
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
S3Utils.toBase64String(object.getMetadata().getMd5()));
getRequest().getHeaders()
.putAll(object.getMetadata().getUserMetadata());
getRequest().getHeaders().putAll(options.buildRequestHeaders());
getRequest().getHeaders().putAll(object.getMetadata().getUserMetadata());
getRequest().getHeaders().putAll(options.buildRequestHeaders());
}
}
}

View File

@ -33,7 +33,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.
@ -122,32 +121,29 @@ public class S3CommandFactory {
return headMetadataFactory.create(bucket, key);
}
@Inject
@Named("jclouds.http.address")
String amazonHost;
public ListOwnedBuckets createGetMetadataForOwnedBuckets() {
return new ListOwnedBuckets(amazonHost, parserFactory.createListBucketsParser());
return new ListOwnedBuckets(parserFactory.createListBucketsParser());
}
public ListBucket createListBucket(String bucket, ListBucketOptions options) {
return new ListBucket(amazonHost, parserFactory.createListBucketParser(), bucket, options);
return new ListBucket(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(parserFactory.createCopyObjectParser(), sourceBucket,
sourceObject, destinationBucket, destinationObject, options);
}
public GetAccessControlList createGetBucketACL(String bucket) {
return new GetAccessControlList(
amazonHost, parserFactory.createAccessControlListParser(), bucket);
parserFactory.createAccessControlListParser(), bucket);
}
public GetAccessControlList createGetObjectACL(String bucket, String objectKey) {
return new GetAccessControlList(
amazonHost, parserFactory.createAccessControlListParser(), bucket, objectKey);
parserFactory.createAccessControlListParser(), bucket, objectKey);
}
}

View File

@ -37,19 +37,13 @@ import org.jclouds.http.HttpFutureCommand;
public class S3FutureCommand<T> extends HttpFutureCommand<T> {
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
String amazonHost, String bucketName) {
super(method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull(bucketName, "bucketName"));
String bucketName) {
super(method, String.format("/%1$s%2$s", checkNotNull(bucketName, "bucketName"),
checkNotNull(uri, "uri")), responseCallable);
}
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
String amazonHost) {
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable) {
super(method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"));
}
protected void addHostHeader(String amazonHost, String bucketName) {
addHostHeader(checkNotNull(bucketName) + "." + amazonHost);
}
}

View File

@ -158,9 +158,10 @@ public class RequestAuthorizeSignature implements HttpRequestFilter {
}
private static void appendBucketName(HttpRequest request, StringBuilder toSign) {
String hostHeader = request.getHeaders().get(HttpHeaders.HOST).iterator().next();
if (hostHeader.endsWith(".s3.amazonaws.com"))
String hostHeader = request.getFirstHeaderOrNull(HttpHeaders.HOST);
if (hostHeader != null && hostHeader.endsWith(".s3.amazonaws.com")) {
toSign.append("/").append(hostHeader.substring(0, hostHeader.length() - 17));
}
}
private static void appendUriPath(HttpRequest request, StringBuilder toSign) {
@ -173,21 +174,21 @@ public class RequestAuthorizeSignature implements HttpRequestFilter {
} else {
toSign.append(request.getUri());
}
// ...however, there are a few exceptions that must be included in the signed URI.
if (paramsString != null) {
StringBuilder paramsToSign = new StringBuilder("?");
String[] params = paramsString.split("&");
for (String param : params) {
String[] paramNameAndValue = param.split("=");
if ("acl".equals(paramNameAndValue[0])) {
paramsToSign.append("acl");
}
// TODO: Other special cases not yet handled: torrent, logging, location, requestPayment
}
if (paramsToSign.length() > 1) {
toSign.append(paramsToSign);
}