From c372a0081f528a21f957c16337771a30d1276259 Mon Sep 17 00:00:00 2001 From: Jason Cooke Date: Thu, 8 Mar 2012 10:32:32 -0800 Subject: [PATCH 1/3] Fix #257 --- .../windowsazure/services/core/utils/pipeline/Exports.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java index 234581b023fb..f7aae2cd9188 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java @@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.LoggingFilter; public class Exports implements Builder.Exports { @@ -52,7 +53,7 @@ public Client create(String profile, Builder builder, Map proper public HttpURLConnectionClient create(String profile, Builder builder, Map properties) { ClientConfig clientConfig = (ClientConfig) properties.get("ClientConfig"); HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig); - //client.addFilter(new LoggingFilter()); + client.addFilter(new LoggingFilter()); return client; } }); From 90442d27eb5ddcc8d38ec61acf6eb4cca4b78a2d Mon Sep 17 00:00:00 2001 From: Jason Cooke Date: Tue, 3 Apr 2012 21:36:53 -0700 Subject: [PATCH 2/3] Address root cause of the issue: the default response EntityInputStream not rewindable, yet is is needed in multiple areas of the parseBatchResponse. Revert workaround fix. --- .../services/core/utils/pipeline/Exports.java | 3 +-- .../table/implementation/TableRestProxy.java | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java index f7aae2cd9188..234581b023fb 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java @@ -22,7 +22,6 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.api.client.filter.LoggingFilter; public class Exports implements Builder.Exports { @@ -53,7 +52,7 @@ public Client create(String profile, Builder builder, Map proper public HttpURLConnectionClient create(String profile, Builder builder, Map properties) { ClientConfig clientConfig = (ClientConfig) properties.get("ClientConfig"); HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig); - client.addFilter(new LoggingFilter()); + //client.addFilter(new LoggingFilter()); return client; } }); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java index bfeddfdb5c80..54b58bd8f20a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java @@ -83,6 +83,7 @@ import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource.Builder; import com.sun.jersey.core.header.InBoundHeaders; +import com.sun.jersey.core.util.ReaderWriter; public class TableRestProxy implements TableContract { private static final String API_VERSION = "2011-08-18"; @@ -577,7 +578,13 @@ public BatchResult batch(BatchOperations operations, TableServiceOptions options ThrowIfError(response); BatchResult result = new BatchResult(); - result.setEntries(parseBatchResponse(response, operations)); + + try { + result.setEntries(parseBatchResponse(response, operations)); + } + catch (IOException e) { + throw new ServiceException(e); + } return result; } @@ -696,7 +703,15 @@ private DataSource createBatchDeleteEntityPart(String table, String partitionKey return bodyPartContent; } - private List parseBatchResponse(ClientResponse response, BatchOperations operations) { + private List parseBatchResponse(ClientResponse response, BatchOperations operations) throws IOException { + // Default stream cannot be reset, but it is needed by multiple parts of this method. + // Replace the default response stream with one that can be read multiple times. + ByteArrayOutputStream out = new ByteArrayOutputStream(); + InputStream in = response.getEntityInputStream(); + ReaderWriter.writeTo(in, out); + byte[] requestEntity = out.toByteArray(); + response.setEntityInputStream(new ByteArrayInputStream(requestEntity)); + List parts = mimeReaderWriter.parseParts(response.getEntityInputStream(), response.getHeaders() .getFirst("Content-Type")); From bbf8b07c835d45eaebbd1738def9d35d640044b5 Mon Sep 17 00:00:00 2001 From: Jason Cooke Date: Wed, 4 Apr 2012 10:14:13 -0700 Subject: [PATCH 3/3] Minor name changes. --- .../services/table/implementation/TableRestProxy.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java index 54b58bd8f20a..0e4467856508 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/TableRestProxy.java @@ -706,11 +706,10 @@ private DataSource createBatchDeleteEntityPart(String table, String partitionKey private List parseBatchResponse(ClientResponse response, BatchOperations operations) throws IOException { // Default stream cannot be reset, but it is needed by multiple parts of this method. // Replace the default response stream with one that can be read multiple times. - ByteArrayOutputStream out = new ByteArrayOutputStream(); - InputStream in = response.getEntityInputStream(); - ReaderWriter.writeTo(in, out); - byte[] requestEntity = out.toByteArray(); - response.setEntityInputStream(new ByteArrayInputStream(requestEntity)); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + InputStream inputStream = response.getEntityInputStream(); + ReaderWriter.writeTo(inputStream, byteArrayOutputStream); + response.setEntityInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); List parts = mimeReaderWriter.parseParts(response.getEntityInputStream(), response.getHeaders() .getFirst("Content-Type"));