Updated Branches: refs/heads/camel-2.11.x f4c113fa2 -> 759b3ce05 refs/heads/camel-2.12.x 629454026 -> 4673d4306
CAMEL-6854 Address the DomConverter getByte() issue Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4673d430 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4673d430 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4673d430 Branch: refs/heads/camel-2.12.x Commit: 4673d4306a467e7d90894799f1f24f73788b02c1 Parents: 7011cc8 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Tue Dec 10 15:17:20 2013 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Tue Dec 10 15:42:23 2013 +0800 ---------------------------------------------------------------------- .../java/org/apache/camel/converter/jaxp/DomConverter.java | 8 +++++--- .../org/apache/camel/converter/jaxp/DomConverterTest.java | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/4673d430/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java index bbd7d7a..8c59219 100644 --- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java +++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/DomConverter.java @@ -18,6 +18,7 @@ package org.apache.camel.converter.jaxp; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -32,6 +33,7 @@ import org.w3c.dom.Text; import org.apache.camel.Converter; import org.apache.camel.Exchange; +import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; /** @@ -133,14 +135,14 @@ public final class DomConverter { } @Converter - public InputStream toInputStream(NodeList nodeList, Exchange exchange) throws TransformerException { + public InputStream toInputStream(NodeList nodeList, Exchange exchange) throws TransformerException, UnsupportedEncodingException { return new ByteArrayInputStream(toByteArray(nodeList, exchange)); } @Converter - public byte[] toByteArray(NodeList nodeList, Exchange exchange) throws TransformerException { + public byte[] toByteArray(NodeList nodeList, Exchange exchange) throws TransformerException, UnsupportedEncodingException { String data = toString(nodeList, exchange); - return data.getBytes(); + return data.getBytes(IOHelper.getCharsetName(exchange)); } private static void append(StringBuilder buffer, NodeList nodeList) { http://git-wip-us.apache.org/repos/asf/camel/blob/4673d430/camel-core/src/test/java/org/apache/camel/converter/jaxp/DomConverterTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/converter/jaxp/DomConverterTest.java b/camel-core/src/test/java/org/apache/camel/converter/jaxp/DomConverterTest.java index 430da07..250c202 100644 --- a/camel-core/src/test/java/org/apache/camel/converter/jaxp/DomConverterTest.java +++ b/camel-core/src/test/java/org/apache/camel/converter/jaxp/DomConverterTest.java @@ -41,7 +41,14 @@ public class DomConverterTest extends ContextTestSupport { Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello>world!</hello>"); byte[] bytes = new DomConverter().toByteArray(document.getChildNodes(), null); - assertTrue("Should be equal", ObjectHelper.equalByteArray("<hello>world!</hello>".getBytes(), bytes)); + assertTrue("Should be equal", ObjectHelper.equalByteArray("<hello>world!</hello>".getBytes("UTF-8"), bytes)); + } + + public void testDomConverterToNoAssicBytes() throws Exception { + Document document = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>\u99f1\u99ddb\u00e4r</foo>"); + + byte[] bytes = new DomConverter().toByteArray(document.getChildNodes(), null); + assertTrue("Should be equal", ObjectHelper.equalByteArray("<foo>\u99f1\u99ddb\u00e4r</foo>".getBytes("UTF-8"), bytes)); } public void testDomConverterToInteger() throws Exception {