You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2008/08/17 15:17:05 UTC

svn commit: r686607 - in /activemq/camel/trunk: components/camel-cxf/src/main/java/org/apache/camel/component/cxf/ components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/ components/camel-cxf/src/main/resources/META-INF/services/or...

Author: ningjiang
Date: Sun Aug 17 06:17:05 2008
New Revision: 686607

URL: http://svn.apache.org/viewvc?rev=686607&view=rev
Log:
CAMEL-829 Using MessageContentsList to hold the cxf producer result

Added:
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java   (with props)
    activemq/camel/trunk/components/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Modified:
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
    activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/PrepareResponse.java

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=686607&r1=686606&r2=686607&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java Sun Aug 17 06:17:05 2008
@@ -46,6 +46,7 @@
 import org.apache.cxf.frontend.ClientFactoryBean;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.BindingOperationInfo;
 
@@ -190,7 +191,11 @@
                         Object[] result = null;
                         // call for the client with the parameters
                         result = invokeClient(operationNameSpace, operationName, parameters, context);
-                        response.setContent(Object[].class, result);
+                        if (result != null) {
+                            response.setContent(List.class, new MessageContentsList(result));
+                        } else {
+                            response.setContent(List.class, new MessageContentsList());
+                        }
                         // copy the response context to the response
                         CxfBinding.storeCXfResponseContext(response, responseContext);
                         CxfBinding.storeCxfResponse(endpoint.getHeaderFilterStrategy(), exchange, response);

Added: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java?rev=686607&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java (added)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java Sun Aug 17 06:17:05 2008
@@ -0,0 +1,59 @@
+/**
+ * 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.converter;
+
+import java.util.Map;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Endpoint;
+import org.apache.cxf.message.MessageContentsList;
+
+
+/**
+ * The <a href="http://activemq.apache.org/camel/type-converter.html">Type Converters</a>
+ * for CXF related types' converting .
+ *
+ * @version $Revision$
+ */
+@Converter
+public final class CxfConverter {
+
+    private CxfConverter() {
+        // Helper class
+    }
+
+    @Converter
+    public static Object[] toArray(final MessageContentsList list) throws Exception {
+        if (list == null) {
+            throw new IllegalArgumentException("The MessageChannel is null");
+        }
+        return list.toArray();
+    }
+
+    public static MessageContentsList toMessageContentsList(final Object[] array) {
+        if (array != null) {
+            return new MessageContentsList(array);
+        } else {
+            return new MessageContentsList();
+        }
+    }
+
+
+
+
+
+}

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

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

Added: activemq/camel/trunk/components/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=686607&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ activemq/camel/trunk/components/camel-cxf/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Sun Aug 17 06:17:05 2008
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.cxf.converter
\ No newline at end of file

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java?rev=686607&r1=686606&r2=686607&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java Sun Aug 17 06:17:05 2008
@@ -32,6 +32,7 @@
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.MessageContentsList;
 
 public class CxfProducerRouterTest extends ContextTestSupport {
     private static final transient Log LOG = LogFactory.getLog(CxfProducerRouterTest.class);
@@ -90,14 +91,15 @@
         Exchange exchange = template.send("direct:EndpointA", senderExchange);
 
         org.apache.camel.Message out = exchange.getOut();
-        // The response message's body is an object array which first element is the return value of the operation,
-        // If there are some holder parameters, the holder parameter will be filled in the reset of array.
-        Object[] output = (Object[])out.getBody();
-        LOG.info("Received output text: " + output[0]);
+        // The response message's body is an MessageContentsList which first element is the return value of the operation,
+        // If there are some holder parameters, the holder parameter will be filled in the reset of List.
+        // The result will be extract from the MessageContentsList with the String class type
+        MessageContentsList result = (MessageContentsList)out.getBody();
+        LOG.info("Received output text: " + result.get(0));
         Map<String, Object> responseContext = CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT));
         assertNotNull(responseContext);
         assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING));
-        assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, output[0]);
+        assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0));
      // END SNIPPET: sending
     }
 

Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java?rev=686607&r1=686606&r2=686607&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java (original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java Sun Aug 17 06:17:05 2008
@@ -89,12 +89,12 @@
         CxfExchange exchange = sendSimpleMessage();
 
         org.apache.camel.Message out = exchange.getOut();
-        Object[] output = (Object[])out.getBody();
-        LOG.info("Received output text: " + output[0]);
+        String result = out.getBody(String.class);
+        LOG.info("Received output text: " + result);
         Map<String, Object> responseContext = CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT));
         assertNotNull(responseContext);
         assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING));
-        assertEquals("reply body on Camel", "echo " + TEST_MESSAGE, output[0]);
+        assertEquals("reply body on Camel", "echo " + TEST_MESSAGE, result);
 
     }
 
@@ -103,12 +103,12 @@
         CxfExchange exchange = sendJaxWsMessage();
 
         org.apache.camel.Message out = exchange.getOut();
-        Object[] output = (Object[])out.getBody();
-        LOG.info("Received output text: " + output[0]);
+        String result = out.getBody(String.class);
+        LOG.info("Received output text: " + result);
         Map<String, Object> responseContext = CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT));
         assertNotNull(responseContext);
         assertEquals("Get the wrong wsdl opertion name", "{http://apache.org/hello_world_soap_http}greetMe", responseContext.get("javax.xml.ws.wsdl.operation").toString());
-        assertEquals("reply body on Camel", "Hello " + TEST_MESSAGE, output[0]);
+        assertEquals("reply body on Camel", "Hello " + TEST_MESSAGE, result);
     }
 
     protected String getSimpleEndpointUri() {

Modified: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java?rev=686607&r1=686606&r2=686607&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java (original)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java Sun Aug 17 06:17:05 2008
@@ -30,12 +30,10 @@
         BankQuote oldQuote = oldExchange.getProperty(BANK_QUOTE, BankQuote.class);
         // Get the oldQute from out message body if we can't get it from the exchange
         if (oldQuote == null) {
-            Object[] oldResult = (Object[])oldExchange.getOut().getBody();
-            oldQuote = (BankQuote) oldResult[0];
+            oldQuote = oldExchange.getOut().getBody(BankQuote.class);
         }
         // Get the newQuote
-        Object[] newResult = (Object[])newExchange.getOut().getBody();
-        BankQuote newQuote = (BankQuote) newResult[0];
+        BankQuote newQuote = newExchange.getOut().getBody(BankQuote.class);
         Exchange result = null;
         BankQuote bankQuote;
 

Modified: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/PrepareResponse.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/PrepareResponse.java?rev=686607&r1=686606&r2=686607&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/PrepareResponse.java (original)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/PrepareResponse.java Sun Aug 17 06:17:05 2008
@@ -21,7 +21,7 @@
 
 public class PrepareResponse implements Processor {
     public void process(Exchange exchange) throws Exception {
-        Object[] result = (Object[]) exchange.getIn().getBody();
+        Object[] result = exchange.getIn().getBody(Object[].class);
         exchange.getOut().setBody(result[0]);
     }
 }