mirror of https://github.com/apache/jclouds.git
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:
parent
0c9b3accda
commit
c6da1b86b7
|
@ -35,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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Issues a HEAD command to determine if the bucket exists or not.
|
* Issues a HEAD command to determine if the bucket exists or not.
|
||||||
|
@ -46,10 +45,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,
|
public BucketExists(ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
||||||
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
super("HEAD", "/" + maxResults(0).buildQueryString(), callable, s3Bucket);
|
||||||
super("HEAD", "/" + maxResults(0).buildQueryString(), callable,
|
|
||||||
amazonHost, s3Bucket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,10 +60,8 @@ public class BucketExists extends S3FutureCommand<Boolean> {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
|
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
|
||||||
if (e.getCause() != null
|
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
||||||
&& e.getCause() instanceof HttpResponseException) {
|
HttpResponseException responseException = (HttpResponseException) e.getCause();
|
||||||
HttpResponseException responseException = (HttpResponseException) e
|
|
||||||
.getCause();
|
|
||||||
if (responseException.getResponse().getStatusCode() == 404) {
|
if (responseException.getResponse().getStatusCode() == 404) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -75,8 +70,8 @@ public class BucketExists extends S3FutureCommand<Boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
|
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
|
||||||
ExecutionException, TimeoutException {
|
TimeoutException {
|
||||||
try {
|
try {
|
||||||
return super.get(l, timeUnit);
|
return super.get(l, timeUnit);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
|
|
@ -33,20 +33,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
|
||||||
|
@ -56,23 +55,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(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("PUT", "/" + checkNotNull(destinationObject, "destinationObject"), callable,
|
||||||
super("PUT",
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,25 +34,23 @@ 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
|
* The DELETE request operation deletes the bucket named in the URI. All objects in the bucket must
|
||||||
* in the bucket must be deleted before the bucket itself can be deleted.
|
* be deleted before the bucket itself can be deleted.
|
||||||
* <p />
|
* <p />
|
||||||
* Only the owner of a bucket can delete it, regardless of the bucket's access
|
* Only the owner of a bucket can delete it, regardless of the bucket's access control policy.
|
||||||
* 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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class DeleteBucket extends S3FutureCommand<Boolean> {
|
public class DeleteBucket extends S3FutureCommand<Boolean> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DeleteBucket(@Named("jclouds.http.address") String amazonHost,
|
public DeleteBucket(ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
||||||
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
|
super("DELETE", "/", callable, s3Bucket);
|
||||||
super("DELETE", "/", callable, amazonHost, s3Bucket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,14 +64,11 @@ public class DeleteBucket extends S3FutureCommand<Boolean> {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
|
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
|
||||||
if (e.getCause() != null
|
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
||||||
&& e.getCause() instanceof HttpResponseException) {
|
AWSResponseException responseException = (AWSResponseException) e.getCause();
|
||||||
AWSResponseException responseException = (AWSResponseException) e
|
|
||||||
.getCause();
|
|
||||||
if (responseException.getResponse().getStatusCode() == 404) {
|
if (responseException.getResponse().getStatusCode() == 404) {
|
||||||
return true;
|
return true;
|
||||||
} else if ("BucketNotEmpty".equals(responseException.getError()
|
} else if ("BucketNotEmpty".equals(responseException.getError().getCode())) {
|
||||||
.getCode())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,8 +76,8 @@ public class DeleteBucket extends S3FutureCommand<Boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
|
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
|
||||||
ExecutionException, TimeoutException {
|
TimeoutException {
|
||||||
try {
|
try {
|
||||||
return super.get(l, timeUnit);
|
return super.get(l, timeUnit);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
|
|
@ -29,11 +29,10 @@ 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.
|
* The DELETE request operation removes the specified object from Amazon S3. Once deleted, there is
|
||||||
* Once deleted, there is no method to restore or undelete an object.
|
* no method to restore or undelete an object.
|
||||||
*
|
*
|
||||||
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?
|
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?
|
||||||
* RESTObjectDELETE.html" />
|
* RESTObjectDELETE.html" />
|
||||||
|
@ -42,9 +41,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,
|
public DeleteObject(ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
|
||||||
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
|
|
||||||
@Assisted("key") String key) {
|
@Assisted("key") String key) {
|
||||||
super("DELETE", "/" + checkNotNull(key), callable, amazonHost, bucket);
|
super("DELETE", "/" + checkNotNull(key), callable, bucket);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,7 +35,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,20 +48,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(ParseSax<AccessControlList> accessControlListParser,
|
||||||
ParseSax<AccessControlList> accessControlListParser,
|
@Assisted("bucketName") String bucket) {
|
||||||
@Assisted("bucketName") String bucket)
|
super("GET", "/?acl", accessControlListParser, bucket);
|
||||||
{
|
|
||||||
super("GET", "/?acl", accessControlListParser, amazonHost, bucket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
|
public GetAccessControlList(ParseSax<AccessControlList> accessControlListParser,
|
||||||
ParseSax<AccessControlList> accessControlListParser,
|
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
|
||||||
@Assisted("bucketName") String bucket,
|
super("GET", "/" + objectKey + "?acl", accessControlListParser, bucket);
|
||||||
@Assisted("objectKey") String objectKey)
|
|
||||||
{
|
|
||||||
super("GET", "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,8 +73,7 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
|
||||||
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
||||||
AWSResponseException responseException = (AWSResponseException) e.getCause();
|
AWSResponseException responseException = (AWSResponseException) e.getCause();
|
||||||
if ("NoSuchBucket".equals(responseException.getError().getCode())
|
if ("NoSuchBucket".equals(responseException.getError().getCode())
|
||||||
|| "NoSuchObject".equals(responseException.getError().getCode()))
|
|| "NoSuchObject".equals(responseException.getError().getCode())) {
|
||||||
{
|
|
||||||
return AccessControlList.NOT_FOUND;
|
return AccessControlList.NOT_FOUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,8 +81,8 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccessControlList get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
|
public AccessControlList get(long l, TimeUnit timeUnit) throws InterruptedException,
|
||||||
TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
try {
|
try {
|
||||||
return super.get(l, timeUnit);
|
return super.get(l, timeUnit);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.jclouds.aws.s3.domain.S3Object;
|
||||||
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;
|
||||||
|
@ -65,10 +64,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(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("GET", "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
|
super("GET", "/" + checkNotNull(key), callable, s3Bucket);
|
||||||
this.getRequest().getHeaders().putAll(options.buildRequestHeaders());
|
this.getRequest().getHeaders().putAll(options.buildRequestHeaders());
|
||||||
callable.setKey(key);
|
callable.setKey(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,20 +36,19 @@ 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
|
||||||
* {@link org.jclouds.aws.s3.domain.S3Object.Metadata#NOT_FOUND} if not available.
|
* {@link org.jclouds.aws.s3.domain.S3Object.Metadata#NOT_FOUND} if not available.
|
||||||
*
|
*
|
||||||
* <p/>
|
* <p/>
|
||||||
* The HEAD operation is used to retrieve information about a specific object or
|
* The HEAD operation is used to retrieve information about a specific object or object size,
|
||||||
* object size, without actually fetching the object itself. This is useful if
|
* without actually fetching the object itself. This is useful if you're only interested in the
|
||||||
* you're only interested in the object metadata, and don't want to waste
|
* object metadata, and don't want to waste bandwidth on the object data.
|
||||||
* bandwidth on the object data.
|
|
||||||
*
|
*
|
||||||
* @see GetObject
|
* @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
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
|
@ -57,16 +56,14 @@ 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(ParseMetadataFromHeaders callable, @Assisted("bucketName") String bucket,
|
||||||
ParseMetadataFromHeaders callable,
|
@Assisted("key") String key) {
|
||||||
@Assisted("bucketName") String bucket, @Assisted("key") String key) {
|
super("HEAD", "/" + checkNotNull(key), callable, bucket);
|
||||||
super("HEAD", "/" + checkNotNull(key), callable, amazonHost, bucket);
|
|
||||||
callable.setKey(key);
|
callable.setKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public S3Object.Metadata get() throws InterruptedException,
|
public S3Object.Metadata get() throws InterruptedException, ExecutionException {
|
||||||
ExecutionException {
|
|
||||||
try {
|
try {
|
||||||
return super.get();
|
return super.get();
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
@ -75,12 +72,9 @@ public class HeadObject extends S3FutureCommand<S3Object.Metadata> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
S3Object.Metadata attemptNotFound(ExecutionException e)
|
S3Object.Metadata attemptNotFound(ExecutionException e) throws ExecutionException {
|
||||||
throws ExecutionException {
|
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
||||||
if (e.getCause() != null
|
HttpResponseException responseException = (HttpResponseException) e.getCause();
|
||||||
&& e.getCause() instanceof HttpResponseException) {
|
|
||||||
HttpResponseException responseException = (HttpResponseException) e
|
|
||||||
.getCause();
|
|
||||||
if (responseException.getResponse().getStatusCode() == 404) {
|
if (responseException.getResponse().getStatusCode() == 404) {
|
||||||
return S3Object.Metadata.NOT_FOUND;
|
return S3Object.Metadata.NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
@ -89,8 +83,8 @@ public class HeadObject extends S3FutureCommand<S3Object.Metadata> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public S3Object.Metadata get(long l, TimeUnit timeUnit)
|
public S3Object.Metadata get(long l, TimeUnit timeUnit) throws InterruptedException,
|
||||||
throws InterruptedException, ExecutionException, TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
try {
|
try {
|
||||||
return super.get(l, timeUnit);
|
return super.get(l, timeUnit);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
|
|
|
@ -37,7 +37,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 +55,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(ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
|
||||||
ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
|
|
||||||
@Assisted ListBucketOptions options) {
|
@Assisted ListBucketOptions options) {
|
||||||
super("GET", "/" + options.buildQueryString(), bucketParser, amazonHost, bucket);
|
super("GET", "/" + options.buildQueryString(), bucketParser, bucket);
|
||||||
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
|
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
|
||||||
handler.setBucketName(bucket);
|
handler.setBucketName(bucket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,12 @@ import org.jclouds.aws.s3.domain.S3Bucket;
|
||||||
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
|
* Returns a list of all of the buckets owned by the authenticated sender of the request.
|
||||||
* 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
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
|
@ -43,9 +42,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(ParseSax<List<S3Bucket.Metadata>> callable) {
|
||||||
ParseSax<List<S3Bucket.Metadata>> callable) {
|
super("GET", "/", callable);
|
||||||
super("GET", "/", callable, amazonHost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,18 +30,18 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and name your own bucket in which to store your objects.
|
* Create and name your own bucket in which to store your objects.
|
||||||
* <p/>
|
* <p/>
|
||||||
* The PUT request operation with a bucket URI creates a new bucket. Depending
|
* The PUT request operation with a bucket URI creates a new bucket. Depending on your latency and
|
||||||
* on your latency and legal requirements, you can specify a location constraint
|
* legal requirements, you can specify a location constraint that will affect where your data
|
||||||
* that will affect where your data physically resides. You can currently
|
* physically resides. You can currently specify a Europe (EU) location constraint via
|
||||||
* specify a Europe (EU) location constraint via {@link PutBucketOptions}.
|
* {@link PutBucketOptions}.
|
||||||
*
|
*
|
||||||
* @see 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
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
|
@ -49,17 +49,16 @@ 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,
|
public PutBucket(ReturnTrueIf2xx callable, @Assisted String bucketName,
|
||||||
ReturnTrueIf2xx callable, @Assisted String bucketName,
|
|
||||||
@Assisted PutBucketOptions options) {
|
@Assisted PutBucketOptions options) {
|
||||||
super("PUT", "/", callable, amazonHost, S3Utils
|
super("PUT", "/", callable, S3Utils.validateBucketName(bucketName));
|
||||||
.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) {
|
||||||
getRequest().setPayload(payload);
|
getRequest().setPayload(payload);
|
||||||
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH,
|
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, payload.getBytes().length + "");
|
||||||
payload.getBytes().length + "");
|
} else {
|
||||||
|
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, "0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -34,7 +34,6 @@ import org.jclouds.http.HttpHeaders;
|
||||||
|
|
||||||
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.
|
||||||
|
@ -43,35 +42,33 @@ import com.google.inject.name.Named;
|
||||||
* This returns a byte[] of the md5 hash of what Amazon S3 received
|
* This returns a byte[] of the md5 hash of what Amazon S3 received
|
||||||
* <p />
|
* <p />
|
||||||
* <p/>
|
* <p/>
|
||||||
* This command allows you to specify {@link PutObjectOptions} to control
|
* This command allows you to specify {@link PutObjectOptions} to control delivery of content.
|
||||||
* delivery of content.
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @see PutObjectOptions
|
* @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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class PutObject extends S3FutureCommand<byte[]> {
|
public class PutObject extends S3FutureCommand<byte[]> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PutObject(@Named("jclouds.http.address") String amazonHost,
|
public PutObject(ParseMd5FromETagHeader callable, @Assisted String s3Bucket,
|
||||||
ParseMd5FromETagHeader callable, @Assisted String s3Bucket,
|
|
||||||
@Assisted S3Object object, @Assisted PutObjectOptions options) {
|
@Assisted S3Object object, @Assisted PutObjectOptions options) {
|
||||||
super("PUT", "/" + checkNotNull(object.getKey()), callable, amazonHost,
|
super("PUT", "/" + checkNotNull(object.getKey()), callable, s3Bucket);
|
||||||
s3Bucket);
|
|
||||||
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
|
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
|
||||||
|
|
||||||
getRequest().setPayload(
|
getRequest().setPayload(checkNotNull(object.getData(), "object.getContent()"));
|
||||||
checkNotNull(object.getData(), "object.getContent()"));
|
|
||||||
|
|
||||||
getRequest().getHeaders().put(
|
getRequest().getHeaders()
|
||||||
|
.put(
|
||||||
HttpHeaders.CONTENT_TYPE,
|
HttpHeaders.CONTENT_TYPE,
|
||||||
checkNotNull(object.getMetadata().getContentType(),
|
checkNotNull(object.getMetadata().getContentType(),
|
||||||
"object.metadata.contentType()"));
|
"object.metadata.contentType()"));
|
||||||
|
|
||||||
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH,
|
getRequest().getHeaders()
|
||||||
object.getMetadata().getSize() + "");
|
.put(HttpHeaders.CONTENT_LENGTH, object.getMetadata().getSize() + "");
|
||||||
|
|
||||||
if (object.getMetadata().getCacheControl() != null) {
|
if (object.getMetadata().getCacheControl() != null) {
|
||||||
getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL,
|
getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL,
|
||||||
|
@ -90,8 +87,7 @@ public class PutObject extends S3FutureCommand<byte[]> {
|
||||||
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
|
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
|
||||||
S3Utils.toBase64String(object.getMetadata().getMd5()));
|
S3Utils.toBase64String(object.getMetadata().getMd5()));
|
||||||
|
|
||||||
getRequest().getHeaders()
|
getRequest().getHeaders().putAll(object.getMetadata().getUserMetadata());
|
||||||
.putAll(object.getMetadata().getUserMetadata());
|
|
||||||
getRequest().getHeaders().putAll(options.buildRequestHeaders());
|
getRequest().getHeaders().putAll(options.buildRequestHeaders());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,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.
|
||||||
|
@ -122,32 +121,29 @@ public class S3CommandFactory {
|
||||||
return headMetadataFactory.create(bucket, key);
|
return headMetadataFactory.create(bucket, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Named("jclouds.http.address")
|
|
||||||
String amazonHost;
|
|
||||||
|
|
||||||
public ListOwnedBuckets createGetMetadataForOwnedBuckets() {
|
public ListOwnedBuckets createGetMetadataForOwnedBuckets() {
|
||||||
return new ListOwnedBuckets(amazonHost, parserFactory.createListBucketsParser());
|
return new ListOwnedBuckets(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(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(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(
|
||||||
amazonHost, parserFactory.createAccessControlListParser(), bucket);
|
parserFactory.createAccessControlListParser(), bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetAccessControlList createGetObjectACL(String bucket, String objectKey) {
|
public GetAccessControlList createGetObjectACL(String bucket, String objectKey) {
|
||||||
return new GetAccessControlList(
|
return new GetAccessControlList(
|
||||||
amazonHost, parserFactory.createAccessControlListParser(), bucket, objectKey);
|
parserFactory.createAccessControlListParser(), bucket, objectKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -37,19 +37,13 @@ import org.jclouds.http.HttpFutureCommand;
|
||||||
public class S3FutureCommand<T> extends HttpFutureCommand<T> {
|
public class S3FutureCommand<T> extends HttpFutureCommand<T> {
|
||||||
|
|
||||||
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
|
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
|
||||||
String amazonHost, String bucketName) {
|
String bucketName) {
|
||||||
super(method, uri, responseCallable);
|
super(method, String.format("/%1$s%2$s", checkNotNull(bucketName, "bucketName"),
|
||||||
addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull(bucketName, "bucketName"));
|
checkNotNull(uri, "uri")), responseCallable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
|
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable) {
|
||||||
String amazonHost) {
|
|
||||||
super(method, uri, responseCallable);
|
super(method, uri, responseCallable);
|
||||||
addHostHeader(checkNotNull(amazonHost, "amazonHost"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addHostHeader(String amazonHost, String bucketName) {
|
|
||||||
addHostHeader(checkNotNull(bucketName) + "." + amazonHost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -158,10 +158,11 @@ public class RequestAuthorizeSignature implements HttpRequestFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendBucketName(HttpRequest request, StringBuilder toSign) {
|
private static void appendBucketName(HttpRequest request, StringBuilder toSign) {
|
||||||
String hostHeader = request.getHeaders().get(HttpHeaders.HOST).iterator().next();
|
String hostHeader = request.getFirstHeaderOrNull(HttpHeaders.HOST);
|
||||||
if (hostHeader.endsWith(".s3.amazonaws.com"))
|
if (hostHeader != null && hostHeader.endsWith(".s3.amazonaws.com")) {
|
||||||
toSign.append("/").append(hostHeader.substring(0, hostHeader.length() - 17));
|
toSign.append("/").append(hostHeader.substring(0, hostHeader.length() - 17));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void appendUriPath(HttpRequest request, StringBuilder toSign) {
|
private static void appendUriPath(HttpRequest request, StringBuilder toSign) {
|
||||||
// Remove parameters from URI, because most must not be included in the signed URI...
|
// Remove parameters from URI, because most must not be included in the signed URI...
|
||||||
|
|
Loading…
Reference in New Issue