Generating Web Services server using Axis2

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

and check http://localhost:8080/axis2/services/ for your fresh working dummy web service.

This little thing just made Web Services even nicer.

2 Responses to Generating Web Services server using Axis2

  1. Hello there,

    Nice blog! Is there an email address I can contact you in private?

  2. Pingback: JavaPins

Leave a comment