You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2012/08/23 16:56:36 UTC

svn commit: r1376523 - /camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java

Author: dkulp
Date: Thu Aug 23 14:56:36 2012
New Revision: 1376523

URL: http://svn.apache.org/viewvc?rev=1376523&view=rev
Log:
If JMX monitoring or something else causes the CXF payload to convert from a non-reproducible Source to a String, the entire payload will get wiped out.  Need to make sure we hold onto a reusable Source.

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

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=1376523&r1=1376522&r2=1376523&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 Thu Aug 23 14:56:36 2012
@@ -23,6 +23,8 @@ import java.util.List;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -159,7 +161,27 @@ public final class CxfPayloadConverter {
                 }
                 TypeConverter tc = registry.lookup(type, Source.class);
                 if (tc != null) {
-                    T t = tc.convertTo(type, payload.getBodySources().get(0));
+                    Source s = payload.getBodySources().get(0);
+                    if (type.isInstance(s)) {
+                        return type.cast(s);
+                    }
+                    if ((s instanceof StreamSource
+                        || s instanceof SAXSource) 
+                        && !type.isAssignableFrom(Document.class)
+                        && !type.isAssignableFrom(Source.class)) {
+                        //non-reproducible sources, we need to convert to DOMSource first
+                        //or the payload will get wiped out
+                        Document d;
+                        try {
+                            d = StaxUtils.read(s);
+                        } catch (XMLStreamException e) {
+                            throw new RuntimeException(e);
+                        }
+                        s = new DOMSource(d.getDocumentElement());
+                        payload.getBodySources().set(0, s);
+                    }
+                    
+                    T t = tc.convertTo(type, s);
                     if (t instanceof Document) {
                         payload.getBodySources().set(0, new DOMSource(((Document)t).getDocumentElement()));
                     } else if (t instanceof Source) {