mirror of https://github.com/apache/jclouds.git
JCLOUDS-438: Map S3 code BucketAlreadyExists
Mapping to ResourceAlreadyExistsException allows external callers to handle this situation specifically.
This commit is contained in:
parent
ea5128209a
commit
0098751f42
|
@ -35,6 +35,7 @@ import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.InsufficientResourcesException;
|
import org.jclouds.rest.InsufficientResourcesException;
|
||||||
|
import org.jclouds.rest.ResourceAlreadyExistsException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
|
|
||||||
|
@ -128,7 +129,12 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 409:
|
case 409:
|
||||||
exception = new IllegalStateException(message, exception);
|
if ("BucketAlreadyExists".equals(errorCode)) {
|
||||||
|
exception = new ResourceAlreadyExistsException(exception);
|
||||||
|
} else {
|
||||||
|
exception = new IllegalStateException(message, exception);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return exception;
|
return exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.http.functions.config.SaxParserModule;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.InsufficientResourcesException;
|
import org.jclouds.rest.InsufficientResourcesException;
|
||||||
import org.jclouds.rest.RequestSigner;
|
import org.jclouds.rest.RequestSigner;
|
||||||
|
import org.jclouds.rest.ResourceAlreadyExistsException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -110,6 +111,22 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
InsufficientResourcesException.class);
|
InsufficientResourcesException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test409WithBucketAlreadyExistsMakesResourceAlreadyExistsException() {
|
||||||
|
assertCodeMakes(
|
||||||
|
POST,
|
||||||
|
URI.create("https://ec2.us-east-1.amazonaws.com/"),
|
||||||
|
CONFLICT.getStatusCode(),
|
||||||
|
"",
|
||||||
|
"<Response><Errors><Error>" +
|
||||||
|
"<Code>BucketAlreadyExists</Code>" +
|
||||||
|
"<Message>The requested bucket name is not available." +
|
||||||
|
" The bucket namespace is shared by all users of the system." +
|
||||||
|
" Please select a different name and try again.</Message>" +
|
||||||
|
"</Error></Errors><RequestID>c14f531a-cc35-4b48-8149-2655c7e6dc76</RequestID></Response>",
|
||||||
|
ResourceAlreadyExistsException.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test400WithInUseCodeSetsIllegalStateException() {
|
public void test400WithInUseCodeSetsIllegalStateException() {
|
||||||
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
assertCodeMakes(GET, URI.create("https://amazonaws.com/foo"), BAD_REQUEST.getStatusCode(), "",
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jclouds.rest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when creating a resource that already exists.
|
||||||
|
*
|
||||||
|
* @author Andrew Gaul
|
||||||
|
*/
|
||||||
|
public class ResourceAlreadyExistsException extends RuntimeException {
|
||||||
|
public ResourceAlreadyExistsException() {
|
||||||
|
this(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceAlreadyExistsException(String message) {
|
||||||
|
this(message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceAlreadyExistsException(Throwable cause) {
|
||||||
|
this(null, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceAlreadyExistsException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue