From 3e422edc43df4ee067ea30199584b48743245730 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 10:22:47 -0800 Subject: [PATCH 1/7] fix for issue 188, broker properties mapper --- .../serviceBus/implementation/BrokerPropertiesMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java index a01aa2aed43b..eefbae626684 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/implementation/BrokerPropertiesMapper.java @@ -28,7 +28,7 @@ public class BrokerPropertiesMapper { public BrokerProperties fromString(String value) throws IllegalArgumentException { ObjectMapper mapper = new ObjectMapper(); try { - return mapper.readValue(value.getBytes(), BrokerProperties.class); + return mapper.readValue(value.getBytes("UTF-8"), BrokerProperties.class); } catch (JsonParseException e) { throw new IllegalArgumentException(e); From 32b0c8be339fd2c2bfe1012ec107e5104d8b0939 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 10:29:13 -0800 Subject: [PATCH 2/7] fix for issue 189, unicode issues in BrokeredMessage --- .../services/serviceBus/models/BrokeredMessage.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/BrokeredMessage.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/BrokeredMessage.java index a2518f45afd9..3c222a52e793 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/BrokeredMessage.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/serviceBus/models/BrokeredMessage.java @@ -16,6 +16,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -70,7 +71,12 @@ public BrokeredMessage(byte[] body) { */ public BrokeredMessage(String body) { this(new BrokerProperties()); - this.body = (body == null) ? null : new ByteArrayInputStream(body.getBytes()); + try { + this.body = (body == null) ? null : new ByteArrayInputStream(body.getBytes("UTF-8")); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } /** From 7595d281c8a84dc1ded5121887f4ab04a3b7c1d9 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 10:52:13 -0800 Subject: [PATCH 3/7] fix for issue 191, unicode issues in BlobOperationRestProxy.java --- .../implementation/BlobOperationRestProxy.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java index 24adf87f4a23..5b865241508f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobOperationRestProxy.java @@ -16,6 +16,7 @@ package com.microsoft.windowsazure.services.blob.implementation; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; @@ -808,7 +809,8 @@ public void breakLease(String container, String blob, String leaseId) throws Ser @Override @Deprecated - public void breakLease(String container, String blob, String leaseId, BlobServiceOptions options) throws ServiceException { + public void breakLease(String container, String blob, String leaseId, BlobServiceOptions options) + throws ServiceException { breakLease(container, blob, options); } @@ -819,8 +821,8 @@ public BreakLeaseResult breakLease(String container, String blob) throws Service @Override public BreakLeaseResult breakLease(String container, String blob, BlobServiceOptions options) - throws ServiceException { - ClientResponse response = doLeaseOperation("break", container, blob, null, options, null); + throws ServiceException { + ClientResponse response = doLeaseOperation("break", container, blob, null, options, null); BreakLeaseResult result = new BreakLeaseResult(); result.setRemainingLeaseTimeInSeconds(Integer.parseInt(response.getHeaders().getFirst("x-ms-lease-time"))); @@ -836,7 +838,8 @@ private AcquireLeaseResult putLeaseImpl(String leaseAction, String container, St return result; } - private ClientResponse doLeaseOperation(String leaseAction, String container, String blob, String leaseId, BlobServiceOptions options, AccessCondition accessCondition) { + private ClientResponse doLeaseOperation(String leaseAction, String container, String blob, String leaseId, + BlobServiceOptions options, AccessCondition accessCondition) { String path = createPathFromContainer(container); WebResource webResource = getResource(options).path(path).path(blob).queryParam("comp", "lease"); @@ -941,7 +944,12 @@ public void createBlobBlock(String container, String blob, String blockId, Input CreateBlobBlockOptions options) throws ServiceException { String path = createPathFromContainer(container); WebResource webResource = getResource(options).path(path).path(blob).queryParam("comp", "block"); - webResource = addOptionalQueryParam(webResource, "blockid", new String(Base64.encode(blockId))); + try { + webResource = addOptionalQueryParam(webResource, "blockid", new String(Base64.encode(blockId), "UTF-8")); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); From dbff29a150ea6f682ea713873f40eff3b6511883 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 17:15:21 -0800 Subject: [PATCH 4/7] update the unicode issues in HmacSHA256Sign file, issue 192#. --- .../blob/implementation/HmacSHA256Sign.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/HmacSHA256Sign.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/HmacSHA256Sign.java index 71a68bd061cc..e40607c67522 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/HmacSHA256Sign.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/HmacSHA256Sign.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.microsoft.windowsazure.services.blob.implementation; @@ -33,8 +33,8 @@ public String sign(String stringToSign) { Mac hmac = Mac.getInstance("hmacSHA256"); hmac.init(new SecretKeySpec(Base64.decode(accessKey), "hmacSHA256")); - byte[] digest = hmac.doFinal(stringToSign.getBytes("UTF8")); - return new String(Base64.encode(digest)); + byte[] digest = hmac.doFinal(stringToSign.getBytes("UTF-8")); + return new String(Base64.encode(digest), "UTF-8"); } catch (Exception e) { throw new IllegalArgumentException("accessKey", e); From 3ff10d54740284ef88f77028a1b874f18dc0917f Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 17:33:01 -0800 Subject: [PATCH 5/7] fix base64 string adapter encoding issue, issue #193. --- .../utils/pipeline/Base64StringAdapter.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Base64StringAdapter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Base64StringAdapter.java index 975bc675e4bb..f9aedb2faf94 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Base64StringAdapter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Base64StringAdapter.java @@ -2,15 +2,15 @@ * Copyright Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.microsoft.windowsazure.services.core.utils.pipeline; @@ -25,7 +25,7 @@ public class Base64StringAdapter extends XmlAdapter { @Override public String marshal(String arg0) throws Exception { - return new String(Base64.encode(arg0)); + return new String(Base64.encode(arg0), "UTF-8"); } @Override From 225aa9aef3aca18a9af284a8eabb825fa0c69d7b Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 17:40:54 -0800 Subject: [PATCH 6/7] fix issue #194, unicode issue in DefaultEdmValueConverter.java --- .../windowsazure/services/table/Exports.java | 4 +- .../DefaultEdmValueConterter.java | 90 ------------------- .../implementation/AtomReaderWriterTests.java | 2 +- 3 files changed, 3 insertions(+), 93 deletions(-) delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConterter.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java index 485104a66a29..6be3e3c25264 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/Exports.java @@ -17,7 +17,7 @@ import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.core.UserAgentFilter; import com.microsoft.windowsazure.services.table.implementation.AtomReaderWriter; -import com.microsoft.windowsazure.services.table.implementation.DefaultEdmValueConterter; +import com.microsoft.windowsazure.services.table.implementation.DefaultEdmValueConverter; import com.microsoft.windowsazure.services.table.implementation.DefaultXMLStreamFactory; import com.microsoft.windowsazure.services.table.implementation.HttpReaderWriter; import com.microsoft.windowsazure.services.table.implementation.MimeReaderWriter; @@ -39,7 +39,7 @@ public void register(Builder.Registry registry) { registry.add(AtomReaderWriter.class); registry.add(MimeReaderWriter.class); registry.add(HttpReaderWriter.class); - registry.add(EdmValueConverter.class, DefaultEdmValueConterter.class); + registry.add(EdmValueConverter.class, DefaultEdmValueConverter.class); registry.add(UserAgentFilter.class); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConterter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConterter.java deleted file mode 100644 index 8d1aff2334cb..000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConterter.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright Microsoft Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.microsoft.windowsazure.services.table.implementation; - -import java.text.ParseException; -import java.util.Date; -import java.util.UUID; - -import javax.inject.Inject; - -import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; -import com.microsoft.windowsazure.services.table.EdmValueConverter; -import com.microsoft.windowsazure.services.table.models.EdmType; -import com.sun.jersey.core.util.Base64; - -public class DefaultEdmValueConterter implements EdmValueConverter { - - private final ISO8601DateConverter iso8601DateConverter; - - @Inject - public DefaultEdmValueConterter(ISO8601DateConverter iso8601DateConverter) { - this.iso8601DateConverter = iso8601DateConverter; - } - - @Override - public String serialize(String edmType, Object value) { - if (value == null) - return null; - - String serializedValue; - if (value instanceof Date) { - serializedValue = iso8601DateConverter.format((Date) value); - } - else if (value instanceof byte[]) { - serializedValue = new String(Base64.encode((byte[]) value)); - } - else { - serializedValue = value.toString(); - } - - return serializedValue; - } - - @Override - public Object deserialize(String edmType, String value) { - if (edmType == null) - return value; - - if (EdmType.DATETIME.equals(edmType)) { - try { - return iso8601DateConverter.parse(value); - } - catch (ParseException e) { - throw new RuntimeException(e); - } - } - else if (EdmType.BOOLEAN.equals(edmType)) { - return Boolean.parseBoolean(value); - } - else if (EdmType.DOUBLE.equals(edmType)) { - return Double.parseDouble(value); - } - else if (EdmType.INT32.equals(edmType)) { - return Integer.parseInt(value); - } - else if (EdmType.INT64.equals(edmType)) { - return Long.parseLong(value); - } - else if (EdmType.BINARY.equals(edmType)) { - return Base64.decode(value); - } - else if (EdmType.GUID.equals(edmType)) { - return UUID.fromString(value); - } - - return value; - } -} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java index 17578984f68c..1a2fd1ef0895 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/implementation/AtomReaderWriterTests.java @@ -32,7 +32,7 @@ public class AtomReaderWriterTests extends IntegrationTestBase { public void parseTableEntriesWorks() throws Exception { // Arrange AtomReaderWriter atom = new AtomReaderWriter(new DefaultXMLStreamFactory(), new DefaultDateFactory(), - new ISO8601DateConverter(), new DefaultEdmValueConterter(new ISO8601DateConverter())); + new ISO8601DateConverter(), new DefaultEdmValueConverter(new ISO8601DateConverter())); String feed = "\r\n" + "\r\n" + " Tables\r\n" From 0ecdd94a252532b6b0b4518244b0444812ce9317 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 6 Mar 2013 17:41:47 -0800 Subject: [PATCH 7/7] add the missing DefaultEdmValueConverter.java file --- .../DefaultEdmValueConverter.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java new file mode 100644 index 000000000000..cdf08312d8ae --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/implementation/DefaultEdmValueConverter.java @@ -0,0 +1,90 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.microsoft.windowsazure.services.table.implementation; + +import java.text.ParseException; +import java.util.Date; +import java.util.UUID; + +import javax.inject.Inject; + +import com.microsoft.windowsazure.services.blob.implementation.ISO8601DateConverter; +import com.microsoft.windowsazure.services.table.EdmValueConverter; +import com.microsoft.windowsazure.services.table.models.EdmType; +import com.sun.jersey.core.util.Base64; + +public class DefaultEdmValueConverter implements EdmValueConverter { + + private final ISO8601DateConverter iso8601DateConverter; + + @Inject + public DefaultEdmValueConverter(ISO8601DateConverter iso8601DateConverter) { + this.iso8601DateConverter = iso8601DateConverter; + } + + @Override + public String serialize(String edmType, Object value) { + if (value == null) + return null; + + String serializedValue; + if (value instanceof Date) { + serializedValue = iso8601DateConverter.format((Date) value); + } + else if (value instanceof byte[]) { + serializedValue = new String(Base64.encode((byte[]) value)); + } + else { + serializedValue = value.toString(); + } + + return serializedValue; + } + + @Override + public Object deserialize(String edmType, String value) { + if (edmType == null) + return value; + + if (EdmType.DATETIME.equals(edmType)) { + try { + return iso8601DateConverter.parse(value); + } + catch (ParseException e) { + throw new RuntimeException(e); + } + } + else if (EdmType.BOOLEAN.equals(edmType)) { + return Boolean.parseBoolean(value); + } + else if (EdmType.DOUBLE.equals(edmType)) { + return Double.parseDouble(value); + } + else if (EdmType.INT32.equals(edmType)) { + return Integer.parseInt(value); + } + else if (EdmType.INT64.equals(edmType)) { + return Long.parseLong(value); + } + else if (EdmType.BINARY.equals(edmType)) { + return Base64.decode(value); + } + else if (EdmType.GUID.equals(edmType)) { + return UUID.fromString(value); + } + + return value; + } +}