Hi Jervis,

Apologies for the lag, due to random Gmail weirdness, this ended up not
being in my main CXF folder...

On 6/4/07, Liu, Jervis <[EMAIL PROTECTED]> wrote:

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


+1 - I think we should promote Endpoint as an entry point for JAX-WS unless
there's some stuff a user needs to control.

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?


+1 - I didn't realize we didn't do the handler setup...

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


+1

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();


Actually now we don't need to explictly supply a BenaInvoker, we can just do
sf.setServiceBean(serviceObj); If you do this the JWSFB will look at the
@WebService annotation and find the appropriate interface as well. So the
bare minimum case is just:

JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setAddress("http://localhost:9080/xml/";);
sf.setServiceBean(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.


+1

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>


There really shouldn't be any need for the <bean> syntax at this point. I
just added support for <simple:server> as well.

  <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.



Correct!

Seems you've got it under control :-)

- Dan

--
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Reply via email to