Everyone knows that you can easily generate Web Service client classes just from a WSDL file in Java. You even have a tool (wsimport) in every JDK distribution (check JDK_HOME/bin) for this. It handles all XML data types to Java mapping and generates all complex types needed. You have such tools for many other programming languages. Scripting languages don’t need them at all, they generate them on the fly.
But what to do if you have to implement a WS client and the only thing you can get from your customer is a WSDL file? Of course, you can generate client classes from it. But how to test it? (You wouldn’t give untested code to your customer, would you?)
That was something I’ve been struggling with today. I’ve got only WSDL and a few example SOAP messages. What I’ve found out is that you can not only generate WS clients with Axis2 but also server skeletons. This really made me like it. It took me 5 minutes to generate all classes for the client as well as for the server. But wait, that was not all. It also gave me an Ant build file with a compile.src target and even start.server! The only thing I’ve had to do was to implement the body of one method in the *Skeleton
class (the class will be named according to what’s in your WSDL file).
So the next time you need to test your Web Service and you have only WSDL, launch (change path and .bat to .sh if you need it):
axis\bin\wsdl2java.bat -ss -ssi -sd -uri file:///<<path>>/<<name>>.wsdl
This will do all the hard job for you. Then edit the *Skeleton
class somewhere under the newly created src folder to return a valid response. Execute:
ant compile.src
ant start.server
and check http://localhost:8080/axis2/services/ for your fresh working dummy Web Service.
This little thing just made Web Services even nicer.