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:31 UTC
[1/4] git commit: CAMEL-6854 Address the DomConverter getByte() issue
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 <wi...@gmail.com>
Authored: Tue Dec 10 15:17:20 2013 +0800
Committer: Willem Jiang <wi...@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 {
[3/4] git commit: CAMEL-6854 Fixed the Type conversion issue between
DOMSource and InputStream breaks on Windows with thanks to Stephan and Aki
Posted by ni...@apache.org.
CAMEL-6854 Fixed the Type conversion issue between DOMSource and InputStream breaks on Windows with thanks to Stephan and Aki
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/68b33618
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/68b33618
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/68b33618
Branch: refs/heads/camel-2.11.x
Commit: 68b3361819ac8e59a64ecd997a4788f6302c8b86
Parents: f4c113f
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Dec 10 15:01:23 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Dec 10 15:42:46 2013 +0800
----------------------------------------------------------------------
.../camel/converter/jaxp/XmlConverter.java | 28 ++++++++++++++------
.../camel/converter/jaxp/XmlConverterTest.java | 20 ++++++++++++++
2 files changed, 40 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/68b33618/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index 487314a..bf00fcc 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -17,6 +17,7 @@
package org.apache.camel.converter.jaxp;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -263,11 +264,24 @@ public class XmlConverter {
*/
@Converter
public byte[] toByteArray(Source source, Exchange exchange) throws TransformerException {
- String answer = toString(source, exchange);
- if (exchange != null) {
- return exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, answer);
+ if (source == null) {
+ return null;
+ } else if (source instanceof BytesSource) {
+ return ((BytesSource)source).getData();
} else {
- return answer.getBytes();
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ if (exchange != null) {
+ // check the camelContext properties first
+ Properties properties = ObjectHelper.getCamelPropertiesWithPrefix(OUTPUT_PROPERTIES_PREFIX,
+ exchange.getContext());
+ if (properties.size() > 0) {
+ toResult(source, new StreamResult(buffer), properties);
+ return buffer.toByteArray();
+ }
+ }
+ // using the old way to deal with it
+ toResult(source, new StreamResult(buffer));
+ return buffer.toByteArray();
}
}
@@ -870,8 +884,7 @@ public class XmlConverter {
@Converter
public InputStream toInputStream(DOMSource source, Exchange exchange) throws TransformerException, IOException {
- String s = toString(source, exchange);
- return new ByteArrayInputStream(s.getBytes());
+ return new ByteArrayInputStream(toByteArray(source, exchange));
}
/**
@@ -884,8 +897,7 @@ public class XmlConverter {
@Converter
public InputStream toInputStream(Document dom, Exchange exchange) throws TransformerException, IOException {
- String s = toString(dom, exchange);
- return new ByteArrayInputStream(s.getBytes());
+ return toInputStream(new DOMSource(dom), exchange);
}
@Converter
http://git-wip-us.apache.org/repos/asf/camel/blob/68b33618/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java b/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
index 5955354..e35a3db 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
@@ -429,6 +429,15 @@ public class XmlConverterTest extends ContextTestSupport {
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, is));
}
+ public void testToInputStreamNonAsciiFromDocument() throws Exception {
+ XmlConverter conv = new XmlConverter();
+ Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>\u99f1\u99ddb\u00e4r</foo>");
+
+ InputStream is = conv.toInputStream(doc, null);
+ assertNotNull(is);
+ assertEquals("<foo>\u99f1\u99ddb\u00e4r</foo>", context.getTypeConverter().convertTo(String.class, is));
+ }
+
public void testToDocumentFromFile() throws Exception {
XmlConverter conv = new XmlConverter();
File file = new File("src/test/resources/org/apache/camel/converter/stream/test.xml");
@@ -450,6 +459,17 @@ public class XmlConverterTest extends ContextTestSupport {
assertEquals("<foo>bar</foo>", s);
}
+ public void testToInputStreamNonAsciiByDomSource() throws Exception {
+ XmlConverter conv = new XmlConverter();
+
+ DOMSource source = conv.toDOMSource("<foo>\u99f1\u99ddb\u00e4r</foo>");
+ InputStream out = conv.toInputStream(source, null);
+ assertNotSame(source, out);
+
+ String s = context.getTypeConverter().convertTo(String.class, out);
+ assertEquals("<foo>\u99f1\u99ddb\u00e4r</foo>", s);
+ }
+
public void testToInputSource() throws Exception {
XmlConverter conv = new XmlConverter();
[4/4] git commit: CAMEL-6854 Address the DomConverter getByte() issue
Posted by ni...@apache.org.
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 {
[2/4] git commit: CAMEL-6854 Fixed the Type conversion issue between
DOMSource and InputStream breaks on Windows with thanks to Stephan and Aki
Posted by ni...@apache.org.
CAMEL-6854 Fixed the Type conversion issue between DOMSource and InputStream breaks on Windows with thanks to Stephan and Aki
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7011cc8a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7011cc8a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7011cc8a
Branch: refs/heads/camel-2.12.x
Commit: 7011cc8af0d66fcdbfa16f07237c75ff5279a4b1
Parents: 6294540
Author: Willem Jiang <wi...@gmail.com>
Authored: Tue Dec 10 15:01:23 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Tue Dec 10 15:42:23 2013 +0800
----------------------------------------------------------------------
.../camel/converter/jaxp/XmlConverter.java | 28 ++++++++++++++------
.../camel/converter/jaxp/XmlConverterTest.java | 20 ++++++++++++++
2 files changed, 40 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7011cc8a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index 39171e9..d841a15 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -17,6 +17,7 @@
package org.apache.camel.converter.jaxp;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -243,11 +244,24 @@ public class XmlConverter {
*/
@Converter
public byte[] toByteArray(Source source, Exchange exchange) throws TransformerException {
- String answer = toString(source, exchange);
- if (exchange != null) {
- return exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, answer);
+ if (source == null) {
+ return null;
+ } else if (source instanceof BytesSource) {
+ return ((BytesSource)source).getData();
} else {
- return answer.getBytes();
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ if (exchange != null) {
+ // check the camelContext properties first
+ Properties properties = ObjectHelper.getCamelPropertiesWithPrefix(OUTPUT_PROPERTIES_PREFIX,
+ exchange.getContext());
+ if (properties.size() > 0) {
+ toResult(source, new StreamResult(buffer), properties);
+ return buffer.toByteArray();
+ }
+ }
+ // using the old way to deal with it
+ toResult(source, new StreamResult(buffer));
+ return buffer.toByteArray();
}
}
@@ -840,8 +854,7 @@ public class XmlConverter {
@Converter
public InputStream toInputStream(DOMSource source, Exchange exchange) throws TransformerException, IOException {
- String s = toString(source, exchange);
- return new ByteArrayInputStream(s.getBytes());
+ return new ByteArrayInputStream(toByteArray(source, exchange));
}
/**
@@ -854,8 +867,7 @@ public class XmlConverter {
@Converter
public InputStream toInputStream(Document dom, Exchange exchange) throws TransformerException, IOException {
- String s = toString(dom, exchange);
- return new ByteArrayInputStream(s.getBytes());
+ return toInputStream(new DOMSource(dom), exchange);
}
@Converter
http://git-wip-us.apache.org/repos/asf/camel/blob/7011cc8a/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java b/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
index 5955354..e35a3db 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
@@ -429,6 +429,15 @@ public class XmlConverterTest extends ContextTestSupport {
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, is));
}
+ public void testToInputStreamNonAsciiFromDocument() throws Exception {
+ XmlConverter conv = new XmlConverter();
+ Document doc = context.getTypeConverter().convertTo(Document.class, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo>\u99f1\u99ddb\u00e4r</foo>");
+
+ InputStream is = conv.toInputStream(doc, null);
+ assertNotNull(is);
+ assertEquals("<foo>\u99f1\u99ddb\u00e4r</foo>", context.getTypeConverter().convertTo(String.class, is));
+ }
+
public void testToDocumentFromFile() throws Exception {
XmlConverter conv = new XmlConverter();
File file = new File("src/test/resources/org/apache/camel/converter/stream/test.xml");
@@ -450,6 +459,17 @@ public class XmlConverterTest extends ContextTestSupport {
assertEquals("<foo>bar</foo>", s);
}
+ public void testToInputStreamNonAsciiByDomSource() throws Exception {
+ XmlConverter conv = new XmlConverter();
+
+ DOMSource source = conv.toDOMSource("<foo>\u99f1\u99ddb\u00e4r</foo>");
+ InputStream out = conv.toInputStream(source, null);
+ assertNotSame(source, out);
+
+ String s = context.getTypeConverter().convertTo(String.class, out);
+ assertEquals("<foo>\u99f1\u99ddb\u00e4r</foo>", s);
+ }
+
public void testToInputSource() throws Exception {
XmlConverter conv = new XmlConverter();