mirror of https://github.com/apache/jclouds.git
Issue 58 reverted as path style bucket access is deprecated
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1087 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
445ca04c4e
commit
498c1dca20
|
@ -35,6 +35,7 @@ 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.
|
||||
|
@ -44,38 +45,42 @@ import com.google.inject.assistedinject.Assisted;
|
|||
*/
|
||||
public class BucketExists extends S3FutureCommand<Boolean> {
|
||||
|
||||
@Inject
|
||||
public BucketExists(ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
||||
super("HEAD", "/" + maxResults(0).buildQueryString(), callable, s3Bucket);
|
||||
}
|
||||
@Inject
|
||||
public BucketExists(@Named("jclouds.http.address") String amazonHost,
|
||||
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
||||
super("HEAD", "/" + maxResults(0).buildQueryString(), callable,
|
||||
amazonHost, 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,19 +33,20 @@ 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
|
||||
|
@ -55,20 +56,23 @@ import com.google.inject.assistedinject.Assisted;
|
|||
public class CopyObject extends S3FutureCommand<S3Object.Metadata> {
|
||||
|
||||
@Inject
|
||||
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);
|
||||
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);
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -34,54 +34,59 @@ 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(ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
||||
super("DELETE", "/", callable, s3Bucket);
|
||||
}
|
||||
@Inject
|
||||
public DeleteBucket(@Named("jclouds.http.address") String amazonHost,
|
||||
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
||||
super("DELETE", "/", callable, amazonHost, 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,10 +29,11 @@ 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" />
|
||||
|
@ -40,9 +41,10 @@ import com.google.inject.assistedinject.Assisted;
|
|||
*/
|
||||
public class DeleteObject extends S3FutureCommand<Boolean> {
|
||||
|
||||
@Inject
|
||||
public DeleteObject(ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
|
||||
@Assisted("key") String key) {
|
||||
super("DELETE", "/" + checkNotNull(key), callable, bucket);
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ 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
|
||||
|
@ -48,15 +49,20 @@ import com.google.inject.assistedinject.Assisted;
|
|||
public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
|
||||
|
||||
@Inject
|
||||
public GetAccessControlList(ParseSax<AccessControlList> accessControlListParser,
|
||||
@Assisted("bucketName") String bucket) {
|
||||
super("GET", "/?acl", accessControlListParser, bucket);
|
||||
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
|
||||
ParseSax<AccessControlList> accessControlListParser,
|
||||
@Assisted("bucketName") String bucket)
|
||||
{
|
||||
super("GET", "/?acl", accessControlListParser, amazonHost, bucket);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public GetAccessControlList(ParseSax<AccessControlList> accessControlListParser,
|
||||
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
|
||||
super("GET", "/" + objectKey + "?acl", accessControlListParser, bucket);
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,7 +79,8 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -81,8 +88,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) {
|
||||
|
|
|
@ -37,6 +37,7 @@ 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;
|
||||
|
@ -64,10 +65,10 @@ import com.google.inject.assistedinject.Assisted;
|
|||
public class GetObject extends S3FutureCommand<S3Object> {
|
||||
|
||||
@Inject
|
||||
public GetObject(ParseObjectFromHeadersAndHttpContent callable,
|
||||
@Assisted("bucketName") String s3Bucket, @Assisted("key") String key,
|
||||
@Assisted GetObjectOptions options) {
|
||||
super("GET", "/" + checkNotNull(key), callable, s3Bucket);
|
||||
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);
|
||||
this.getRequest().getHeaders().putAll(options.buildRequestHeaders());
|
||||
callable.setKey(key);
|
||||
}
|
||||
|
|
|
@ -36,59 +36,65 @@ 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(ParseMetadataFromHeaders callable, @Assisted("bucketName") String bucket,
|
||||
@Assisted("key") String key) {
|
||||
super("HEAD", "/" + checkNotNull(key), callable, bucket);
|
||||
callable.setKey(key);
|
||||
}
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,11 +31,13 @@ import org.jclouds.aws.AWSResponseException;
|
|||
import org.jclouds.aws.s3.commands.options.ListBucketOptions;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.xml.ListBucketHandler;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
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.
|
||||
|
@ -54,9 +56,10 @@ import com.google.inject.assistedinject.Assisted;
|
|||
public class ListBucket extends S3FutureCommand<S3Bucket> {
|
||||
|
||||
@Inject
|
||||
public ListBucket(ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
|
||||
public ListBucket(@Named("jclouds.http.address") String amazonHost,
|
||||
ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
|
||||
@Assisted ListBucketOptions options) {
|
||||
super("GET", "/" + options.buildQueryString(), bucketParser, bucket);
|
||||
super("GET", "/" + options.buildQueryString(), bucketParser, amazonHost, bucket);
|
||||
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
|
||||
handler.setBucketName(bucket);
|
||||
}
|
||||
|
@ -72,7 +75,7 @@ public class ListBucket extends S3FutureCommand<S3Bucket> {
|
|||
|
||||
@VisibleForTesting
|
||||
S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException {
|
||||
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
|
||||
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
||||
AWSResponseException responseException = (AWSResponseException) e.getCause();
|
||||
if ("NoSuchBucket".equals(responseException.getError().getCode())) {
|
||||
return S3Bucket.NOT_FOUND;
|
||||
|
|
|
@ -29,21 +29,23 @@ 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(ParseSax<List<S3Bucket.Metadata>> callable) {
|
||||
super("GET", "/", callable);
|
||||
}
|
||||
@Inject
|
||||
public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost,
|
||||
ParseSax<List<S3Bucket.Metadata>> callable) {
|
||||
super("GET", "/", callable, amazonHost);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,35 +30,36 @@ 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(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");
|
||||
}
|
||||
}
|
||||
@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 + "");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,7 @@ 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.
|
||||
|
@ -42,53 +43,56 @@ import com.google.inject.assistedinject.Assisted;
|
|||
* 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(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");
|
||||
@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");
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ 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.
|
||||
|
@ -121,29 +122,32 @@ public class S3CommandFactory {
|
|||
return headMetadataFactory.create(bucket, key);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named("jclouds.http.address")
|
||||
String amazonHost;
|
||||
|
||||
public ListOwnedBuckets createGetMetadataForOwnedBuckets() {
|
||||
return new ListOwnedBuckets(parserFactory.createListBucketsParser());
|
||||
return new ListOwnedBuckets(amazonHost, parserFactory.createListBucketsParser());
|
||||
}
|
||||
|
||||
public ListBucket createListBucket(String bucket, ListBucketOptions options) {
|
||||
return new ListBucket(parserFactory.createListBucketParser(), bucket, options);
|
||||
return new ListBucket(amazonHost, parserFactory.createListBucketParser(), bucket, options);
|
||||
}
|
||||
|
||||
public CopyObject createCopyObject(String sourceBucket, String sourceObject,
|
||||
String destinationBucket, String destinationObject, CopyObjectOptions options) {
|
||||
return new CopyObject(parserFactory.createCopyObjectParser(), sourceBucket,
|
||||
return new CopyObject(amazonHost, parserFactory.createCopyObjectParser(), sourceBucket,
|
||||
sourceObject, destinationBucket, destinationObject, options);
|
||||
}
|
||||
|
||||
public GetAccessControlList createGetBucketACL(String bucket) {
|
||||
return new GetAccessControlList(
|
||||
parserFactory.createAccessControlListParser(), bucket);
|
||||
amazonHost, parserFactory.createAccessControlListParser(), bucket);
|
||||
}
|
||||
|
||||
public GetAccessControlList createGetObjectACL(String bucket, String objectKey) {
|
||||
return new GetAccessControlList(
|
||||
parserFactory.createAccessControlListParser(), bucket, objectKey);
|
||||
amazonHost, parserFactory.createAccessControlListParser(), bucket, objectKey);
|
||||
}
|
||||
|
||||
}
|
|
@ -37,13 +37,19 @@ import org.jclouds.http.HttpFutureCommand;
|
|||
public class S3FutureCommand<T> extends HttpFutureCommand<T> {
|
||||
|
||||
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
|
||||
String bucketName) {
|
||||
super(method, String.format("/%1$s%2$s", checkNotNull(bucketName, "bucketName"),
|
||||
checkNotNull(uri, "uri")), responseCallable);
|
||||
String amazonHost, String bucketName) {
|
||||
super(method, uri, responseCallable);
|
||||
addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull(bucketName, "bucketName"));
|
||||
}
|
||||
|
||||
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable) {
|
||||
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
|
||||
String amazonHost) {
|
||||
super(method, uri, responseCallable);
|
||||
addHostHeader(checkNotNull(amazonHost, "amazonHost"));
|
||||
}
|
||||
|
||||
protected void addHostHeader(String amazonHost, String bucketName) {
|
||||
addHostHeader(checkNotNull(bucketName) + "." + amazonHost);
|
||||
}
|
||||
|
||||
}
|
|
@ -158,10 +158,9 @@ public class RequestAuthorizeSignature implements HttpRequestFilter {
|
|||
}
|
||||
|
||||
private static void appendBucketName(HttpRequest request, StringBuilder toSign) {
|
||||
String hostHeader = request.getFirstHeaderOrNull(HttpHeaders.HOST);
|
||||
if (hostHeader != null && hostHeader.endsWith(".s3.amazonaws.com")) {
|
||||
String hostHeader = request.getHeaders().get(HttpHeaders.HOST).iterator().next();
|
||||
if (hostHeader.endsWith(".s3.amazonaws.com"))
|
||||
toSign.append("/").append(hostHeader.substring(0, hostHeader.length() - 17));
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendUriPath(HttpRequest request, StringBuilder toSign) {
|
||||
|
@ -174,21 +173,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);
|
||||
}
|
||||
|
|
|
@ -41,13 +41,12 @@ import org.testng.annotations.Test;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "s3.ParseObjectFromHeadersAndHttpContentTest")
|
||||
public class ParseObjectFromHeadersAndHttpContentTest {
|
||||
ParseObjectFromHeadersAndHttpContent callable;
|
||||
ParseMetadataFromHeaders metadataParser;
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testCall() throws HttpException {
|
||||
metadataParser = createMock(ParseMetadataFromHeaders.class);
|
||||
callable = new ParseObjectFromHeadersAndHttpContent(metadataParser);
|
||||
ParseMetadataFromHeaders metadataParser = createMock(ParseMetadataFromHeaders.class);
|
||||
ParseObjectFromHeadersAndHttpContent callable = new ParseObjectFromHeadersAndHttpContent(
|
||||
metadataParser);
|
||||
HttpResponse response = createMock(HttpResponse.class);
|
||||
expect(response.getStatusCode()).andReturn(409).atLeastOnce();
|
||||
expect(response.getContent()).andReturn(null);
|
||||
|
@ -58,8 +57,9 @@ public class ParseObjectFromHeadersAndHttpContentTest {
|
|||
|
||||
@Test
|
||||
public void testParseContentLengthWhenContentRangeSet() throws HttpException {
|
||||
metadataParser = createMock(ParseMetadataFromHeaders.class);
|
||||
callable = new ParseObjectFromHeadersAndHttpContent(metadataParser);
|
||||
ParseMetadataFromHeaders metadataParser = createMock(ParseMetadataFromHeaders.class);
|
||||
ParseObjectFromHeadersAndHttpContent callable = new ParseObjectFromHeadersAndHttpContent(
|
||||
metadataParser);
|
||||
HttpResponse response = createMock(HttpResponse.class);
|
||||
metadataParser.setResponse(response);
|
||||
Metadata meta = createMock(Metadata.class);
|
||||
|
|
Loading…
Reference in New Issue