Author: ningjiang
Date: Tue Aug 12 02:02:04 2008
New Revision: 685098

URL: http://svn.apache.org/viewvc?rev=685098&view=rev
Log:
CAMEL-532 Added the checking of service class

Modified:
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
    
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
    
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
    
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java?rev=685098&r1=685097&r2=685098&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
 Tue Aug 12 02:02:04 2008
@@ -64,12 +64,14 @@
 
         if (endpoint.isSpringContextEndpoint()) {
             CxfEndpointBean endpointBean = endpoint.getCxfEndpointBean();
+            CxfEndpointUtils.checkServiceClass(endpointBean.getServiceClass());
             svrBean = 
CxfEndpointUtils.getServerFactoryBean(endpointBean.getServiceClass());
             isWebServiceProvider = 
CxfEndpointUtils.hasAnnotation(endpointBean.getServiceClass(),
                                                                   
WebServiceProvider.class);
             endpoint.configure(svrBean);
 
         } else { // setup the serverFactoryBean with the URI parameters
+            CxfEndpointUtils.checkServiceClassName(endpoint.getServiceClass());
             Class serviceClass = 
ClassLoaderUtils.loadClass(endpoint.getServiceClass(), this.getClass());
             svrBean = CxfEndpointUtils.getServerFactoryBean(serviceClass);
             isWebServiceProvider = 
CxfEndpointUtils.hasAnnotation(serviceClass, WebServiceProvider.class);

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=685098&r1=685097&r2=685098&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 Tue Aug 12 02:02:04 2008
@@ -77,10 +77,9 @@
         if (endpoint.isSpringContextEndpoint()) {
             CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
             serviceClass = cxfEndpointBean.getServiceClass();
+            CxfEndpointUtils.checkServiceClass(serviceClass);
         } else {
-            if (endpoint.getServiceClass() == null) {
-                throw new CamelException("serviceClass setting missing from 
CXF endpoint configuration");
-            }
+            CxfEndpointUtils.checkServiceClassName(endpoint.getServiceClass());
             try {
                 serviceClass = 
ClassLoaderUtils.loadClass(endpoint.getServiceClass(), this.getClass());
             } catch (ClassNotFoundException e) {
@@ -120,42 +119,32 @@
         }
         if (endpoint.isSpringContextEndpoint()) {
             CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
+            
CxfEndpointUtils.checkServiceClass(cxfEndpointBean.getServiceClass());
             if (cfb == null) {
                 cfb = 
CxfEndpointUtils.getClientFactoryBean(cxfEndpointBean.getServiceClass());
             }
             endpoint.configure(cfb);
 
         } else { // set up the clientFactoryBean by using URI information
-            if (null != endpoint.getServiceClass()) {
-                try {
-                    // We need to choose the right front end to create the
-                    // clientFactoryBean
-                    Class serviceClass = 
ClassLoaderUtils.loadClass(endpoint.getServiceClass(), this
-                        .getClass());
-                    if (cfb == null) {
-                        cfb = 
CxfEndpointUtils.getClientFactoryBean(serviceClass);
-                    }
-                    cfb.setAddress(endpoint.getAddress());
-                    if (null != endpoint.getServiceClass()) {
-                        
cfb.setServiceClass(ObjectHelper.loadClass(endpoint.getServiceClass()));
-                    }
-                    if (null != endpoint.getWsdlURL()) {
-                        cfb.setWsdlURL(endpoint.getWsdlURL());
-                    }
-                } catch (ClassNotFoundException e) {
-                    throw new CamelException(e);
-                }
-            } else { // we can't see any service class from the endpoint
+            CxfEndpointUtils.checkServiceClassName(endpoint.getServiceClass());
+            try {
+                // We need to choose the right front end to create the
+                // clientFactoryBean
+                Class serviceClass = 
ClassLoaderUtils.loadClass(endpoint.getServiceClass(), this.getClass());
                 if (cfb == null) {
-                    cfb = new ClientFactoryBean();
+                    cfb = CxfEndpointUtils.getClientFactoryBean(serviceClass);
+                }
+                cfb.setAddress(endpoint.getAddress());
+                if (null != endpoint.getServiceClass()) {
+                    
cfb.setServiceClass(ObjectHelper.loadClass(endpoint.getServiceClass()));
                 }
                 if (null != endpoint.getWsdlURL()) {
                     cfb.setWsdlURL(endpoint.getWsdlURL());
-                } else {
-                    // Throw an exception indicating insufficient endpoint info
-                    throw new CamelException("Not enough information to create 
a CXF endpoint. (Provide WSDL url or service class name.)");
                 }
+            } catch (ClassNotFoundException e) {
+                throw new CamelException(e);
             }
+
             if (endpoint.getServiceName() != null) {
                 cfb.setServiceName(CxfEndpointUtils.getServiceName(endpoint));
             }

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java?rev=685098&r1=685097&r2=685098&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
 Tue Aug 12 02:02:04 2008
@@ -30,6 +30,7 @@
 import org.apache.camel.component.cxf.CxfEndpoint;
 import org.apache.camel.component.cxf.DataFormat;
 import org.apache.camel.component.cxf.spring.CxfEndpointBean;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.Message;
@@ -236,6 +237,18 @@
         }
     }
 
+    public static void checkServiceClass(Class clazz) throws CamelException {
+        if (clazz == null) {
+            throw new CamelException("serviceClass is required for CXF 
endpoint configuration");
+        }
+    }
+
+    public static void checkServiceClassName(String className) throws 
CamelException {
+        if (ObjectHelper.isNullOrBlank(className)) {
+            throw new CamelException("serviceClass is required for CXF 
endpoint configuration");
+        }
+    }
+
     public static DataFormat getDataFormat(CxfEndpoint endpoint) throws 
CamelException {
         String dataFormatString = endpoint.getDataFormat();
         if (dataFormatString == null) {

Modified: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java?rev=685098&r1=685097&r2=685098&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
 Tue Aug 12 02:02:04 2008
@@ -20,6 +20,9 @@
 
 import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelException;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 import org.apache.camel.component.cxf.CxfComponent;
 import org.apache.camel.component.cxf.CxfEndpoint;
 import org.apache.camel.component.cxf.DataFormat;
@@ -37,12 +40,18 @@
         + "&serviceName={http://www.example.com/test}ServiceName";
         + "&setDefaultBus=true";
 
-
+    private static final String NO_SERVICE_CLASS_URI = 
"cxf://http://www.example.com/testaddress";
+        + "?portName={http://www.example.com/test}PortName";
+        + "&serviceName={http://www.example.com/test}ServiceName";;
 
     protected String getEndpointURI() {
         return CXF_BASE_URI;
     }
 
+    protected String getNoServiceClassURI() {
+        return NO_SERVICE_CLASS_URI;
+    }
+
     protected CamelContext getCamelContext() throws Exception {
         return new DefaultCamelContext();
     }
@@ -64,6 +73,43 @@
         assertEquals("We should get the Message DataFormat", 
CxfEndpointUtils.getDataFormat(endpoint), DataFormat.MESSAGE);
     }
 
+    public void testCheckServiceClassWithTheEndpoint() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getNoServiceClassURI());
+        try {
+            CxfEndpointUtils.checkServiceClassName(endpoint.getServiceClass());
+            fail("Should get a CamelException here");
+        } catch (CamelException exception) {
+            assertNotNull("Should get a CamelException here", exception);
+            assertEquals("serviceClass is required for CXF endpoint 
configuration", exception.getMessage());
+        }
+    }
+
+    public void testCheckServiceClassProcedure() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getNoServiceClassURI());
+        try {
+            endpoint.createProducer();
+        } catch (CamelException exception) {
+            assertNotNull("Should get a CamelException here", exception);
+            assertEquals("serviceClass is required for CXF endpoint 
configuration", exception.getMessage());
+        }
+    }
 
+    public void testCheckServiceClassConsumer() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getNoServiceClassURI());
+        try {
+            endpoint.createConsumer(new NullProcessor());
+        } catch (CamelException exception) {
+            assertNotNull("Should get a CamelException here", exception);
+            assertEquals("serviceClass is required for CXF endpoint 
configuration", exception.getMessage());
+        }
+    }
+
+    class NullProcessor implements Processor {
+
+        public void process(Exchange exchange) throws Exception {
+            // Do nothing here
+        }
+
+    }
 
 }

Modified: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java?rev=685098&r1=685097&r2=685098&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
 Tue Aug 12 02:02:04 2008
@@ -57,6 +57,10 @@
         return "cxf:bean:testEndpoint";
     }
 
+    protected String getNoServiceClassURI() {
+        return "cxf:bean:noServiceClassEndpoint";
+    }
+
     public void testGetDataFormat() throws Exception {
         CxfEndpoint endpoint = createEndpoint(getEndpointURI() + 
"?dataFormat=MESSAGE");
         assertEquals("We should get the Message DataFormat", 
CxfEndpointUtils.getDataFormat(endpoint),
@@ -85,4 +89,6 @@
                      DataFormat.PAYLOAD);
     }
 
+
+
 }

Modified: 
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml?rev=685098&r1=685097&r2=685098&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
 Tue Aug 12 02:02:04 2008
@@ -36,7 +36,11 @@
 
   </cxf:cxfEndpoint>
 
-
+   <cxf:cxfEndpoint id="noServiceClassEndpoint" 
address="http://localhost:9000/router";
+    endpointName="s:PortName"
+    serviceName="s:ServiceName"
+    xmlns:s="http://www.example.com/test";>
+   </cxf:cxfEndpoint>
 
 
 


Reply via email to