fixed bad cast

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1090 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-08 01:27:09 +00:00
parent 9cec8159d4
commit 5cb5a3bb71
3 changed files with 48 additions and 56 deletions

View File

@ -37,56 +37,53 @@ import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named; 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(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
ReturnTrueIf2xx callable, @Assisted String s3Bucket) { @Assisted String s3Bucket) {
super("DELETE", "/", callable, amazonHost, s3Bucket); super("DELETE", "/", callable, amazonHost, s3Bucket);
} }
@Override @Override
public Boolean get() throws InterruptedException, ExecutionException { public Boolean get() throws InterruptedException, ExecutionException {
try { try {
return super.get(); return super.get();
} catch (ExecutionException e) { } catch (ExecutionException e) {
return attemptNotFound(e); return attemptNotFound(e);
} }
} }
@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 AWSResponseException) {
&& e.getCause() instanceof HttpResponseException) { AWSResponseException responseException = (AWSResponseException) e.getCause();
AWSResponseException responseException = (AWSResponseException) e if (responseException.getResponse().getStatusCode() == 404) {
.getCause(); return true;
if (responseException.getResponse().getStatusCode() == 404) { } else if ("BucketNotEmpty".equals(responseException.getError().getCode())) {
return true; return false;
} else if ("BucketNotEmpty".equals(responseException.getError() }
.getCode())) { }
return false; throw e;
} }
}
throw e;
}
@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) {
return attemptNotFound(e); return attemptNotFound(e);
} }
} }
} }

View File

@ -50,18 +50,15 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
@Inject @Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost, public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser, ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket) @Assisted("bucketName") String bucket) {
{
super("GET", "/?acl", accessControlListParser, amazonHost, bucket); super("GET", "/?acl", accessControlListParser, amazonHost, bucket);
} }
@Inject @Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost, public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser, ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket, @Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
@Assisted("objectKey") String objectKey)
{
super("GET", "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket); super("GET", "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
} }
@ -76,11 +73,10 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
@VisibleForTesting @VisibleForTesting
AccessControlList attemptNotFound(ExecutionException e) throws ExecutionException { AccessControlList attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) { if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
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 +84,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) {

View File

@ -31,7 +31,6 @@ import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.commands.options.ListBucketOptions; import org.jclouds.aws.s3.commands.options.ListBucketOptions;
import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Bucket;
import org.jclouds.aws.s3.xml.ListBucketHandler; import org.jclouds.aws.s3.xml.ListBucketHandler;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.xml.ParseSax; import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -75,7 +74,7 @@ public class ListBucket extends S3FutureCommand<S3Bucket> {
@VisibleForTesting @VisibleForTesting
S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException { S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) { if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause(); AWSResponseException responseException = (AWSResponseException) e.getCause();
if ("NoSuchBucket".equals(responseException.getError().getCode())) { if ("NoSuchBucket".equals(responseException.getError().getCode())) {
return S3Bucket.NOT_FOUND; return S3Bucket.NOT_FOUND;