You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/12/10 08:43:34 UTC
[4/4] git commit: CAMEL-6854 Address the DomConverter getByte() issue
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/759b3ce0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/759b3ce0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/759b3ce0
Branch: refs/heads/camel-2.11.x
Commit: 759b3ce05ad93104ffea8bedd9177d43f6d477fc
Parents: 68b3361
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Dec 10 15:17:20 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Dec 10 15:42:47 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/759b3ce0/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/759b3ce0/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 {