From aa14f5b051a9b57947e5d022fb262fe1c1ee4d7f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 1 May 2012 10:10:33 -0700 Subject: [PATCH] always display some error content --- .../jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/aws/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java b/common/aws/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java index 7471bf47c5..e4dc779e8c 100644 --- a/common/aws/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java +++ b/common/aws/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java @@ -18,6 +18,7 @@ */ package org.jclouds.aws.handlers; +import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; import static org.jclouds.http.HttpUtils.releasePayload; import java.io.IOException; @@ -65,7 +66,9 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler { Exception exception = new HttpResponseException(command, response); try { AWSError error = null; - String message = null; + // it is important to always read fully and close streams + byte[] data = closeClientButKeepContentStream(response); + String message = data != null ? new String(data) : null; if (response.getPayload() != null) { String contentType = response.getPayload().getContentMetadata().getContentType(); if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {