Author: ningjiang
Date: Wed Dec 15 05:15:54 2010
New Revision: 1049432
URL: http://svn.apache.org/viewvc?rev=1049432&view=rev
Log:
CAMEL-3426 Make sure the callback.done is called when the CXF producer is
calling a oneway operation
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java
(with props)
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java
(with props)
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
(with props)
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/GreeterImpl.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=1049432&r1=1049431&r2=1049432&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 Dec 15 05:15:54 2010
@@ -69,7 +69,7 @@ public class CxfProducer extends Default
this.endpoint = endpoint;
client = endpoint.createClient();
}
-
+
// As the cxf client async and sync api is implement different,
// so we don't delegate the sync process call to the async process
public boolean process(Exchange camelExchange, AsyncCallback callback) {
@@ -93,6 +93,9 @@ public class CxfProducer extends Default
// send the CXF async request
client.invoke(cxfClientCallback, boi, getParams(endpoint,
camelExchange),
invocationContext, cxfExchange);
+ if (boi.getOperationInfo().isOneWay()) {
+ callback.done(false);
+ }
} catch (Throwable ex) {
// error occurred before we had a chance to go async
// so set exception and invoke callback true
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java?rev=1049432&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java
Wed Dec 15 05:15:54 2010
@@ -0,0 +1,82 @@
+/**
+ * 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.itest.greeter;
+
+import java.io.File;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CamelFileGreeterOneWayTest extends CamelSpringTestSupport {
+
+ private static final transient Log LOG =
LogFactory.getLog(CamelGreeterTest.class);
+
+ private static Endpoint endpoint;
+ private static GreeterImpl greeterImpl;
+
+ @BeforeClass
+ public static void startServer() throws Exception {
+ // Start the Greeter Server
+ greeterImpl = new GreeterImpl();
+ String address = "http://localhost:9000/SoapContext/SoapPort";
+ endpoint = Endpoint.publish(address, greeterImpl);
+ LOG.info("The WS endpoint is published! ");
+ }
+
+ @AfterClass
+ public static void stopServer() throws Exception {
+ // Shutdown the Greeter Server
+ if (endpoint != null) {
+ endpoint.stop();
+ endpoint = null;
+ }
+ }
+
+ @Test
+ public void testMocksAreValid() throws Exception {
+ deleteDirectory("target/messages/input/");
+ greeterImpl.resetOneWayCounter();
+ ProducerTemplate template = context.createProducerTemplate();
+ template.sendBodyAndHeader("file://target/messages/input/", "Hello
World", Exchange.FILE_NAME, "hello.txt");
+
+ // Sleep a while and wait for the message whole processing
+ Thread.sleep(4000);
+ template.stop();
+
+ // make sure the greeter is called
+ assertEquals("The oneway operation of greeter should be called", 1,
greeterImpl.getOneWayCounter());
+
+ File file = new File("target/messages/input/hello.txt");
+ assertFalse("File " + file + " should be deleted", file.exists());
+ }
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml");
+ }
+
+}
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java?rev=1049432&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java
Wed Dec 15 05:15:54 2010
@@ -0,0 +1,30 @@
+/**
+ * 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.itest.greeter;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cxf.CxfConstants;
+
+public class FilePrepareRequest implements Processor {
+ public void process(Exchange exchange) throws Exception {
+ String request = exchange.getIn().getBody(String.class);
+ exchange.getOut().setBody(request);
+ exchange.getOut().setHeader(CxfConstants.OPERATION_NAME,
"greetMeOneWay");
+ }
+
+}
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/FilePrepareRequest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/GreeterImpl.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/GreeterImpl.java?rev=1049432&r1=1049431&r2=1049432&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/GreeterImpl.java
(original)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/greeter/GreeterImpl.java
Wed Dec 15 05:15:54 2010
@@ -31,6 +31,7 @@ public class GreeterImpl implements Gree
private static final Logger LOG =
Logger.getLogger(GreeterImpl.class.getPackage().getName());
+ private int oneWayCounter;
public String greetMe(String me) {
LOG.info("Executing operation greetMe");
@@ -43,6 +44,7 @@ public class GreeterImpl implements Gree
LOG.info("Executing operation greetMeOneWay");
LOG.info("Executing operation greetMeOneWay\n");
LOG.info("Hello there " + me);
+ oneWayCounter++;
}
public String sayHi() {
@@ -60,6 +62,14 @@ public class GreeterImpl implements Gree
LOG.info("Executing operation pingMe, throwing PingMeFault
exception\n");
throw new PingMeFault("PingMeFault raised by server", faultDetail);
}
+
+ public int getOneWayCounter() {
+ return oneWayCounter;
+ }
+
+ public void resetOneWayCounter() {
+ oneWayCounter = 0;
+ }
}
Added:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml?rev=1049432&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
(added)
+++
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
Wed Dec 15 05:15:54 2010
@@ -0,0 +1,55 @@
+<?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"
+
+ 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
+ ">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+
+ <cxf:cxfEndpoint id="serviceEndpoint"
address="http://localhost:9000/SoapContext/SoapPort"
+ wsdlURL="wsdl/hello_world.wsdl"
+ serviceClass="org.apache.hello_world_soap_http.Greeter"
+ endpointName="s:SoapOverHttp"
+ serviceName="s:SOAPService"
+ xmlns:s="http://apache.org/hello_world_soap_http">
+ <cxf:properties>
+ <entry key="setDefaultBus" value="false"/>
+ </cxf:properties>
+ </cxf:cxfEndpoint>
+
+ <bean id="prepareRequest"
class="org.apache.camel.itest.greeter.FilePrepareRequest"/>
+
+ <!-- START SNIPPET: example -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="file:target/messages/input?delete=true"/>
+ <process ref="prepareRequest"/>
+ <to uri="cxf://bean:serviceEndpoint"/>
+ </route>
+ </camelContext>
+ <!-- END SNIPPET: example -->
+
+</beans>
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/greeter/CamelFileGreeterOneWayTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml