Repository: olingo-odata2 Updated Branches: refs/heads/master 17beae0d0 -> f71f456e4
[OLINGO-1234]Batch response does not show the umlaut characters correctly Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/f71f456e Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/f71f456e Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/f71f456e Branch: refs/heads/master Commit: f71f456e44d7c2e045e2c1ad303c9a8666c5a78e Parents: 17beae0 Author: ramya vasanth <[email protected]> Authored: Fri Feb 16 10:01:11 2018 +0530 Committer: ramya vasanth <[email protected]> Committed: Fri Feb 16 10:01:11 2018 +0530 ---------------------------------------------------------------------- .../olingo/odata2/core/batch/BatchHelper.java | 5 ++-- .../odata2/core/batch/BatchResponseWriter.java | 4 +++ .../odata2/core/batch/BatchResponseTest.java | 27 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f71f456e/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java index 7e91548..42cd445 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java @@ -42,7 +42,7 @@ public class BatchHelper { public static final String BINARY_ENCODING = "binary"; public static final String UTF8_ENCODING = "UTF-8"; public static final String ISO_ENCODING = "ISO-8859-1"; - public static String DEFAULT_ENCODING = "UTF-8"; + public static String DEFAULT_ENCODING = "ISO-8859-1"; public static final String HTTP_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; public static final String HTTP_CONTENT_ID = "Content-Id"; public static final String MIME_HEADER_CONTENT_ID = "MimeHeader-ContentId"; @@ -145,7 +145,7 @@ public class BatchHelper { } public BodyBuilder append(String string) { - byte [] b = string.getBytes(CHARSET_ISO_8859_1); + byte [] b = string.getBytes(DEFAULT_CHARSET); put(b); return this; } @@ -223,6 +223,7 @@ public class BatchHelper { public Body() { this.content = EMPTY_BYTES; + setDefaultValues(ISO_ENCODING); } public int getLength() { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f71f456e/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java index 9dc986c..978e502 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseWriter.java @@ -24,6 +24,7 @@ import org.apache.olingo.odata2.api.commons.HttpContentType; import org.apache.olingo.odata2.api.commons.HttpHeaders; import org.apache.olingo.odata2.api.commons.HttpStatusCodes; import org.apache.olingo.odata2.api.processor.ODataResponse; +import org.apache.olingo.odata2.core.commons.ContentType; import java.util.List; @@ -109,6 +110,9 @@ public class BatchResponseWriter { writer.append(CRLF); writer.append("HTTP/1.1").append(SP).append(String.valueOf(response.getStatus().getStatusCode())).append(SP) .append(response.getStatus().getInfo()).append(CRLF); + if (response.getHeader("Content-Type") != null) { + BatchHelper.extractCharset(ContentType.parse(response.getHeader("Content-Type"))); + } appendHeader(response); if (!HttpStatusCodes.NO_CONTENT.equals(response.getStatus())) { BatchHelper.Body body = new BatchHelper.Body(response); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f71f456e/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java index 91411f0..8369f8f 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertArrayEquals; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -219,4 +220,30 @@ public class BatchResponseTest { } return data; } + + @Test + public void testissueWithHeaderHavingUmlautChars() throws BatchException, IOException { + List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>(); + String headerValue = "<notification xmlns:ns=\"http://namespace\">" + + "<code>TEST_MSG/004</code><message>Team ID 'XXX_E'äöü à is not in the defined range." + + "</message><target>Team_Identifier</target><severity>error</severity><details><detail>" + + "<code>TEST_MSG/010</code><message>" + + "This is a message text of a business exception raised by the provider.</message><target>" + + "</target><severity>warning</severity></detail></details></notification>"; + ODataResponse response = ODataResponse.entity("Walter Winter") + .status(HttpStatusCodes.OK) + .header("message", headerValue) + .contentHeader("application/xml") + .build(); + List<ODataResponse> responses = new ArrayList<ODataResponse>(1); + responses.add(response); + parts.add(BatchResponsePart.responses(responses).changeSet(false).build()); + + BatchResponseWriter writer = new BatchResponseWriter(); + ODataResponse batchResponse = writer.writeResponse(parts); + + assertNotNull(batchResponse.getEntity()); + assertTrue(batchResponse.getEntity().toString(). + contains("Team ID 'XXX_E'äöü à is not in the defined range.")); + } } \ No newline at end of file
