Author: davsclaus
Date: Wed Nov 18 11:05:29 2009
New Revision: 881719

URL: http://svn.apache.org/viewvc?rev=881719&view=rev
Log:
CAMEL-2196: CxfProducer improved to accept body in POJO mode without having to 
be wrapped as list. This also fixed a NPE issue as before it would just send 
null.

Modified:
    
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    
camel/trunk/examples/camel-example-cxf-async/src/main/java/org/apache/camel/example/client/CamelClient.java

Modified: 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=881719&r1=881718&r2=881719&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 Wed Nov 18 11:05:29 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.cxf;
 
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -155,20 +156,37 @@
      * Get the parameters for the web service operation
      */
     private Object[] getParams(CxfEndpoint endpoint, Exchange exchange) {
-        
+
+        // TODO: this method should probably be more strict and validate 
(CAMEL-2195)
+
         Object[] params = null;
         if (endpoint.getDataFormat() == DataFormat.POJO) {
             List<?> list = exchange.getIn().getBody(List.class);
             if (list != null) {
                 params = list.toArray();
             } else {
-                params = new Object[0];
+                // maybe we can iterate the body and that way create a list 
for the parameters
+                // then end users do not need to trouble with List
+                Iterator it = exchange.getIn().getBody(Iterator.class);
+                if (it != null && it.hasNext()) {
+                    list = 
exchange.getContext().getTypeConverter().convertTo(List.class, it);
+                    if (list != null) {
+                        params = list.toArray();
+                    }
+                }
+                if (params == null) {
+                    // no we could not then use the body as single parameter
+                    params = new Object[1];
+                    params[0] = exchange.getIn().getBody();
+                }
             }
         } else if (endpoint.getDataFormat() == DataFormat.PAYLOAD) {
             params = new Object[1];
+            // TODO: maybe it should be mandatory body?
             params[0] = exchange.getIn().getBody(CxfPayload.class);
         } else if (endpoint.getDataFormat() == DataFormat.MESSAGE) {
             params = new Object[1];
+            // TODO: maybe it should be mandatory body?
             params[0] = exchange.getIn().getBody(InputStream.class);
         }
 

Modified: 
camel/trunk/examples/camel-example-cxf-async/src/main/java/org/apache/camel/example/client/CamelClient.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf-async/src/main/java/org/apache/camel/example/client/CamelClient.java?rev=881719&r1=881718&r2=881719&view=diff
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf-async/src/main/java/org/apache/camel/example/client/CamelClient.java
 (original)
+++ 
camel/trunk/examples/camel-example-cxf-async/src/main/java/org/apache/camel/example/client/CamelClient.java
 Wed Nov 18 11:05:29 2009
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.example.client;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.example.reportincident.InputReportIncident;
@@ -64,12 +61,8 @@
             input.setEmail("[email protected]");
             input.setPhone("55512345678");
 
-            // must add to a list otherwise CXF cannot send data
-            // TODO: camel-cxf should be able to do this itself without me 
having to create a List object
-            List data = new ArrayList();
-            data.add(input);
-
-            producer.sendBody("direct:start", data);
+            // send our input to the Camel route
+            producer.sendBody("direct:start", input);
         }
         System.out.println("... Send done");
 


Reply via email to