Thursday, 3 December 2009

Web Service Definition with CXF, Maven, Spring

For a long time I have never designed and implemented a web service. I think for 2 years I have been using Remoting in my projects. Two days ago my company needed a small web service. The web service method would take a collection of entity as a parameter, then operate on the entities and return the operated collection back. I implemented the web service using Eclipse platform's web service tool. I have created an interface and the implementation class. Then I right clicked on the implementation class and selected the Web Service link, then Create Web Service link.

Then a pop up window opened and when I clicked the Next button I received a warning message below.

I recognized that axis needs custom object's definition in the wsdd file. And it does not support List, Set, Vector.. vs types of java. If I would define whole the custom objects to a definition file I would suffer from that.

I searched for web service tools for a while. I found Apache's open source project CXF. I sometimes heard about cxf from my brother. I was new to CXF and I needed a sample Hello World project to see the steps of creating a new project. In general, people type blogs about new technologies, but they don't provide a sample project implementation. I am suffering about this problem. Some of bloggers paste their code blocks but sometimes they are not enough. Yesterday night I have found a blog about CXF from
. Thanks to Benjamin.

Then I created a dynamic web project, enabled maven, enabled spring to the project. I created the operation classes, client class and tested the project. The console made a smile at me. You can download source code of the project. To run the project all you have to do is deploy to Tomcat and run as a java application. Enjoy :)