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 2012/11/27 09:52:41 UTC
svn commit: r1414022 - 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/
Author: ningjiang
Date: Tue Nov 27 08:52:40 2012
New Revision: 1414022
URL: http://svn.apache.org/viewvc?rev=1414022&view=rev
Log:
CAMEL-5823 CxfConsumer should not populate the cxf response with the original input message if the cxfExchange is oneway, with thanks to Aki
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfOneWayRouteTest.java
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfOneWayRouteBeans.xml
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
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=1414022&r1=1414021&r2=1414022&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 Tue Nov 27 08:52:40 2012
@@ -277,6 +277,10 @@ public class DefaultCxfBinding implement
public void populateCxfResponseFromExchange(Exchange camelExchange,
org.apache.cxf.message.Exchange cxfExchange) {
+ if (cxfExchange.isOneWay()) {
+ return;
+ }
+
// create response context
Map<String, Object> responseContext = new HashMap<String, Object>();
Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfOneWayRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfOneWayRouteTest.java?rev=1414022&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfOneWayRouteTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfOneWayRouteTest.java Tue Nov 27 08:52:40 2012
@@ -0,0 +1,128 @@
+/**
+ * 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.io.ByteArrayOutputStream;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.OnExceptionDefinition;
+import org.apache.camel.processor.ErrorHandler;
+import org.apache.camel.processor.exceptionpolicy.ExceptionPolicyStrategy;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.hello_world_soap_http.Greeter;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+/**
+ * Tests a cxf routing scenario from an oneway cxf EP to a file EP to not forward the old input
+ * back to the oneway cxf EP.
+ */
+public class CxfOneWayRouteTest extends CamelSpringTestSupport {
+ private static final QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
+ private static final QName PORT_NAME = new QName("http://apache.org/hello_world_soap_http", "SoapPort");
+ private static final String ROUTER_ADDRESS = "http://localhost:" + CXFTestSupport.getPort1() + "/CxfOneWayRouteTest/router";
+
+ private static Exception bindingException;
+ private static boolean bindingDone;
+
+ @Before
+ public void setup() {
+ bindingException = null;
+ bindingDone = false;
+ }
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ // we can put the http conduit configuration here
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfOneWayRouteBeans.xml");
+ }
+
+ protected Greeter getCXFClient() throws Exception {
+ Service service = Service.create(SERVICE_NAME);
+ service.addPort(PORT_NAME , "http://schemas.xmlsoap.org/soap/", ROUTER_ADDRESS);
+ Greeter greeter = service.getPort(PORT_NAME, Greeter.class);
+ return greeter;
+ }
+
+ @Test
+ public void testInvokingOneWayServiceFromCXFClient() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedFileExists("target/camel-file/cxf-oneway-route");
+
+ Greeter client = getCXFClient();
+ client.greetMeOneWay("lemac");
+
+ // may need to wait until the oneway call completes
+ long waitUntil = System.currentTimeMillis() + 10000;
+ while (!bindingDone && System.currentTimeMillis() < waitUntil) {
+ Thread.sleep(1000);
+ }
+
+ assertMockEndpointsSatisfied();
+ assertNull("exception occured: " + bindingException, bindingException);
+ }
+
+ public static class TestProcessor implements Processor {
+ static final byte[] MAGIC = {(byte)0xca, 0x3e, 0x1e};
+
+ public void process(Exchange exchange) throws Exception {
+ // adding some binary segment
+ String msg = exchange.getIn().getBody(String.class);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bos.write(MAGIC);
+ bos.write(msg.getBytes());
+ exchange.getIn().setBody(bos.toByteArray());
+ }
+ }
+
+ public static class TestCxfBinding extends DefaultCxfBinding {
+ @Override
+ public void populateCxfResponseFromExchange(Exchange camelExchange, org.apache.cxf.message.Exchange cxfExchange) {
+ try {
+ super.populateCxfResponseFromExchange(camelExchange, cxfExchange);
+ } catch (RuntimeException e) {
+ bindingException = e;
+ throw e;
+ } finally {
+ bindingDone = true;
+ }
+ }
+
+ }
+}
Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfOneWayRouteBeans.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfOneWayRouteBeans.xml?rev=1414022&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfOneWayRouteBeans.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfOneWayRouteBeans.xml Tue Nov 27 08:52:40 2012
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cxf="http://camel.apache.org/schema/cxf"
+ xmlns:s="http://apache.org/hello_world_soap_http"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <bean id="testBinding" class="org.apache.camel.component.cxf.CxfOneWayRouteTest$TestCxfBinding"/>
+ <bean id="testProcessor" class="org.apache.camel.component.cxf.CxfOneWayRouteTest$TestProcessor"/>
+
+ <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:${CXFTestSupport.port1}/CxfOneWayRouteTest/router"
+ serviceClass="org.apache.hello_world_soap_http.GreeterImpl"
+ endpointName="s:SoapPort"
+ serviceName="s:SOAPService"/>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint?dataFormat=PAYLOAD&cxfBinding=#testBinding" />
+ <to uri="log:org.apache.camel?level=DEBUG" />
+ <to uri="bean:testProcessor" />
+ <to uri="file://target/camel-file/cxf-oneway-route"/>
+ <to uri="mock:result" />
+ </route>
+ </camelContext>
+
+</beans>