camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r828264 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ test/java/org/apache/camel/component/cxf/
Date Thu, 22 Oct 2009 00:23:38 GMT
Author: wtam
Date: Thu Oct 22 00:23:38 2009
New Revision: 828264

URL: http://svn.apache.org/viewvc?rev=828264&view=rev
Log:
Clean up serviceClass-less support [CAMEL-1810], make sure serviceName and portName/endpointName
are provided

Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyPayloadModeNoSpringTest.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=828264&r1=828263&r2=828264&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 Oct 22 00:23:38 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.component.cxf;
 
 import java.lang.reflect.Proxy;
-import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -41,7 +40,6 @@
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.ClassHelper;
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.ClientImpl;
 import org.apache.cxf.endpoint.Endpoint;
@@ -150,67 +148,7 @@
      * Create a client factory bean object.  Notice that the serviceClass <b>must</b>
be
      * an interface.
      */
-    protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls) throws CamelException
{        
-        if (cls == null && !getDataFormat().equals(DataFormat.POJO)) {
-            return new ClientProxyFactoryBean(new ClientFactoryBean(new WSDLServiceFactoryBean())
{
-                @Override
-                protected void createClient(Endpoint ep) {
-                    setClient(new CamelCxfClientImpl(getBus(), ep));
-                }    
-                
-                protected void initializeAnnotationInterceptors(Endpoint ep, Class<?>
cls) {
-                    // Do nothing here
-                }
-                
-            })
-            {   // Override the ClientProxyFactoryBean's create method
-                // Don't create the proxy object
-                public Object create() {
-                
-                    if (getProperties() == null) {
-                        setProperties(new HashMap<String, Object>());
-                    }
-                    
-                    if (getUsername() != null) {
-                        AuthorizationPolicy authPolicy = new AuthorizationPolicy();
-                        authPolicy.setUserName(getUsername());
-                        authPolicy.setPassword(getPassword());
-                        getProperties().put(AuthorizationPolicy.class.getName(), authPolicy);
-                    }
-                    
-                    initFeatures();                
-                    getClientFactoryBean().setProperties(getProperties());
-                    
-                    if (bus != null) {
-                        getClientFactoryBean().setBus(bus);
-                    }
-
-                    if (getDataBinding() != null) {
-                        getClientFactoryBean().setDataBinding(getDataBinding());
-                    }
-                    
-                    Client c = getClientFactoryBean().create();
-                    if (getInInterceptors() != null) {
-                        c.getInInterceptors().addAll(getInInterceptors());
-                    }
-                    if (getOutInterceptors() != null) {
-                        c.getOutInterceptors().addAll(getOutInterceptors());
-                    }
-                    if (getInFaultInterceptors() != null) {
-                        c.getInFaultInterceptors().addAll(getInFaultInterceptors());
-                    }
-                    if (getOutFaultInterceptors() != null) {
-                        c.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
-                    }
-
-                    return c;
-                }
-            };        
-        }
-        
-        // quick null point check for serviceClass
-        //ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
-        
+    protected ClientProxyFactoryBean createClientFactoryBean(Class<?> cls) throws CamelException
{               
         if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
             return new JaxWsProxyFactoryBean(new JaxWsClientFactoryBean() {
                 @Override
@@ -227,6 +165,26 @@
             });
         }
     }
+    
+    /**
+     * 
+     * Create a client factory bean object without serviceClass interface.
+     */
+    protected ClientFactoryBean createClientFactoryBean() {
+        return new ClientFactoryBean(new WSDLServiceFactoryBean()) {
+                        
+            @Override
+            protected void createClient(Endpoint ep) {
+                setClient(new CamelCxfClientImpl(getBus(), ep));
+            }    
+            
+            @Override
+            protected void initializeAnnotationInterceptors(Endpoint ep, Class<?> cls)
{
+                // Do nothing here
+            }
+            
+        };
+    }
 
     protected Bus doGetBus() {
         return BusFactory.getDefaultBus();
@@ -236,10 +194,7 @@
      * 
      * Populate a client factory bean
      */
-    protected void setupClientFactoryBean(ClientProxyFactoryBean factoryBean, Class<?>
cls) {
-        // quick null point check for serviceClass
-        //ObjectHelper.notNull(cls, "Please provide endpoint service interface class");
-        
+    protected void setupClientFactoryBean(ClientProxyFactoryBean factoryBean, Class<?>
cls) {       
         // service class
         factoryBean.setServiceClass(cls);
         
@@ -271,6 +226,35 @@
         factoryBean.setBus(getBus());
         
     }
+
+    protected void setupClientFactoryBean(ClientFactoryBean factoryBean) {       
+        // address
+        factoryBean.setAddress(getEndpointUri());
+
+        // wsdl url
+        if (getWsdlURL() != null) {
+            factoryBean.setWsdlURL(getWsdlURL());
+        }
+        
+        // service name qname
+        if (getServiceName() != null) {
+            factoryBean.setServiceName(CxfEndpointUtils.getQName(getServiceName()));
+        }
+        
+        // port name qname
+        if (getPortName() != null) {
+            factoryBean.setEndpointName(CxfEndpointUtils.getQName(getPortName()));
+        }
+
+        // apply feature here
+        if (getDataFormat() == DataFormat.MESSAGE) {
+            factoryBean.getFeatures().add(new MessageDataFormatFeature());
+        } else if (getDataFormat() == DataFormat.PAYLOAD) {
+            factoryBean.getFeatures().add(new PayLoadDataFormatFeature());
+        }
+        
+        factoryBean.setBus(getBus());        
+    }
     
     // Package private methods
     // -------------------------------------------------------------------------
@@ -288,23 +272,22 @@
         Class<?> cls = null;
         if (getServiceClass() != null) {
             cls = ClassLoaderUtils.loadClass(getServiceClass(), getClass());
-        }
-
-        // create client factory bean
-        ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
-        
-        // setup client factory bean
-        setupClientFactoryBean(factoryBean, cls);
-        
-        if (cls == null) {
-            return (Client)factoryBean.create();
-        } else {
+            // create client factory bean
+            ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
+            // setup client factory bean
+            setupClientFactoryBean(factoryBean, cls);
             return ((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
+        } else {
+            ObjectHelper.notNull(portName, "Please provide endpoint/port name");
+            ObjectHelper.notNull(serviceName, "Please provide service name");
+            ClientFactoryBean factoryBean = createClientFactoryBean();
+            // setup client factory bean
+            setupClientFactoryBean(factoryBean);
+            return factoryBean.create();
         }
         
     }
 
-
     /**
      * Create a CXF server factory bean
      */
@@ -323,6 +306,8 @@
         ServerFactoryBean answer = null;
         
         if (cls == null) {
+            ObjectHelper.notNull(portName, "Please provide endpoint/port name");
+            ObjectHelper.notNull(serviceName, "Please provide service name");
             answer = new ServerFactoryBean(new WSDLServiceFactoryBean());
         } else if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
             answer = new JaxWsServerFactoryBean();
@@ -488,8 +473,5 @@
                 super.setParameters(params, message);
             }
         }
-
-
     }
-
 }

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java?rev=828264&r1=828263&r2=828264&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
Thu Oct 22 00:23:38 2009
@@ -29,6 +29,7 @@
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.configuration.spring.ConfigurerImpl;
 import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientFactoryBean;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.frontend.ServerFactoryBean;
@@ -111,35 +112,60 @@
             ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
         }
 
-        // create client factory bean
-        ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
-        
-        // configure client factory bean by CXF configurer
-        configure(factoryBean);
+        if (cls != null) {
+            // create client factory bean
+            ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);
+
+            // configure client factory bean by CXF configurer
+            configure(factoryBean);
+
+            // setup client factory bean
+            setupClientFactoryBean(factoryBean, cls);
+
+            // fill in values that have not been filled.
+            QName serviceQName = null;
+            try {
+                serviceQName = factoryBean.getServiceName();
+            } catch (IllegalStateException e) {
+                // It throws IllegalStateException if serviceName has not been set.
+            }
 
-        // setup client factory bean
-        setupClientFactoryBean(factoryBean, cls);
+            if (serviceQName == null && getServiceLocalName() != null) {
+                factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
+            }
+            if (factoryBean.getEndpointName() == null && getEndpointLocalName() !=
null) {
+                factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
+            }
 
-        // fill in values that have not been filled.
-        QName serviceQName = null;
-        try {
-            serviceQName = factoryBean.getServiceName();
-        } catch (IllegalStateException e) {
-            // It throws IllegalStateException if serviceName has not been set.
-        }
-        
-        if (serviceQName == null && getServiceLocalName() != null) {
-            factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
-        }
-        if (factoryBean.getEndpointName() == null && getEndpointLocalName() != null)
{
-            factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
-        }
-        
-        if (cls == null) {
+            return ((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
+        } else {
+            ClientFactoryBean factoryBean = createClientFactoryBean();
+
+            // configure client factory bean by CXF configurer
+            configure(factoryBean);
+            
+            // setup client factory bean
+            setupClientFactoryBean(factoryBean);
+            
+            // fill in values that have not been filled.
+            QName serviceQName = null;
+            try {
+                serviceQName = factoryBean.getServiceName();
+            } catch (IllegalStateException e) {
+                // It throws IllegalStateException if serviceName has not been set.
+            }
+            
+            if (serviceQName == null && getServiceLocalName() != null) {
+                factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
+            }
+            if (factoryBean.getEndpointName() == null && getEndpointLocalName() !=
null) {
+                factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
+            }
+            
+            ObjectHelper.notNull(factoryBean.getEndpointName(), "Please provide endpoint/port
name");
+            ObjectHelper.notNull(factoryBean.getServiceName(), "Please provide service name");
             return (Client)factoryBean.create();
         }
-        
-        return ((ClientProxy)Proxy.getInvocationHandler(factoryBean.create())).getClient();
     }
 
 
@@ -183,6 +209,10 @@
             answer.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
         }
 
+        if (cls == null) {
+            ObjectHelper.notNull(answer.getEndpointName(), "Please provide endpoint/port
name");
+            ObjectHelper.notNull(answer.getServiceName(), "Please provide service name");
+        }
         return answer;
     }
 

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java?rev=828264&r1=828263&r2=828264&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/WSDLServiceFactoryBean.java
Thu Oct 22 00:23:38 2009
@@ -16,72 +16,29 @@
  */
 package org.apache.camel.component.cxf;
 
-import javax.xml.namespace.QName;
-
-import org.apache.cxf.service.Service;
 import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.wsdl11.WSDLServiceFactory;
+import org.apache.cxf.service.invoker.Invoker;
 
+/**
+ * A service factory bean class that create a service factory without requiring a service
class
+ * (SEI).
+ *
+ * @version $Revision$
+ */
 public class WSDLServiceFactoryBean extends ReflectionServiceFactoryBean {
-    private QName serviceName;
-    private QName endpointName;
-
     @Override
-    public Service create() {
-
-        WSDLServiceFactory factory = new WSDLServiceFactory(getBus(), getWsdlURL(), getServiceQName());
-
-        setService(factory.create());
-        initializeDefaultInterceptors();
-        //disable the date interceptors
-        updateEndpointInfors();
-        createEndpoints();
-
-        return getService();
-    }
-
-
-    private void updateEndpointInfors() {
-        Service service = getService();
-
-        for (ServiceInfo inf : service.getServiceInfos()) {
-            for (EndpointInfo ei : inf.getEndpoints()) {
-                //setup the endpoint address
-                ei.setAddress("local://" + ei.getService().getName().toString() + "/" + ei.getName().getLocalPart());
-                // working as the dispatch mode, the binding factory will not add interceptor
-                //ei.getBinding().setProperty(AbstractBindingFactory.DATABINDING_DISABLED,
Boolean.TRUE);
-            }
-        }
-
+    protected void initializeWSDLOperations() {
+        // skip this operation that requires service class
     }
     
+    @Override
     protected void checkServiceClassAnnotations(Class<?> sc) {
-        // do nothing here
+        // skip this operation that requires service class
     }
-
-    public void setServiceName(QName name) {
-        serviceName = name;
-    }
-
-    public String getServiceName() {
-        return serviceName.toString();
-    }
-
-    public QName getServiceQName() {
-        return serviceName;
-    }
-
-    public QName getEndpointName() {
-        // get the endpoint name if it is not set
-        if (endpointName == null) {
-            endpointName = getService().getEndpoints().keySet().iterator().next();
-        }
-        return endpointName;
-    }
-
-    public void setEndpointName(QName name) {
-        endpointName = name;
+    
+    @Override
+    protected Invoker createInvoker() {
+        // Camel specific invoker will be set 
+        return null;
     }
 }

Modified: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyPayloadModeNoSpringTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyPayloadModeNoSpringTest.java?rev=828264&r1=828263&r2=828264&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyPayloadModeNoSpringTest.java
(original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CXFWsdlOnlyPayloadModeNoSpringTest.java
Thu Oct 22 00:23:38 2009
@@ -34,6 +34,10 @@
 
 public class CXFWsdlOnlyPayloadModeNoSpringTest extends CamelTestSupport {
     
+    protected static final String SERVICE_NAME = "{http://camel.apache.org/wsdl-first}PersonService";
+    protected static final String SERVICE_NAME_PROP =  "serviceName=" + SERVICE_NAME;
+    protected static final String PORT_NAME_PROP = "portName={http://camel.apache.org/wsdl-first}soap";
+    protected static final String WSDL_URL_PROP = "wsdlURL=classpath:person.wsdl";
     private Endpoint endpoint;
 
     @Before
@@ -53,8 +57,8 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("cxf://http://localhost:8092/PersonService?wsdlURL=classpath:person.wsdl&dataFormat="
+ getDataFormat())
-                    .to("cxf://http://localhost:8093/PersonService?wsdlURL=classpath:person.wsdl&dataFormat="
+ getDataFormat());
+                from("cxf://http://localhost:8092/PersonService?" + PORT_NAME_PROP + "&"
+ SERVICE_NAME_PROP + "&" + WSDL_URL_PROP + "&dataFormat=" + getDataFormat())
+                    .to("cxf://http://localhost:8093/PersonService?" + PORT_NAME_PROP + "&"
+ SERVICE_NAME_PROP + "&" + WSDL_URL_PROP + "&dataFormat=" + getDataFormat());
             }
         };
     }
@@ -66,8 +70,8 @@
     @Test
     public void testRoutes() throws Exception {
         URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
-        PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/wsdl-first",
-                                                                "PersonService"));
+        PersonService ss = new PersonService(wsdlURL, QName.valueOf(SERVICE_NAME));
+
         Person client = ss.getSoap();
         Holder<String> personId = new Holder<String>();
         personId.value = "hello";



Mime
View raw message