camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1097912 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/converter/CxfPayloadConverter.java test/java/org/apache/camel/component/cxf/converter/CxfPayloadConverterTest.java
Date Fri, 29 Apr 2011 18:56:23 GMT
Author: davsclaus
Date: Fri Apr 29 18:56:22 2011
New Revision: 1097912

URL: http://svn.apache.org/viewvc?rev=1097912&view=rev
Log:
CAMEL-3917: Fixed issue with CxfPayloadConverter. Thanks to Aki Yoshida for patch.

Modified:
    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/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=1097912&r1=1097911&r2=1097912&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
Fri Apr 29 18:56:22 2011
@@ -32,12 +32,13 @@ import org.apache.camel.TypeConverter;
 import org.apache.camel.component.cxf.CxfPayload;
 import org.apache.camel.spi.TypeConverterRegistry;
 
-
 @Converter
 public final class CxfPayloadConverter {
+
     private CxfPayloadConverter() {
         // Helper class
     }
+
     @Converter
     public static <T> CxfPayload<T> documentToCxfPayload(Document doc, Exchange
exchange) {
         return elementToCxfPayload(doc.getDocumentElement(), exchange);
@@ -87,7 +88,7 @@ public final class CxfPayloadConverter {
                 return (T) documentToCxfPayload(document, exchange);
             }
             // maybe we can convert via an InputStream
-            CxfPayload<?> p = null;
+            CxfPayload<?> p;
             p = convertVia(InputStream.class, exchange, value, registry);
             if (p != null) {
                 return (T) p;
@@ -97,6 +98,8 @@ public final class CxfPayloadConverter {
             if (p != null) {
                 return (T) p;
             }
+            // no we could not do it currently
+            return (T) Void.TYPE;
         }
         // Convert a CxfPayload into something else
         if (CxfPayload.class.isAssignableFrom(value.getClass())) {
@@ -111,6 +114,9 @@ public final class CxfPayloadConverter {
                 NodeList nodeList = cxfPayloadToNodeList((CxfPayload<?>) value, exchange);
                 if (nodeList.getLength() > 0) {
                     return tc.convertTo(type, nodeList.item(0));
+                } else {
+                    // no we could not do it currently
+                    return (T) Void.TYPE;
                 }
             }
         }

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=1097912&r1=1097911&r2=1097912&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
Fri Apr 29 18:56:22 2011
@@ -27,6 +27,7 @@ import javax.xml.parsers.DocumentBuilder
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import org.apache.camel.component.cxf.CxfPayload;
@@ -37,6 +38,7 @@ import org.junit.Test;
 public class CxfPayloadConverterTest extends ExchangeTestSupport {
     private Document document;
     private CxfPayload<String[]> payload;
+    private CxfPayload<String[]> emptyPayload;
     private FileInputStream inputStream;
 
     @Override
@@ -51,6 +53,7 @@ public class CxfPayloadConverterTest ext
         List<Element> body = new ArrayList<Element>();
         body.add(document.getDocumentElement());
         payload = new CxfPayload<String[]>(new ArrayList<String[]>(), body);
+        emptyPayload = new CxfPayload<String[]>(new ArrayList<String[]>(), new
ArrayList<Element>());
         inputStream = new FileInputStream(file);
     }
 
@@ -92,4 +95,22 @@ public class CxfPayloadConverterTest ext
         assertTrue(inputStream instanceof InputStream);       
     }
 
+    @Test
+    public void testCxfPayloadToNode() {
+        // call the payload conversion that works
+        exchange.getIn().setBody(payload);
+        Node node = exchange.getIn().getBody(Node.class);
+        assertNotNull(node);
+        
+        // do the empty conversion
+        exchange.getIn().setBody(emptyPayload);
+        node = exchange.getIn().getBody(Node.class);
+        assertNull(node);
+
+        // do the same one that worked before
+        exchange.getIn().setBody(payload);
+        node = exchange.getIn().getBody(Node.class);
+        assertNotNull(node);
+    }
+
 }



Mime
View raw message