From 5959dfb02a80d067c2141e26ea26028e74cab1f0 Mon Sep 17 00:00:00 2001 From: challenh Date: Fri, 6 Jun 2014 23:40:06 +0800 Subject: [PATCH] [OLINGO-318]client should base64encode edm.binary data, not as URLSafeString --- .../olingo/commons/core/edm/primitivetype/EdmBinary.java | 7 ++++++- .../commons/core/edm/primitivetype/EdmBinaryTest.java | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java index ee85d1722..f7cf9afcd 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinary.java @@ -19,6 +19,7 @@ package org.apache.olingo.commons.core.edm.primitivetype; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.StringUtils; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; /** @@ -124,6 +125,10 @@ public class EdmBinary extends SingletonPrimitiveType { "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); } - return Base64.encodeBase64URLSafeString(byteArrayValue); + return base64EncodeToString(byteArrayValue); + } + + private static String base64EncodeToString(byte[] bytes){ + return StringUtils.newStringUtf8(Base64.encodeBase64(bytes, false)); } } diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java index 95c93f87e..f52c32f56 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmBinaryTest.java @@ -66,12 +66,12 @@ public class EdmBinaryTest extends PrimitiveTypeBaseTest { public void valueToString() throws Exception { final byte[] binary = new byte[]{(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF}; - assertEquals("qrvM3e7_", instance.valueToString(binary, null, null, null, null, null)); + assertEquals("qrvM3e7/", instance.valueToString(binary, null, null, null, null, null)); - assertEquals("qrvM3e7_", instance.valueToString(binary, null, 6, null, null, null)); - assertEquals("qrvM3e7_", instance.valueToString(binary, null, Integer.MAX_VALUE, null, null, null)); + assertEquals("qrvM3e7/", instance.valueToString(binary, null, 6, null, null, null)); + assertEquals("qrvM3e7/", instance.valueToString(binary, null, Integer.MAX_VALUE, null, null, null)); - assertEquals("qg", instance.valueToString(new Byte[]{new Byte((byte) 170)}, null, null, null, null, null)); + assertEquals("qg==", instance.valueToString(new Byte[]{new Byte((byte) 170)}, null, null, null, null, null)); expectFacetsErrorInValueToString(instance, binary, null, 3, null, null, null);