If serviceClass always required for CXF component, throw specific exception 
instead of NPE
------------------------------------------------------------------------------------------

                 Key: CAMEL-532
                 URL: https://issues.apache.org/activemq/browse/CAMEL-532
             Project: Apache Camel
          Issue Type: Improvement
            Reporter: Glen Mazza
            Priority: Minor


The Camel-CXF documentation[1] says the "serviceClass" option is not required 
when you are using CXF as a consumer (SOAP client).  (Slightly differently, 
FUSE's documentation[2] is saying that the "serviceClass" is not required if 
you provide the wsdlURL, the portName, and the serviceName.) I believe the 
following CXF_URI should work then even if I exclude the serviceClass:

   private static final String JAXWS_SERVER_ADDRESS = 
"http://localhost:8080/doubleit/services/doubleit";;
   private static final String CXF_URI = "cxf://" + JAXWS_SERVER_ADDRESS
     + "?wsdlURL=http://localhost:8080/doubleit/services/doubleit?wsdl";
     + "&serviceClass=com.mycompany.webservice.service.DoubleItPortTypeImpl"
     + "&portName={http://www.example.org/DoubleIt}DoubleItPort";
     + "&serviceName={http://www.example.org/DoubleIt}DoubleItService";;

...

      context.addRoutes(new RouteBuilder() {
         public void configure() {

            from("test-jms:queue:test.queue").process(new Processor() {
               public void process(Exchange e) {
                   System.out.println("This was called - Body: " + 
e.getIn().getBody(String.class));
                   e.getIn().setHeader(CxfConstants.OPERATION_NAME,"DoubleIt");
                   final List<String> params = new ArrayList<String>();
                   params.add(e.getIn().getBody(String.class));
                   e.getOut().setBody(params);
                 }
           }).to(CXF_URI).to("file://testfile").process(new Processor() {
              public void process(Exchange e) {
                 System.out.println("In process"); //  + 
e.getIn().getBody(String.class));
                 List<String> abc = e.getIn().getBody(ArrayList.class);
                 System.out.println("This was called - in File list: " + 
abc.get(0));
                }
               });
           }
      });     
...

But the problem is that the serviceClass seems to be always required, even if I 
supply the wsdlURL, portName, and serviceName as I did here.  When I remove the 
serviceClass from the code above, I get a NPE in the CXF code in both of these 
scenarios:

1.)  If I keep the wsdlURL, portName, and serviceName in the string above:

java.lang.NullPointerException
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeWSDLOperations(ReflectionServiceFactoryBean.java:447)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:274)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:360)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:156)
        at 
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:74)
        at 
org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)
        at 
org.apache.camel.component.cxf.CxfProducer.createClientFormClientFactoryBean(CxfProducer.java:165)
        at 
org.apache.camel.component.cxf.CxfProducer.<init>(CxfProducer.java:66)

2.)  If I just keep the wsdlURL, and remove portName and serviceName also:

java.lang.NullPointerException
        at 
org.apache.cxf.service.factory.DefaultServiceConfiguration.getServiceNamespace(DefaultServiceConfiguration.java:168)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.getServiceNamespace(ReflectionServiceFactoryBean.java:1383)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.getServiceQName(ReflectionServiceFactoryBean.java:1338)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:268)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:360)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:156)
        at 
org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:74)
        at 
org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)
        at 
org.apache.camel.component.cxf.CxfProducer.createClientFormClientFactoryBean(CxfProducer.java:165)
        at 
org.apache.camel.component.cxf.CxfProducer.<init>(CxfProducer.java:66)
...


If I'm correct, that serviceClass is required no matter what, I think we need 
to update our Camel documentation to clarify that.  Also, to modify CxfProducer 
to throw a clear exception ("serviceClass is required") if the serviceClass is 
missing, instead of the user just getting the NPE somewhere deep in the CXF 
code.

Glen

[1] http://activemq.apache.org/camel/cxf.html
[2] http://open.iona.com/docs/router/1.3/deploy_guide/FMRC.CXFComp.html


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to