s3 error parse regression

This commit is contained in:
Adrian Cole 2011-01-26 00:16:24 -08:00
parent 1e017d47e1
commit f1288fed4c
3 changed files with 9 additions and 22 deletions

View File

@ -53,7 +53,7 @@ import org.jclouds.s3.functions.ObjectKey;
import org.jclouds.s3.functions.ParseObjectFromHeadersAndHttpContent;
import org.jclouds.s3.functions.ParseObjectMetadataFromHeaders;
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
import org.jclouds.s3.functions.ReturnTrueOn404OrNotFoundFalseIfNotEmpty;
import org.jclouds.s3.functions.ReturnTrueOn404OrNotFoundFalseOnIllegalState;
import org.jclouds.s3.options.CopyObjectOptions;
import org.jclouds.s3.options.ListBucketOptions;
import org.jclouds.s3.options.PutBucketOptions;
@ -182,7 +182,7 @@ public interface S3AsyncClient {
*/
@DELETE
@Path("/")
@ExceptionParser(ReturnTrueOn404OrNotFoundFalseIfNotEmpty.class)
@ExceptionParser(ReturnTrueOn404OrNotFoundFalseOnIllegalState.class)
ListenableFuture<Boolean> deleteBucketIfEmpty(
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators( { BucketNameValidator.class }) String bucketName);

View File

@ -20,18 +20,12 @@
package org.jclouds.s3.functions;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Throwables.getCausalChain;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.size;
import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull;
import static org.jclouds.util.Throwables2.getFirstThrowableOfType;
import static org.jclouds.util.Throwables2.propagateOrNull;
import java.util.List;
import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.blobstore.ContainerNotFoundException;
import com.google.common.base.Function;
@ -41,20 +35,13 @@ import com.google.common.base.Function;
* @author Adrian Cole
*/
@Singleton
public class ReturnTrueOn404OrNotFoundFalseIfNotEmpty implements Function<Exception, Boolean> {
public class ReturnTrueOn404OrNotFoundFalseOnIllegalState implements Function<Exception, Boolean> {
public Boolean apply(Exception from) {
List<Throwable> throwables = getCausalChain(from);
Iterable<AWSResponseException> matchingAWSResponseException = filter(throwables, AWSResponseException.class);
if (size(matchingAWSResponseException) >= 1 && get(matchingAWSResponseException, 0).getError() != null) {
if (get(matchingAWSResponseException, 0).getError().getCode().equals("BucketNotEmpty"))
return false;
if (getFirstThrowableOfType(from, IllegalStateException.class) != null) {
return false;
}
Iterable<ContainerNotFoundException> matchingContainerNotFoundException = filter(throwables,
ContainerNotFoundException.class);
if (size(matchingContainerNotFoundException) >= 1) {
if (getFirstThrowableOfType(from, ContainerNotFoundException.class) != null) {
return true;
}
if (returnValueOnCodeOrNull(from, true, equalTo(404)) != null)

View File

@ -38,7 +38,7 @@ import org.jclouds.s3.domain.AccessControlList.Permission;
import org.jclouds.s3.functions.ParseObjectFromHeadersAndHttpContent;
import org.jclouds.s3.functions.ParseObjectMetadataFromHeaders;
import org.jclouds.s3.functions.ReturnFalseIfBucketAlreadyOwnedByYouOrIllegalState;
import org.jclouds.s3.functions.ReturnTrueOn404OrNotFoundFalseIfNotEmpty;
import org.jclouds.s3.functions.ReturnTrueOn404OrNotFoundFalseOnIllegalState;
import org.jclouds.s3.options.CopyObjectOptions;
import org.jclouds.s3.options.ListBucketOptions;
import org.jclouds.s3.options.PutBucketOptions;
@ -231,7 +231,7 @@ public class S3AsyncClientTest extends BaseS3AsyncClientTest {
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnTrueOn404OrNotFoundFalseIfNotEmpty.class);
assertExceptionParserClassEquals(method, ReturnTrueOn404OrNotFoundFalseOnIllegalState.class);
checkFilters(request);
}