XFire WebService With Spring

Tried setting up XFire with Spring and thought I’d share that experience. One more place to come for this information will not hurt ah!

Once again I used Maven to build my test application. At the bottom of this article you will find a download link for the entire application.

I have used Axis in the past and wanted to try out some other frameworks. At the same time I absolutely needed the framework to support JSR 181 (web service annotations), required the framework to integrate with Spring and relatively simple configuration. Oh also I did not want to write any WSDL. This example is an RPC based web service (unlike my previous article on document based web service with Spring-WS). I will after this article also start using Axis2, since I have been an Axis fan for many years.

JSR 181 is important to me. I think annotations are the right way to go for most simple tasks that do not require a lot of input. The web service annotations are good example about where annotations are the right fit. I have seen examples of annotations where it would be far easier and clearer to put it into the XML style configuration. Some folks are anti-annotations and I think that attitude is not the best. Use it where it makes the most sense.

Lets view the echo service java POJO code.

As you can see above I have made liberal use of JSR 181 web service annotations.

  • @WebService declares the class as exposing a web service method(s).
  • @WebMethod declares the particular method as being exposed as a web service operartion.
  • @WebParam gives easy-to-read parameter names which will show up in the auto-generated WSDL. Always provide these for the sake of your consumers sanity.
  • Also you can see that the java method is named ‘printback’ but exposed as name ‘echo’ by the @WebMethod annotation.

Here is the web.xml.

The web.xml configures the ‘XFireSpringServlet‘ and sets up the Spring listener. Straightforward.

Finally here is the xfire-servlet.xml (this is our spring configurationfile).

  • Sets up the xfire bean to recognize jsr 181 annotations.
  • Last bean is our echo service implementation bean (withannotations).

That is it. Build and deploy this and you should see the WSDL at http://localhost:9090/echoservice/services/EchoServiceImpl?wsdl.

Click here to download the Maven based project code. To build run:

  • mvn package
  • mvn jetty:run