fixed azure blob error parsing when no content is returned

This commit is contained in:
Adrian Cole 2010-11-08 09:02:48 +01:00
parent 2f00ab22e4
commit a0fbeb96e7
2 changed files with 53 additions and 34 deletions

View File

@ -68,13 +68,21 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
try {
if (response.getPayload() != null) {
String contentType = response.getPayload().getContentMetadata().getContentType();
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)
&& !new Long(0).equals(response.getPayload().getContentMetadata().getContentLength())) {
try {
AzureStorageError error = utils.parseAzureStorageErrorFromContent(command, response, response
.getPayload().getInput());
if (error != null) {
message = error.getMessage();
exception = new AzureStorageResponseException(command, response, error);
}
} catch (RuntimeException e) {
try {
message = Utils.toStringAndClose(response.getPayload().getInput());
} catch (IOException e1) {
}
}
} else {
try {
message = Utils.toStringAndClose(response.getPayload().getInput());

View File

@ -50,17 +50,28 @@ public class ParseAzureErrorFromXmlContentTest {
@Test
public void test411WithTextHtmlIllegalArgumentException() {
assertCodeMakes("PUT", URI
.create("https://jclouds.blob.core.windows.net/adriancole-azureblob-413790770?restype=container"), 411,
assertCodeMakes("PUT",
URI.create("https://jclouds.blob.core.windows.net/adriancole-azureblob-413790770?restype=container"), 411,
"Length Required", "text/html; charset=us-ascii", "<HTML><HEAD><TITLE>Length Required</TITLE>\r\n",
IllegalArgumentException.class);
}
@Test
public void test304WithNoContentIllegalArgumentException() {
assertCodeMakes("GET", URI.create("https://jclouds.blob.core.windows.net/adriancole-blobstore0/apples"), 411,
"HTTP/1.1 304 The condition specified using HTTP conditional header(s) is not met.", "application/unknown",
"", IllegalArgumentException.class);
}
@Test
public void test412WithTextHtmlHttpResponseException() {
assertCodeMakes("GET", URI
.create("https://jclouds.blob.core.windows.net/adriancole-blobstore2?restype=container&comp=list&prefix=apps/apps/apps/&include=metadata"), 412,
"HTTP/1.1 412 The condition specified using HTTP conditional header(s) is not met.", "application/xml", "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ConditionNotMet</Code><Message>The condition specified using HTTP conditional header(s) is not met.\nRequestId:921efcad-84bc-4e0a-863d-24810d1096e1\nTime:2010-11-04T15:03:07.8694513Z</Message></Error>",
assertCodeMakes(
"GET",
URI.create("https://jclouds.blob.core.windows.net/adriancole-blobstore2?restype=container&comp=list&prefix=apps/apps/apps/&include=metadata"),
412,
"HTTP/1.1 412 The condition specified using HTTP conditional header(s) is not met.",
"application/xml",
"<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ConditionNotMet</Code><Message>The condition specified using HTTP conditional header(s) is not met.\nRequestId:921efcad-84bc-4e0a-863d-24810d1096e1\nTime:2010-11-04T15:03:07.8694513Z</Message></Error>",
AzureStorageResponseException.class);
}