diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java index c022ab06a799..8aca9db4c693 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/PipelineHelpers.java @@ -27,17 +27,29 @@ import com.sun.jersey.api.client.WebResource.Builder; public class PipelineHelpers { + + private static String createErrorMessage(ClientResponse clientResponse) { + clientResponse.bufferEntity(); + String errorMessage = clientResponse.toString(); + if (clientResponse.hasEntity()) { + errorMessage = errorMessage + " " + clientResponse.getEntity(String.class); + } + return errorMessage; + } + public static void ThrowIfNotSuccess(ClientResponse clientResponse) { int statusCode = clientResponse.getStatus(); if ((statusCode < 200) || (statusCode >= 300)) { - throw new UniformInterfaceException(clientResponse); + String errorMessage = createErrorMessage(clientResponse); + throw new UniformInterfaceException(errorMessage, clientResponse); } } public static void ThrowIfError(ClientResponse clientResponse) { if (clientResponse.getStatus() >= 400) { - throw new UniformInterfaceException(clientResponse); + String errorMessage = createErrorMessage(clientResponse); + throw new UniformInterfaceException(errorMessage, clientResponse); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java index a8b4f3cab0cb..c195aad9320f 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/ContentKeyIntegrationTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.*; import java.net.URL; +import java.net.URLDecoder; import java.net.URLEncoder; import java.security.PrivateKey; import java.security.Security; @@ -284,9 +285,10 @@ public void rebindContentKeyWithX509CertficateSuccess() throws Exception { byte[] aesKey = createTestAesKey(); ContentKeyInfo contentKeyInfo = createValidTestContentKeyWithAesKey("rebindContentKeyWithX509Success", aesKey); URL serverCertificateUri = getClass().getResource("/certificate/server.crt"); - X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(serverCertificateUri.getFile()); + X509Certificate x509Certificate = EncryptionHelper.loadX509Certificate(URLDecoder.decode( + serverCertificateUri.getFile(), "UTF-8")); URL serverPrivateKey = getClass().getResource("/certificate/server.der"); - PrivateKey privateKey = EncryptionHelper.getPrivateKey(serverPrivateKey.getFile()); + PrivateKey privateKey = EncryptionHelper.getPrivateKey(URLDecoder.decode(serverPrivateKey.getFile(), "UTF-8")); String rebindedContentKey = service.action(ContentKey.rebind(contentKeyInfo.getId(), URLEncoder.encode(Base64.encode(x509Certificate.getEncoded()), "UTF-8")));