camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r899104 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/CxfEndpoint.java test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
Date Thu, 14 Jan 2010 08:19:10 GMT
Author: ningjiang
Date: Thu Jan 14 08:19:10 2010
New Revision: 899104

URL: http://svn.apache.org/viewvc?rev=899104&view=rev
Log:
CAMEL-2356 Added unit test to verify the CamelCxfClientImpl bus setting

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=899104&r1=899103&r2=899104&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
Thu Jan 14 08:19:10 2010
@@ -152,25 +152,20 @@
      */
     protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls) throws CamelException
{
         if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
-            ClientFactoryBean cfb = new JaxWsClientFactoryBean() {
+            return new JaxWsProxyFactoryBean(new JaxWsClientFactoryBean() {
                 @Override
                 protected Client createClient(Endpoint ep) {
                     return new CamelCxfClientImpl(getBus(), ep);
                 }
-            };
-            // set the client bus with cxfEndpoint Bus
-            cfb.setBus(getBus());
-            return new JaxWsProxyFactoryBean(cfb);
+            });
+            
         } else {
-            ClientFactoryBean cfb = new ClientFactoryBean() {
+            return new ClientProxyFactoryBean(new ClientFactoryBean() {
                 @Override
                 protected Client createClient(Endpoint ep) {
                     return new CamelCxfClientImpl(getBus(), ep);
                 }
-            };
-            // set the client bus with cxfEndpoint Bus
-            cfb.setBus(getBus());
-            return new ClientProxyFactoryBean(cfb);
+            });
         }
     }
     
@@ -179,7 +174,7 @@
      * Create a client factory bean object without serviceClass interface.
      */
     protected ClientFactoryBean createClientFactoryBean() {
-        ClientFactoryBean cfb = new ClientFactoryBean(new WSDLServiceFactoryBean()) {
+        return new ClientFactoryBean(new WSDLServiceFactoryBean()) {
                         
             @Override
             protected Client createClient(Endpoint ep) {
@@ -192,9 +187,6 @@
             }
             
         };
-        // set the client bus with cxfEndpoint Bus
-        cfb.setBus(getBus());
-        return cfb;
     }
 
     protected Bus doGetBus() {
@@ -464,12 +456,16 @@
      * to insert parameters into CXF Message for {@link DataFormat#PAYLOAD}
      * mode.
      */
-    private class CamelCxfClientImpl extends ClientImpl {
-
+    class CamelCxfClientImpl extends ClientImpl {
+       
         public CamelCxfClientImpl(Bus bus, Endpoint ep) {
             super(bus, ep);
         }
         
+        public Bus getBus() {
+            return bus;
+        }
+        
         @SuppressWarnings("unchecked")
         @Override
         protected void setParameters(Object[] params, Message message) {

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java?rev=899104&r1=899103&r2=899104&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfEndpointTest.java
Thu Jan 14 08:19:10 2010
@@ -17,7 +17,12 @@
 
 package org.apache.camel.component.cxf;
 
+import org.apache.camel.component.cxf.CxfEndpoint.CamelCxfClientImpl;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.spring.SpringCamelContext;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.CXFBusImpl;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,6 +34,15 @@
  * @version $Revision$
  */
 public class CxfEndpointTest extends Assert {
+    
+    private String routerEndpointURI = "cxf://http://localhost:9000/router"
+        + "?serviceClass=org.apache.camel.component.cxf.HelloService"
+        + "&dataFormat=POJO";
+    private String wsdlEndpointURI = "cxf://http://localhost:9002/helloworld"
+        + "?wsdlURL=classpath:person.wsdl"
+        + "&serviceName={http://camel.apache.org/wsdl-first}PersonService"
+        + "&portName={http://camel.apache.org/wsdl-first}soap"
+        + "&dataFormat=PAYLOAD";
 
     @Test
     public void testSpringCxfEndpoint() throws Exception {
@@ -44,5 +58,25 @@
             svf.getServiceClass().getCanonicalName(),
             "org.apache.camel.component.cxf.HelloService");
     }
+    
+    @Test
+    public void testSettingClientBus() throws Exception {
+        CXFBusImpl bus = (CXFBusImpl) BusFactory.newInstance().createBus();
+        bus.setId("oldCXF");
+        BusFactory.setThreadDefaultBus(bus);
+        
+        CXFBusImpl newBus = (CXFBusImpl) BusFactory.newInstance().createBus();
+        newBus.setId("newCXF");
+        CxfComponent cxfComponent = new CxfComponent(new DefaultCamelContext());
+        CxfEndpoint endpoint = (CxfEndpoint)cxfComponent.createEndpoint(routerEndpointURI);
+        endpoint.setBus(newBus);
+        CamelCxfClientImpl client = (CamelCxfClientImpl)endpoint.createClient();
+        assertEquals("CamelCxfClientImpl should has the same bus with CxfEndpoint", newBus,
client.getBus());
+        
+        endpoint = (CxfEndpoint)cxfComponent.createEndpoint(wsdlEndpointURI);
+        endpoint.setBus(newBus);
+        client = (CamelCxfClientImpl)endpoint.createClient();
+        assertEquals("CamelCxfClientImpl should has the same bus with CxfEndpoint", newBus,
client.getBus());
+    }
 
 }



Mime
View raw message