...
- Are you using the ObjectServiceFactory, AnnotationServiceFactory, or JAXWSServiceFactory? Go->
- Are you using services.xml? Go->
- Are you using the XFireServlet the Spring ServiceBean? Go->
- Are you using the Spring XFireExporterServiceBean? Go->
- Are you using the XFireServletSpring XFireExporter? Go->
Should I Migrate Yet?
...
Example ObjectServiceFactory Migration
Section |
---|
Column |
---|
| Here is an example of using the ObjectServiceFactory in XFire: Code Block |
---|
|
ObjectServiceFactory osf = new ObjectServiceFactory();
Service service = osf.create(MyServiceInterface.class);
service.setInvoker(new BeanInvoker(new MyServiceImpl());
|
|
Column |
---|
This would be the CXF equivalent: Code Block |
---|
|
ServerFactoryBean sf new ServerFactoryBean();
sf.getServiceFactory().setDataBinding(new AegisDatabinding();
sf.setServiceBean(new MyServiceImpl());
sf.setServiceClass(MyServiceInterface.class);
sf.setAddress("http://localhost:8080/myservice");
sf.create();
|
|
|
Example AnnotationServiceFactory Migration
Section |
---|
Column |
---|
| Here is an example of using the AnnotationServiceFactory in XFire: Code Block |
---|
|
AnnotationServiceFactory osf = new AnnotationServiceFactory();
Service service = osf.create(MyServiceInterface.class);
service.setInvoker(new BeanInvoker(new MyServiceImpl());
|
|
Column |
---|
This would be the CXF equivalent: Code Block |
---|
|
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean ();
sf.getServiceFactory().setDataBinding(new AegisDatabinding();
sf.setServiceClass(MyServiceImpl.class);
sf.setAddress("http://localhost:8080/myservice");
sf.create();
|
|
|
Example JAXWSServiceFactory Migration
Section |
---|
Column |
---|
| Here is an example of using the JAXWSServiceFactory in XFire: Code Block |
---|
|
JAXWSServiceFactory sf = new JAXWSServiceFactory();
Service service = sf.create(MyServiceImpl.class);
service.setInvoker(new BeanInvoker(new MyServiceImpl());
|
|
Column |
---|
This would be the CXF equivalent: Code Block |
---|
|
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(MyServiceImpl.class);
sf.setAddress("http://localhost:8080/myservice");
sf.create();
|
|
|
HTTP and Servlet Setup
CXF supports a much wider range of options for deploying your service over HTTP. XFire created a static mapping between the HTTP URL and the service name - i.e. a service named "HelloService" was accessible at http://localhost/services/HelloService
Image Added. CXF on the other hand allows you to control the URL which your service is published on. This address is provided to CXF either through the setAddress() call on the ServerFactoryBeans or via your XML configuration.
Another improvement over XFire is that CXF will now transparently detect whether the CXFServlet is being used. If it is, your service will be available on that location. If it is not, CXF will automatically start an embedded Jetty instance (provided the cxf-rt-transports-http-jetty module is on your classpath). No more calls to XFireHttpServer are needed!
To set up the CXF servlet, please read the how-to on the Servlet Transport page.
To use the embedded Jetty instance, no extra work is needed. Simply follow the above ServiceFactory examples.
services.xml
XFire included support for deploying your services via a services.xml file.
In CXF this file is named cxf.xml.
Section |
---|
Column |
---|
| XFire services.xml example: Code Block |
---|
|
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service xmlns:t="urn:my:namespace">
<name>testservice</name>
<serviceClass>org.example.TestService
</serviceClass>
<implementationClass>org.codehaus.xfire.spring.TestServiceImpl</implementationClass>
<namespace>urn:my:namespace</namespace>
<serviceFactory>org.codehaus.xfire.jaxws.JAXWSServiceFactory</serviceFactory>
<properties>
<property key="myKey">value</property>
</properties>
<inHandlers>
<handler handlerClass="org.codehaus.xfire.spring.TestHandler"/>
</inHandlers>
</service>
</beans>
|
|
Column |
---|
CXF example: Code Block |
---|
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:endpoint address="http://localhost/testService"
serviceName="t:testService"
xmlns:t="urn:my:namespace">
<jaxws:implementor>
<bean class="org.example.TestServiceImpl"/>
</jaxws:implementor>
<jaxws:properties>
<entry key="foo" value="bar"/>
</jaxws:properties>
<jaxws:inInterceptors>
<bean class="org.example.ExampleInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
</beans>
|
|
|
There are a few important things to note here on the differences:
- Many of these attributes are optional, such as the service name
- You don't need to specify a serviceClass if you are using JAX-WS as your service should be annotated with the @WebService.endpoitnInterface attribute.
- The equivalent of XFire Handlers is Interceptors inside CXF. They feature a much improved API!
The above sample is for JAX-WS/JSR181 services. For those developing services without annotations, here's an example for the Simple Frontend"
Code Block |
---|
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simple="http://cxf.apache.org/simple"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/simple
http://cxf.apache.org/schemas/simple.xsd">
<simple:server address="http://localhost/testService"
serviceClass="org.example.TestService">
<simple:serviceBean>
<bean class="org.example.TestServiceImpl"/>
</simple:serviceBean>
<simple:properties>
<entry key="foo" value="bar"/>
</jaxws:properties>
<simple:inInterceptors>
<bean class="org.example.ExampleInterceptor"/>
</simple:inInterceptors>
</simple:endpoint>
</beans>
|