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 17:10:23 UTC
svn commit: r1376533 -
/camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
Author: dkulp
Date: Thu Aug 23 15:10:22 2012
New Revision: 1376533
URL: http://svn.apache.org/viewvc?rev=1376533&view=rev
Log:
Merged revisions 1376523 via git cherry-pick from
https://svn.apache.org/repos/asf/camel/trunk
........
r1376523 | dkulp | 2012-08-23 10:56:36 -0400 (Thu, 23 Aug 2012) | 2 lines
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/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
Modified: camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java?rev=1376533&r1=1376532&r2=1376533&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java (original)
+++ camel/branches/camel-2.10.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java Thu Aug 23 15:10:22 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) {