camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7025 fixed the NPE of StaxConverter
Date Mon, 02 Dec 2013 06:51:03 GMT
CAMEL-7025 fixed the NPE of StaxConverter


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/78f3531d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/78f3531d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/78f3531d

Branch: refs/heads/camel-2.12.x
Commit: 78f3531d3625b50c7a0a5c91966b03469806b905
Parents: cdb5794
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Dec 2 14:38:20 2013 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Dec 2 14:50:38 2013 +0800

----------------------------------------------------------------------
 .../apache/camel/converter/jaxp/StaxConverter.java    | 14 ++++++++++++--
 .../camel/converter/jaxp/StaxConverterTest.java       |  5 ++---
 2 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/78f3531d/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 5469df5..ca16a11 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/78f3531d/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 5fe411b..3caba1f 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());
@@ -74,7 +74,6 @@ public class StaxConverterTest extends ContextTestSupport {
         assertNotNull(output);
 
         String result = new String(output.toByteArray(), UTF_8.name());
-
         boolean equals = TEST_XML_WITH_XML_HEADER.equals(result) || TEST_XML_WITH_XML_HEADER_ISO_8859_1.equals(result);
         assertTrue("Should match header", equals);
     }
@@ -93,7 +92,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()) {


Mime
View raw message