Generating Web Services server using Axis2
August 9, 2011 2 Comments
Everybody knows that you can easily generate Web Services client classes just from WSDL file in Java.
You even have such tool (wsimport) in every JDK distribution (check JDK_HOME/bin). It handles
all XML data types to Java mapping and generates all complex types needed. You even 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 WS client and 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, won’t you?)
That was something I’ve been struggling today. I’ve got only WSDL and 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 client as well as for server.
But wait it was not all. It also gave me Ant build file with compile.src target and even start.server!
Only thing I’ve had to do is to implement body of one method in *Skeleton class (class will be named according to what’s in your WSDL file).
So next time you need to test your Web Services and you have only WSDL launch:
axis\bin\wsdl2java.bat -ss -ssi -sd -uri file:///<<path>>/<<name>>.wsdl
(change path and .bat to .sh if you need it)
This will do all hard job for you.
Then edit *Skeleton class somewhere under newly created src folder to return some valid response. Execute:
ant compile.src ant start.server
for your fresh working dummy web service.
This little thing just made Web Services even nicer.