camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r957140 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ test/java/org/apache/camel/component/cxf/ test/resources/org/apache/camel/component/cxf/
Date Wed, 23 Jun 2010 08:15:17 GMT
Author: ningjiang
Date: Wed Jun 23 08:15:17 2010
New Revision: 957140

URL: http://svn.apache.org/viewvc?rev=957140&view=rev
Log:
CAMEL-2841 camel-cxf should support to set the response context for POJO dataformat, also
added some test code to show how to let cxf send response with xml start document

Added:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/WriteXmlDeclarationInterceptor.java
  (with props)
Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java?rev=957140&r1=957139&r2=957140&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
Wed Jun 23 08:15:17 2010
@@ -287,11 +287,9 @@ public class DefaultCxfBinding implement
         // make sure the "requestor role" property does not get propagated as we do switch
role
         responseContext.remove(Message.REQUESTOR_ROLE);
         
-        // propagate contexts
-        if (dataFormat != DataFormat.POJO) {
-            // copying response context to out message seems to cause problem in POJO mode
-            outMessage.putAll(responseContext);
-        }
+        outMessage.putAll(responseContext);
+        
+        // Do we still need to put the response context back like this
         outMessage.put(Client.RESPONSE_CONTEXT, responseContext);      
         
         if (LOG.isTraceEnabled()) {

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java?rev=957140&r1=957139&r2=957140&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerMessageTest.java
Wed Jun 23 08:15:17 2010
@@ -21,8 +21,19 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-
-public class CxfConsumerMessageTest extends CxfConsumerTest {
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.junit.Test;
+
+public class CxfConsumerMessageTest extends CamelTestSupport {
+    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 String TEST_MESSAGE = "Hello World!";
+    
     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/\">"
@@ -57,6 +68,25 @@ public class CxfConsumerMessageTest exte
             }
         };
     }
+    
+    @Test
+    public void testInvokingServiceFromCXFClient() throws Exception {
+        ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
+        ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
+        clientBean.setAddress(SIMPLE_ENDPOINT_ADDRESS);
+        clientBean.setServiceClass(HelloService.class);
+        clientBean.setBus(BusFactory.getDefaultBus());
+
+        HelloService client = (HelloService) proxyFactory.create();
+
+        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);
+        assertEquals("We should get the echo boolean result from router ", bool.toString(),
"true");
+
+    }
 
 
 }

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java?rev=957140&r1=957139&r2=957140&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadTest.java
Wed Jun 23 08:15:17 2010
@@ -28,7 +28,7 @@ import org.apache.camel.builder.RouteBui
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.cxf.binding.soap.SoapHeader;
 
-public class CxfConsumerPayloadTest extends CxfConsumerTest {
+public class CxfConsumerPayloadTest extends CxfConsumerMessageTest {
         
     private static final String ECHO_RESPONSE = "<ns1:echoResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
             + "<return xmlns=\"http://cxf.component.camel.apache.org/\">echo Hello
World!</return>"

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java?rev=957140&r1=957139&r2=957140&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
Wed Jun 23 08:15:17 2010
@@ -17,7 +17,9 @@
 
 package org.apache.camel.component.cxf;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -25,6 +27,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientFactoryBean;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.junit.Test;
@@ -34,6 +37,9 @@ public class CxfConsumerTest extends Cam
     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 String ECHO_REQUEST = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+        + "<soap:Body><ns1:echo xmlns:ns1=\"http://cxf.component.camel.apache.org/\">"
+        + "<arg0 xmlns=\"http://cxf.component.camel.apache.org/\">Hello World!</arg0></ns1:echo></soap:Body></soap:Envelope>";
 
     private static final String ECHO_OPERATION = "echo";
     private static final String ECHO_BOOLEAN_OPERATION = "echoBoolean";
@@ -54,6 +60,10 @@ public class CxfConsumerTest extends Cam
                         Object result = operation + " " + (String)parameter.get(0);
                         // Put the result back
                         exchange.getOut().setBody(result);
+                        // set up the response context which force start document
+                        Map<String, Object> map = new HashMap<String, Object>();
+                        map.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);
+                        exchange.getOut().setHeader(Client.RESPONSE_CONTEXT, map);
                     }
                 })
                 .when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_BOOLEAN_OPERATION)).process(new
Processor() {
@@ -87,7 +97,12 @@ public class CxfConsumerTest extends Cam
         Boolean bool = client.echoBoolean(Boolean.TRUE);
         assertNotNull("The result should not be null", bool);
         assertEquals("We should get the echo boolean result from router ", bool.toString(),
"true");
-
+    }
+    
+    @Test
+    public void testXmlDeclaration() throws Exception {
+        String response = template.requestBody(SIMPLE_ENDPOINT_ADDRESS, ECHO_REQUEST, String.class);
+        assertTrue("Can't find the xml declaration.", response.startsWith("<?xml version='1.0'
encoding="));
     }
 
 

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/WriteXmlDeclarationInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/WriteXmlDeclarationInterceptor.java?rev=957140&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/WriteXmlDeclarationInterceptor.java
(added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/WriteXmlDeclarationInterceptor.java
Wed Jun 23 08:15:17 2010
@@ -0,0 +1,37 @@
+/**
+ * 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 org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+//START SNIPPET: example
+public class WriteXmlDeclarationInterceptor extends AbstractPhaseInterceptor<SoapMessage>
{
+    public WriteXmlDeclarationInterceptor() {
+        super(Phase.PRE_STREAM);
+        addBefore(StaxOutInterceptor.class.getName());
+    }
+
+    public void handleMessage(SoapMessage message) throws Fault {
+        message.put("org.apache.cxf.stax.force-start-document", Boolean.TRUE);        
+    }
+
+}
+//END SNIPPET: example
\ No newline at end of file

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

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

Modified: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml?rev=957140&r1=957139&r2=957140&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml
(original)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/GreeterEndpointsRouterContext.xml
Wed Jun 23 08:15:17 2010
@@ -29,9 +29,15 @@
    <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
    <!-- Added the import for testing the CAMEL-329 -->
 
-
+   <!-- START SNIPPET: example -->
    <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"
-    		serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/>
+    		serviceClass="org.apache.hello_world_soap_http.GreeterImpl">
+        <cxf:outInterceptors>
+            <!-- This interceptor will force the CXF server send the XML start document
to client -->
+            <bean class="org.apache.camel.component.cxf.WriteXmlDeclarationInterceptor"/>
+        </cxf:outInterceptors>
+   </cxf:cxfEndpoint>
+   <!-- END SNIPPET: example --> 		
 
    <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9000/SoapContext/SoapPort"
     		wsdlURL="testutils/hello_world.wsdl"



Mime
View raw message