Web-Services with Axis 2, CXF and Maven – Part 1

Digging into Web-Services is really complex, there are so many stumbling blocks. First of all one has to understand all the WS-* specifications, or at least the important ones about service. Also important are the guidelines regarding interoperability between Java and .Net. Then the next is the framework one wants to use. Typically everyone talks about Axis2, but sometimes there is also CXF and the new Spring-WS. After that decision the question is about the integration into the development cycle. How can one integrate the generative tasks into the build cycle, e.g. with Maven. This post tries to present one possible solution for these problems in a step to step guide. So lets start.

First of all the project itself is separated into two modules. The first module is for the service implementation and contains the code for the implementation and the service definition in WSDL and XSD files. So lets assume you’ve already wriiten the XSD and WSDL files in your favorite editor. Personally I’m switching between Eclipse and Netbeans. At this point comes the first important hint when using Maven. Put your WSDL and XSD into src/main/resources/META-INF so they are deployed together with the service implementation into the Axis2 runtime.

Then the project descriptor for the service implementation module needs to be updated. Add a property for the Axis2 version, so it can be used at all dependencies and plugin configurations. This makes switching from one version to the other quite charming because it’s just a matter of changing one number. The project dependencies must include the axis2 artifact from org.apache.axis2 and the choosen databinding, e.g. axis2-jaxbri, also from org.apache.axis2. Also add the Maven plugin axis2-wsdl2code-maven-plugin to the build section. This generates the files with source code for the service implementation on the Axis2 runtime. Make sure the plugin executes the goal wsdl2code and the configuration points to the correct WSDL location. Also you should switch on the generation of the server side and services.xml. For a better design it is also a good choice to enable the generation of a server side interface. A hint here is also to include the dependency to the databinding when you’ve not chosen adb.

Now comes the hard part on the console where you simply use mvn compile to generate the files. From these generated files copy the services.xml file from target/generated-sources/axis2/wsdl2code into src/main/resources/META-INF folder. This is the runtime configuration of your service and needed by Axis2.

After this is finished you can package and deploy your service to an Axis2 runtime. But the service will report unchecked exceptions because nothing is implemented. So write a class which either extends the generated skeleton or implements the skeleton interface. This will separate your written code from the generated code. If the implementation extends the skeleton any new service method will report unchecked exceptions after redeployment. Removing a method will give a compile error because of the existing override annotation. Adding a service method when an interface is implemented will create a compile error before the new deployment. As last step change the service-class in the services.xml file to point to your service implementation.

Schlagwörter: , , ,

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

%d Bloggern gefällt das: