mirror of https://github.com/apache/jclouds.git
vcloud director 1.5 adds suffix of ;1.0 on content type
This commit is contained in:
parent
260c23170b
commit
61f2ff6468
|
@ -37,7 +37,6 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.VCloudResponseException;
|
||||
import org.jclouds.vcloud.domain.VCloudError;
|
||||
import org.jclouds.vcloud.domain.VCloudError.MinorCode;
|
||||
|
@ -68,19 +67,18 @@ public class ParseVCloudErrorFromHttpResponse implements HttpErrorHandler {
|
|||
VCloudError error = null;
|
||||
String message = null;
|
||||
if (response.getPayload() != null) {
|
||||
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||
if (VCloudMediaType.ERROR_XML.equals(contentType)) {
|
||||
try {
|
||||
error = utils.parseErrorFromContent(request, response);
|
||||
if (error != null) {
|
||||
message = error.getMessage();
|
||||
exception = new VCloudResponseException(command, response, error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
} else {
|
||||
message = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
exception = message != null ? new HttpResponseException(command, response, message) : exception;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} finally {
|
||||
response.getPayload().release();
|
||||
}
|
||||
}
|
||||
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
|
||||
|
|
|
@ -54,7 +54,10 @@ public class VCloudUtils {
|
|||
// HEAD has no content
|
||||
if (response.getPayload() == null)
|
||||
return null;
|
||||
if (VCloudMediaType.ERROR_XML.equals(response.getPayload().getContentMetadata().getContentType())) {
|
||||
// NOTE in vCloud Datacenter 1.5, if you make vCloud 1.0 requests, the content type
|
||||
// header is suffixed with ;1.0
|
||||
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||
if (contentType != null && contentType.startsWith(VCloudMediaType.ERROR_XML)) {
|
||||
try {
|
||||
return (VCloudError) factory.create(errorHandlerProvider.get()).setContext(request).apply(response);
|
||||
} catch (RuntimeException e) {
|
||||
|
|
|
@ -53,6 +53,19 @@ public class ParseVCloudErrorFromHttpResponseTest extends BaseHttpErrorHandlerTe
|
|||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet403NoAcessToEntitySetsResourceNotFoundExceptionOnAPI1_0AgainstVCD1_5() {
|
||||
assertCodeMakes(
|
||||
"GET",
|
||||
URI.create("https://mycloud.greenhousedata.com/api/v1.0/vApp/vapp-d3a1f2cd-d07b-4ddc-bf7b-fb7468b4d95a"),
|
||||
403,
|
||||
"HTTP/1.1 403",
|
||||
// NOTE VCD 1.5 appends the api version to the media type
|
||||
VCloudMediaType.ERROR_XML + ";1.0",
|
||||
"<Error xmlns=\"http://www.vmware.com/vcloud/v1\" minorErrorCode=\"ACCESS_TO_RESOURCE_IS_FORBIDDEN\" message=\"No access to entity "(com.vmware.vcloud.entity.vapp:d3a1f2cd-d07b-4ddc-bf7b-fb7468b4d95a)".\" majorErrorCode=\"403\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://mycloud.greenhousedata.com/api/v1.0/schema/master.xsd\"></Error>",
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete404SetsHttpResponseException() {
|
||||
assertCodeMakes("DELETE", URI.create("https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/vdc/32"),
|
||||
|
|
Loading…
Reference in New Issue