camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1362589 - in /camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf: CxfEndpoint.java converter/CxfPayloadConverter.java
Date Tue, 17 Jul 2012 18:18:11 GMT
Author: dkulp
Date: Tue Jul 17 18:18:10 2012
New Revision: 1362589

URL: http://svn.apache.org/viewvc?rev=1362589&view=rev
Log:
Some optimizations and fixes around getting the name from stax based
payloads

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

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=1362589&r1=1362588&r2=1362589&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 Jul 17 18:18:10 2012
@@ -33,7 +33,9 @@ import javax.xml.transform.stream.Stream
 import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.handler.Handler;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelException;
@@ -902,35 +904,37 @@ public class CxfEndpoint extends Default
 
         private String findName(List<Source> sources, int i) {
             Source source = sources.get(i);
+            XMLStreamReader r = null;
             if (source instanceof DOMSource) {
-                return ((Element)((DOMSource)source).getNode()).getLocalName();
+                Node nd = ((DOMSource)source).getNode();
+                if (nd instanceof Document) {
+                    nd = ((Document)nd).getDocumentElement();
+                }
+                return ((Element)nd).getLocalName();
             } else if (source instanceof StaxSource) {
                 StaxSource s = (StaxSource)source;
-                return s.getXMLStreamReader().getLocalName();
+                r = s.getXMLStreamReader();
             } else if (source instanceof StAXSource) {
                 StAXSource s = (StAXSource)source;
-                XMLStreamReader r = s.getXMLStreamReader();
-                if (r.getEventType() != XMLStreamReader.START_ELEMENT) {
-                    try {
-                        r.nextTag();
-                    } catch (XMLStreamException e) {
-                        //ignore
-                    }
-                }
-                return r.getLocalName();
+                r = s.getXMLStreamReader();
             } else if (source instanceof StreamSource) {
                 //flip to stax so we can get the name
-                XMLStreamReader reader = StaxUtils.createXMLStreamReader(source);
-                StaxSource src2 = new StaxSource(reader);
+                r = StaxUtils.createXMLStreamReader(source);
+                StaxSource src2 = new StaxSource(r);
                 sources.set(i, src2);
-                if (reader.getEventType() == XMLStreamReader.START_DOCUMENT) {
-                    try {
-                        reader.nextTag();
-                    } catch (XMLStreamException e) {
-                        //ignore
+            }
+            if (r != null) {
+                try {
+                    if (r.getEventType() == XMLStreamReader.START_DOCUMENT) {
+                        r.next();
+                    }
+                    if (r.getEventType() != XMLStreamReader.START_ELEMENT) {
+                        r.nextTag();
                     }
+                } catch (XMLStreamException e) {
+                    //ignore
                 }
-                return reader.getLocalName();
+                return r.getLocalName();
             }
             return null;
         }

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=1362589&r1=1362588&r2=1362589&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 Jul 17 18:18:10 2012
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -145,7 +146,13 @@ public final class CxfPayloadConverter {
             if (payload.getBodySources().size() == 1) {
                 TypeConverter tc = registry.lookup(type, Source.class);
                 if (tc != null) {
-                    return tc.convertTo(type, payload.getBodySources().get(0));
+                    T t = tc.convertTo(type, payload.getBodySources().get(0));
+                    if (t instanceof Document) {
+                        payload.getBodySources().set(0, new DOMSource(((Document)t).getDocumentElement()));
+                    } else if (t instanceof Source) {
+                        payload.getBodySources().set(0, (Source)t);
+                    }
+                    return t;
                 }                
             }
             TypeConverter tc = registry.lookup(type, NodeList.class);



Mime
View raw message