camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1423645 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ main/java/org/apache/camel/component/cxf/converter/ test/java/org/apache/camel/component/cxf/converter/
Date Tue, 18 Dec 2012 20:58:07 GMT
Author: dkulp
Date: Tue Dec 18 20:58:07 2012
New Revision: 1423645

URL: http://svn.apache.org/viewvc?rev=1423645&view=rev
Log:
[CAMEL-5877] Fix some issues converting to Source for CxfPayload
Modified patch from Aki Yoshida applied

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=1423645&r1=1423644&r2=1423645&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
Tue Dec 18 20:58:07 2012
@@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.WebServiceProvider;
@@ -954,7 +955,7 @@ public class CxfEndpoint extends Default
             } else if (source instanceof StAXSource) {
                 StAXSource s = (StAXSource)source;
                 r = s.getXMLStreamReader();
-            } else if (source instanceof StreamSource) {
+            } else if (source instanceof StreamSource || source instanceof SAXSource) {
                 //flip to stax so we can get the name
                 r = StaxUtils.createXMLStreamReader(source);
                 StaxSource src2 = new StaxSource(r);

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java?rev=1423645&r1=1423644&r2=1423645&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
Tue Dec 18 20:58:07 2012
@@ -17,6 +17,8 @@
 package org.apache.camel.component.cxf.converter;
 
 import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -113,11 +115,32 @@ public final class CxfPayloadConverter {
         // CxfPayloads from other types
         if (type.isAssignableFrom(CxfPayload.class)) {
             if (!value.getClass().isArray()) {
-                TypeConverter tc = registry.lookup(Source.class, value.getClass());
-                if (tc != null) {
-                    Source src = tc.convertTo(Source.class, exchange, value);
+                Source src = null;
+                // many of the common format that can have a Source created directly
+                if (value instanceof InputStream) {
+                    src = new StreamSource((InputStream)value);
+                } else if (value instanceof Reader) {
+                    src = new StreamSource((Reader)value);
+                } else if (value instanceof String) {
+                    src = new StreamSource(new StringReader((String)value));            
       
+                } else if (value instanceof Node) {
+                    src = new DOMSource((Node)value);
+                } else if (value instanceof Source) {
+                    src = (Source)src;
+                }
+                if (src == null) {
+                    // assuming staxsource is preferred, otherwise use the one preferred
+                    TypeConverter tc = registry.lookup(javax.xml.transform.stax.StAXSource.class,
value.getClass());
+                    if (tc == null) {
+                        tc = registry.lookup(Source.class, value.getClass());
+                    }
+                    if (tc != null) {
+                        src = tc.convertTo(Source.class, exchange, value);
+                    }
+                }
+                if (src != null) {
                     return (T) sourceToCxfPayload(src, exchange);
-                }                
+                }
             }
             TypeConverter tc = registry.lookup(NodeList.class, value.getClass());
             if (tc != null) {

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java?rev=1423645&r1=1423644&r2=1423645&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
Tue Dec 18 20:58:07 2012
@@ -93,7 +93,10 @@ public class CxfPayloadConverterTest ext
         exchange.getIn().setBody(inputStream);
         CxfPayload<?> payload = exchange.getIn().getBody(CxfPayload.class);
         assertTrue(payload instanceof CxfPayload);
+        assertEquals("Get a wrong size of body", 1, payload.getBodySources().size());
         assertEquals("Get a wrong size of body", 1, payload.getBody().size());
+        assertEquals("expects stream source", "streamsource", payload.getBodySources().get(0).getClass().getSimpleName().toLowerCase());
+        
     }
     
     @Test



Mime
View raw message