Hi,

Recently I've seen some confusions in our user group around the usage of 
JaxWsServerFactoryBean, and to be honest, it confuses me sometimes as well. To 
better document this part, I have gathered couple of  questions, now I m 
inviting you to give out your answers and comments. Of course I know we 
programmers all hate writing documents, so I also provided some of my answers, 
but with no guarantee to be correct. Please review my answers and feel free to 
correct. Once this done, I ll put them into CXF documentation. 

1. Q: When shall I use standard JAX-WS API (e.g., 
javax.xml.ws.Endpoint.publish()) to publish a service and when shall I use 
JaxWsServerFactoryBean?
   A: Recently I've seen we are giving out a lot of code snippet to users that 
using JaxWsServerFactoryBean. Are we encouraging users to use  this 
JaxWsServerFactoryBean API, or we should encourage them to stick to standard 
JAX-WS APIs as much as possible? The next question followed up naturally is 
when I have to use JaxWsServerFactoryBean? My understanding is you use 
JaxWsServerFactoryBean only when you have to  programmatically set some CXF 
specific properties on JaxWsServerFactoryBean, e.g., set the BeanInvoker


2. Q: Is JaxWsServerFactoryBean exactly equivalent to 
javax.xml.ws.Endpoint.publish()? 
   A: Unfortunately, this is not the case. For example, handler chain and 
context injection is not done in JaxWsServerFactoryBean. There is a relevant 
JIRA issues about this (http://issues.apache.org/jira/browse/CXF-558).  I think 
we should refactor EndpointImpl and JaxWsServerFactoryBean, so that essentially 
everything in EndpointImpl is delegates to the JaxWsServerFactoryBean, 
EndpointImpl is just a wrapper on top of JaxWsServerFactoryBean. This will also 
fix CXF-558. Thoughts?


3. Q: When shall I use JaxWsServerFactoryBean and when shall I use 
ServerFactoryBean.
   A: So basically if you are using JAX-WS frontend, you need to use 
JaxWsServerFactoryBean. Alternatively you can use simple frontend if your 
service implementation is a pojo, and you do not want to use any JAX-WS API or 
annotations, in this case you need to use ServerFactoryBean. More information 
about simple frontend can be found from  
http://cwiki.apache.org/confluence/display/CXF20DOC/Simple+Frontend


Example 1, using JaxWsServerFactoryBean to create a JAX-WS service:
        BookServiceImpl serviceObj = new BookServiceImpl();
        JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
        sf.setServiceClass(BookService.class);
        // Use the HTTP Binding which understands the Java Rest Annotations
        sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
        sf.setAddress("http://localhost:9080/xml/";);
        sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
        sf.create();


Example 2, using ServerFactoryBean.to create a server from POJO:
// Create our service implementation
HelloImplhelloWorldImpl helloImpl = new HelloImpl();

// Create our Server
ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.setServiceClass(Hello.class);
svrFactory.setAddress("http://localhost:8080/Hello";);
svrFactory.setServiceBean(helloImpl);
svrFactory.create();

4. Q. What APIs are available on JaxWsServerFactoryBean, and what's the meaning 
of them.
   A. We need to document this clearly. e.g., how to enable MTOM, how to set 
BeanInvoker etc.

5. Q: How to configure JaxWsServerFactoryBean and standard JAX-WS endpoint 
using spring configuration. 
   A: An example is as below
  <bean id="greeterServerFactory"
    class="org.apache.cxf.jaxws.JaxWsServerFactoryBean" init-method="create">
    <property name="serviceClass" 
value="org.apache.hello_world_soap_http.GreeterImpl" />
    <property name="serviceBean">
      <bean class="org.apache.hello_world_soap_http.GreeterImpl"/>
    </property>
    <property name="address" value="/services/Greeter"/>
    <property name="bus" ref="cxf"/>
    <property name="bindingId" value="http://apache.org/cxf/binding/http"/>
    <property name="properties">
      <map>
       <entry key="mtom-enabled" value="true"/>
      </map>
    </property>
  </bean>
  
   <jaxws:endpoint id="endpoint1" 
              implementor="org.apache.hello_world_soap_http.GreeterImpl"
              address="/services/Greeter1"
              wsdlLocation="/wsdl/hello_world.wsdl"
   />


6. Q: I am also confused between the use of JaxWsServerFactoryBean and 
JaxWsSericeFactoryBean. For example, is the code snippet below a valid code?
        JaxWsServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
        serviceFactory.setBus(bus);
        serviceFactory.setInvoker(new JAXWSMethodInvoker(impl));
        serviceFactory.setServiceClass(impl.getClass());
        serviceFactory.setWsdlURL(wsdlLoc);


        JaxWsServerFactoryBean serverFactory = new JaxWsServerFactoryBean();
        serverFactory.setServiceFactory(serviceFactory);
        serverFactory.setBus(bus);
        serverFactory.setEndpointName(new QName(portName));
        serverFactory.setAddress(address);
        serverFactory.setServiceClass(impl.getClass());
        serverFactory.create();

   A: ServiceFactorys construct the Service, ServerFactorys construct the 
Server. You dont need to create a JaxWsServiceFactoryBean by yourself, as 
JaxWsServerFactoryBean will create a default one. You do the code above only 
when you want to have your own customized JaxWsServiceFactoryBean.


Reply via email to