Author: ningjiang
Date: Sat Jun  7 20:57:14 2008
New Revision: 664432

URL: http://svn.apache.org/viewvc?rev=664432&view=rev
Log:
CAMEL-586 support to copy the camel message to cxf message

Added:
    
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
   (with props)
Modified:
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
    
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java?rev=664432&r1=664431&r2=664432&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
 Sat Jun  7 20:57:14 2008
@@ -102,10 +102,11 @@
             if (LOG.isLoggable(Level.FINEST)) {
                 LOG.finest("Get the response outMessage " + outMessage);
             }
-            if (outMessage == null) {
-                outMessage = endpoint.getBinding().createMessage();
-            }
+            // Copy the outMessage back if we set the out's body
+            org.apache.camel.Message camelMessage = result.getOut();
+            CxfBinding.copyMessage(camelMessage, outMessage);
         }
+        // set the CXF outMessage back to the exchange
         exchange.setOutMessage(outMessage);
     }
 

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java?rev=664432&r1=664431&r2=664432&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
 Sat Jun  7 20:57:14 2008
@@ -82,7 +82,7 @@
         return answer;
     }
 
-
+    // Store
     public static void storeCxfResponse(CxfExchange exchange, Message 
response) {
         // no need to process headers as we use the CXF message
         CxfMessage out = exchange.getOut();
@@ -98,6 +98,23 @@
         }
     }
 
+    // Copy the Camel message to CXF message
+    public static void copyMessage(org.apache.camel.Message camelMessage, 
org.apache.cxf.message.Message cxfMessage) {
+        InputStream is = camelMessage.getBody(InputStream.class);
+        if (is != null) {
+            cxfMessage.setContent(InputStream.class, is);
+        } else {
+            Object result = camelMessage.getBody();
+            if (result != null) {
+                if (result instanceof InputStream) {
+                    cxfMessage.setContent(InputStream.class, result);
+                } else {
+                    cxfMessage.setContent(result.getClass(), result);
+                }
+            }
+        }
+    }
+
     public static void storeCXfResponseContext(Message response, Map<String, 
Object> context) {
         if (context != null) {
             ContextPropertiesMapping.mapResponsefromCxf2Jaxws(context);

Added: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java?rev=664432&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
 Sat Jun  7 20:57:14 2008
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CxfConsumerMessageTest extends CxfConsumerTest {
+    private static final transient Log LOG = 
LogFactory.getLog(CxfConsumerMessageTest.class);
+    private static final String ECHO_METHOD = "ns1:echo 
xmlns:ns1=\"http://cxf.component.camel.apache.org/\"";;
+
+    private static final String ECHO_RESPONSE = "<soap:Envelope 
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\";>"
+            + "<soap:Body><ns1:echoResponse 
xmlns:ns1=\"http://cxf.component.camel.apache.org/\";>"
+            + "<return xmlns=\"http://cxf.component.camel.apache.org/\";>echo 
Hello World!</return>"
+            + "</ns1:echoResponse></soap:Body></soap:Envelope>";
+    private static final String ECHO_BOOLEAN_RESPONSE = "<soap:Envelope 
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\";>"
+            + "<soap:Body><ns1:echoBooleanResponse 
xmlns:ns1=\"http://cxf.component.camel.apache.org/\";>"
+            + "<return 
xmlns=\"http://cxf.component.camel.apache.org/\";>true</return>"
+            + "</ns1:echoBooleanResponse></soap:Body></soap:Envelope>";
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from(SIMPLE_ENDPOINT_URI + "&dataFormat=MESSAGE").process(new 
Processor() {
+                    public void process(final Exchange exchange) {
+                        Message in = exchange.getIn();
+                        // Get the request message
+                        String request = in.getBody(String.class);
+                        // Send the response message back
+                        if (request.indexOf(ECHO_METHOD) > 0) {
+                            exchange.getOut().setBody(ECHO_RESPONSE);
+                        } else { // echoBoolean call
+                            exchange.getOut().setBody(ECHO_BOOLEAN_RESPONSE);
+                        }
+
+                    }
+                });
+            }
+        };
+    }
+
+
+}

Propchange: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java?rev=664432&r1=664431&r2=664432&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
 Sat Jun  7 20:57:14 2008
@@ -33,14 +33,16 @@
 
 
 public class CxfConsumerTest extends ContextTestSupport {
+    protected static final String SIMPLE_ENDPOINT_ADDRESS = 
"http://localhost:28080/test";;
+    protected static final String SIMPLE_ENDPOINT_URI = "cxf://" + 
SIMPLE_ENDPOINT_ADDRESS
+        + "?serviceClass=org.apache.camel.component.cxf.HelloService";
     private static final transient Log LOG = 
LogFactory.getLog(CxfProducerRouterTest.class);
-    private static final String SIMPLE_ENDPOINT_ADDRESS = 
"http://localhost:28080/test";;
-    private static final String SIMPLE_ENDPOINT_URI = "cxf://" + 
SIMPLE_ENDPOINT_ADDRESS
-                                                       + 
"?serviceClass=org.apache.camel.component.cxf.HelloService";
+
     private static final String ECHO_OPERATION = "echo";
     private static final String ECHO_BOOLEAN_OPERATION = "echoBoolean";
     private static final String TEST_MESSAGE = "Hello World!";
 
+
     // START SNIPPET: example
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
@@ -77,8 +79,8 @@
 
         HelloService client = (HelloService) proxyFactory.create();
 
-        String result = client.echo("hello world");
-        assertEquals("We should get the echo string result from router", 
result, "echo hello world");
+        String result = client.echo(TEST_MESSAGE);
+        assertEquals("We should get the echo string result from router", 
result, "echo " + TEST_MESSAGE);
 
         Boolean bool = client.echoBoolean(Boolean.TRUE);
         assertNotNull("The result should not be null", bool);


Reply via email to