Author: ningjiang
Date: Fri Feb 24 05:01:47 2012
New Revision: 1293079

URL: http://svn.apache.org/viewvc?rev=1293079&view=rev
Log:
CAMEL-5035 CxfProducer should release the CXF client when the producer is 
stopped

Modified:
    
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
    
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.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=1293079&r1=1293078&r2=1293079&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
 Fri Feb 24 05:01:47 2012
@@ -69,7 +69,23 @@ public class CxfProducer extends Default
     public CxfProducer(CxfEndpoint endpoint) throws Exception {
         super(endpoint);
         this.endpoint = endpoint;
-        client = endpoint.createClient();
+    }
+    
+    @Override
+    protected void doStart() throws Exception {
+        if (client == null) {
+            client = endpoint.createClient();
+        }
+    }
+    
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        if (client != null) {
+            // It will help to release the request context map
+            client.destroy();
+            client = null;
+        }
     }
    
     // As the cxf client async and sync api is implement different,

Modified: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java?rev=1293079&r1=1293078&r2=1293079&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
 Fri Feb 24 05:01:47 2012
@@ -33,6 +33,7 @@ import org.apache.camel.component.cxf.co
 import org.apache.camel.component.cxf.converter.CxfPayloadConverter;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.cxf.bus.CXFBusFactory;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Server;
@@ -68,7 +69,8 @@ public class CxfProducerTest extends Ass
         return "http://localhost:"; + CXFTestSupport.getPort2() + "/" + 
getClass().getSimpleName() + "/test";
     }
     protected String getWrongServerAddress() {
-        return "http://localhost:"; + CXFTestSupport.getPort3() + "/" + 
getClass().getSimpleName() + "/test";
+        // Avoiding the test error on camel-cxf module
+        return "http://localhost:"; + AvailablePortFinder.getNextAvailable() + 
"/" + getClass().getSimpleName() + "/test";
     }
     
     @Before
@@ -126,6 +128,7 @@ public class CxfProducerTest extends Ass
     public void testInvokingAWrongServer() throws Exception {
         Exchange reply = sendSimpleMessage(getWrongEndpointUri());
         assertNotNull("We should get the exception here", 
reply.getException());
+        System.out.println(reply.getException());
         assertTrue(reply.getException().getCause() instanceof 
ConnectException);
         
         

Modified: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java?rev=1293079&r1=1293078&r2=1293079&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
 Fri Feb 24 05:01:47 2012
@@ -71,6 +71,8 @@ public class CxfEndpointBeanTest extends
     public void testPropertiesSettingOnCxfClient() throws Exception {
         CxfEndpoint clientEndpoint = ctx.getBean("clientEndpoint", 
CxfEndpoint.class);
         CxfProducer producer = (CxfProducer) clientEndpoint.createProducer();
+        // need to start the producer to get the client
+        producer.start();
         Client client = producer.getClient();
         HTTPConduit conduit = (HTTPConduit)client.getConduit();
         assertEquals("Got the wrong user name", "test", 
conduit.getAuthorization().getUserName());


Reply via email to