Apache CXF for services
We’re building a simple web application that uses, among others, the following technologies:
- GWT for the front end and AJAX
- The Spring framework as a lightweight container and for some other services such as transaction management.
- Jetty as the web server and Servlet container.
- Hibernate for ORM
- Maven for building and dependency management.
One of the requirements was to provide some web services so an external module could interact with the system. None of the technologies already in place provided support for that, so I started looking for the right web services implementation.
I wanted to use the native Spring support for declarative remoting. It supports both JAX-WS and JAX-RPC and it allows you to choose the Web Services engine under the hood. Also, I wanted to have the option to export RESTful services.
Initially, I found too many ways to address my needs, but I didn’t have the time to test them all, so I quickly narrowed my choices to:
- Changing Jetty for JBoss , and use RESTEasy.
- Use Spring MVC for RESTful
- Add one or more of the following frameworks to the application stack
- Apache Axis 2
- Restlet
- Apache CXF
I discarded using JBoss because I wanted to keep the application lightweight. Switching to JBoss would have brought too much overhead for both the development and the production environments and we wouldn’t be using much of the services it provides.
The Spring support for RESTful services is too tightly tied to Spring MVC, which we’re not using. Instead we’re using GWT. So I ruled out that option.
Apache Axis 2 seemed a good choice but, again, I was looking for a smaller, lightweight framework. I wasn’t going to use most of the features it provides. Moreover, integration with Spring is not one the project’s highlight features.
I must admit I don’t have much to say about Restlet, because I tried Apache CXF first and it fit perfectly.
Apache CXF is a lightweight services framework that supports JAX-RPC, JAX-WS and JAX-RS. It was built with Spring in mind from the beginning so it integrates smoothly in our stack. It is also published in a maven repository so I didn’t have to manually add new libraries and check for dependencies conflicts.
Once I added CXF to the project’s pom.xml file and configured the CXF servlet in Jetty, I just had to declare a new endpoint in Spring configuration using the jaxws:endpoint tag and mark the service implementation with the @WebService annotation.
The only roadblock I’ve run into while configuring CXF 2.2.9 was a dependency conflict with Spring 3.0.1. The latter requires version 3.1 of the ASM library for bytecode manipulation, while one of the CXF pom.xml files specifies ASM version 2.2.9. I’ve changed CFX requirements to allow ASM 3.1 and so far I’ve found no problems.
I’ve still yet to test some of the interesting features of the tool, such as WS-Security and RESTful services but if you’re in need for a lightweight services framework that integrates well with Spring and you don’t want to use a full blown JEE application server, then I recommend that you try out Apache CXF.





Your opinion matters
Post Your Comment here: