camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject camel git commit: CAMEL-10080 CxfPayloadConverter to use a XMLStreamReader based conversion if applicable
Date Tue, 21 Jun 2016 10:25:25 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 0bfc8a263 -> 88c605bfa


CAMEL-10080 CxfPayloadConverter to use a XMLStreamReader based conversion if applicable


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

Branch: refs/heads/camel-2.17.x
Commit: 88c605bfae044b7fd9da3e83aeff3148c9f46938
Parents: 0bfc8a2
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Tue Jun 21 10:16:09 2016 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Tue Jun 21 12:25:19 2016 +0200

----------------------------------------------------------------------
 .../component/cxf/converter/CxfPayloadConverter.java  | 14 +++++++++++---
 .../cxf/converter/CxfPayloadConverterTest.java        | 13 +++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/88c605bf/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
index 74e0d10..196dbce 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
@@ -195,7 +195,16 @@ public final class CxfPayloadConverter {
                 if (type.isInstance(s)) {
                     return type.cast(s);
                 }
-                TypeConverter tc = registry.lookup(type, Source.class);
+                TypeConverter tc = registry.lookup(type, XMLStreamReader.class);
+                if (tc != null && (s instanceof StaxSource || s instanceof StAXSource))
{
+                    XMLStreamReader r = (s instanceof StAXSource)
+                            ? ((StAXSource)s).getXMLStreamReader() : ((StaxSource) s).getXMLStreamReader();
+                    if (payload.getNsMap() != null) {
+                        r = new DelegatingXMLStreamReader(r, payload.getNsMap());
+                    }
+                    return (T)tc.convertTo(type, r);
+                }
+                tc = registry.lookup(type, Source.class);
                 if (tc != null) {
                     XMLStreamReader r = null;
                     if (payload.getNsMap() != null) {
@@ -208,8 +217,7 @@ public final class CxfPayloadConverter {
                             s = new StAXSource(new DelegatingXMLStreamReader(r, payload.getNsMap()));
                         }
                     }
-                    T t = tc.convertTo(type, s);
-                    return t;
+                    return (T)tc.convertTo(type, s);
                 }
             }
             TypeConverter tc = registry.lookup(type, NodeList.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/88c605bf/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
index 5bf636f..8e2d46c 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
@@ -27,6 +27,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stax.StAXSource;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -36,6 +37,7 @@ import org.w3c.dom.NodeList;
 import org.apache.camel.StreamCache;
 import org.apache.camel.component.cxf.CxfPayload;
 import org.apache.camel.test.junit4.ExchangeTestSupport;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -43,6 +45,7 @@ public class CxfPayloadConverterTest extends ExchangeTestSupport {
     private Document document;
     private CxfPayload<String[]> payload;
     private CxfPayload<String[]> emptyPayload;
+    private CxfPayload<String[]> staxpayload;
     private FileInputStream inputStream;
 
     @Override
@@ -62,8 +65,11 @@ public class CxfPayloadConverterTest extends ExchangeTestSupport {
         document.getDocumentElement().normalize();
         List<Source> body = new ArrayList<Source>();
         body.add(new DOMSource(document.getDocumentElement()));
+        List<Source> staxbody = new ArrayList<Source>();
+        staxbody.add(new StAXSource(StaxUtils.createXMLStreamReader(new FileInputStream(file),
"utf-8")));
         payload = new CxfPayload<String[]>(new ArrayList<String[]>(), body, null);
         emptyPayload = new CxfPayload<String[]>(new ArrayList<String[]>(), new
ArrayList<Source>(), null);
+        staxpayload = new CxfPayload<String[]>(new ArrayList<String[]>(), staxbody,
null);
         inputStream = new FileInputStream(file);
     }
 
@@ -115,6 +121,13 @@ public class CxfPayloadConverterTest extends ExchangeTestSupport {
     }
 
     @Test
+    public void testFromCxfStAXPayload() {
+        exchange.getIn().setBody(staxpayload);
+        InputStream inputStream = exchange.getIn().getBody(InputStream.class);
+        assertTrue(inputStream instanceof InputStream);
+    }
+
+    @Test
     public void testCxfPayloadToNode() {
         // call the payload conversion that works
         exchange.getIn().setBody(payload);


Mime
View raw message