Updated Branches:
refs/heads/camel-2.11.x 1eb8c1aee -> 958157b8b
refs/heads/camel-2.12.x cdb579454 -> 78f3531d3
CAMEL-7025 fixed the NPE of StaxConverter
Conflicts:
camel-core/src/test/java/org/apache/camel/converter/jaxp/StaxConverterTest.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/958157b8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/958157b8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/958157b8
Branch: refs/heads/camel-2.11.x
Commit: 958157b8bbc23cb2be451aa293e2f8e19e84a723
Parents: 1eb8c1a
Author: Willem Jiang <[email protected]>
Authored: Mon Dec 2 14:38:20 2013 +0800
Committer: Willem Jiang <[email protected]>
Committed: Mon Dec 2 14:48:21 2013 +0800
----------------------------------------------------------------------
.../apache/camel/converter/jaxp/StaxConverter.java | 14 ++++++++++++--
.../camel/converter/jaxp/StaxConverterTest.java | 8 ++++----
2 files changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/958157b8/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
----------------------------------------------------------------------
diff --git
a/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
b/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
index dbcd4f4..2d1a93d 100644
---
a/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
+++
b/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
@@ -167,7 +167,12 @@ public class StaxConverter {
public XMLStreamReader createXMLStreamReader(InputStream in, Exchange
exchange) throws XMLStreamException {
XMLInputFactory factory = getInputFactory();
try {
- return factory.createXMLStreamReader(IOHelper.buffered(in),
IOHelper.getCharsetName(exchange, false));
+ String charsetName = IOHelper.getCharsetName(exchange, false);
+ if (charsetName == null) {
+ return factory.createXMLStreamReader(IOHelper.buffered(in));
+ } else {
+ return factory.createXMLStreamReader(IOHelper.buffered(in),
charsetName);
+ }
} finally {
returnXMLInputFactory(factory);
}
@@ -236,7 +241,12 @@ public class StaxConverter {
public XMLEventReader createXMLEventReader(InputStream in, Exchange
exchange) throws XMLStreamException {
XMLInputFactory factory = getInputFactory();
try {
- return factory.createXMLEventReader(IOHelper.buffered(in),
IOHelper.getCharsetName(exchange, false));
+ String charsetName = IOHelper.getCharsetName(exchange, false);
+ if (charsetName == null) {
+ return factory.createXMLEventReader(IOHelper.buffered(in));
+ } else {
+ return factory.createXMLEventReader(IOHelper.buffered(in),
charsetName);
+ }
} finally {
returnXMLInputFactory(factory);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/958157b8/camel-core/src/test/java/org/apache/camel/converter/jaxp/StaxConverterTest.java
----------------------------------------------------------------------
diff --git
a/camel-core/src/test/java/org/apache/camel/converter/jaxp/StaxConverterTest.java
b/camel-core/src/test/java/org/apache/camel/converter/jaxp/StaxConverterTest.java
index eba7b59..c211b62 100644
---
a/camel-core/src/test/java/org/apache/camel/converter/jaxp/StaxConverterTest.java
+++
b/camel-core/src/test/java/org/apache/camel/converter/jaxp/StaxConverterTest.java
@@ -58,7 +58,7 @@ public class StaxConverterTest extends ContextTestSupport {
output = new ByteArrayOutputStream();
// ensure UTF-8 encoding
Exchange exchange = new DefaultExchange(context);
- exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.name());
+ //exchange.setProperty(Exchange.CHARSET_NAME,
ISO_8859_1.toString());
writer =
context.getTypeConverter().mandatoryConvertTo(XMLEventWriter.class, exchange,
output);
while (reader.hasNext()) {
writer.add(reader.nextEvent());
@@ -75,8 +75,8 @@ public class StaxConverterTest extends ContextTestSupport {
String result = new String(output.toByteArray(), UTF_8.name());
- assertEquals(TEST_XML_WITH_XML_HEADER, result);
-
+ boolean equals = TEST_XML_WITH_XML_HEADER.equals(result) ||
TEST_XML_WITH_XML_HEADER_ISO_8859_1.equals(result);
+ assertTrue("Should match header", equals);
}
public void testEncodingXmlStreamReader() throws Exception {
@@ -93,7 +93,7 @@ public class StaxConverterTest extends ContextTestSupport {
output = new ByteArrayOutputStream();
// ensure UTF-8 encoding
Exchange exchange = new DefaultExchange(context);
- exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.name());
+ //exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.name());
writer =
context.getTypeConverter().mandatoryConvertTo(XMLStreamWriter.class, exchange,
output);
// copy to writer
while (reader.hasNext()) {