The next series of articles describe my experiences and my personal believe about some best practives using Spring-WS to build a webservice and a corresponding client.
The Spring documentation itself promotes using a Contract-First approach. This means you first think about your Request - Response objects and the corresponding service objects used to interchange information.
For this hands-on tutorial I wrote a webservice which allows you to find movies based on their title.
Below the xml schema used for this demo 'webservicedemo.xsd'.
It's important to know that your request and response messsages HAVE to end with respectively uppercase 'Request' and 'Response' like in my case QueryByTitleRequest and QueryByTitleResponse.
To start we'll create a separate project which contains nothing more then the generated JAXB classes. The reason why I advise this approach is that you only have to generate the stubs once for both the webservice itself as well as the client and add this project as a dependency.
Create a new source folder src/main/resources and copy webservicedemo.xsd to this folder. Also create a bindings.xjb with the content below.
As you can see I created a SimpleTypeConverter which contains some methods to convert to and from java.util.Date to the XML String representation of a Date.
The pom.xml for this project is show below:
Now we can generate our jaxb stubs using the command below:
If we also run mvn eclipse:eclipse again the folder src/main/generated will be added as a source folder.
In part 2 I will start with explaining step-by-step how to create the webservice itself.