Simplify SOAP Service Development
What happens when the average Java developer either chooses to or is compelled to look into Web Services? Well, usually it starts by downloading the JWSDP, reading the J2EE Tutorial or using an IDE to generate the sets of classes that you need. None of these options are easy though, and most of them results in a bunch of classes that you might not necessarilly understand.
There is a simpler way to develop web services though. Apache Axis allows a developer to take a POJO and turn it into a web service though configuration through 2 means.
The first one is to rename the .java file to .jws and to drop it within an Axis servlet context. This allows you to take classes that have fairly simple signatures and that use basic types (String, int, List, Map...) and to turn them instantly into a SOAP service. This is done through a process similar to what JSP pages go through. Axis finds the class, generates the required support classes, compiles everything and then exposes the service to the world.
A good example would be the following Hello World service:
// HelloWorld.jws
public class HelloWorld {
public String sayHello() {
return "Hello World!";
}
public String saySomething(String msg) {
return msg;
}
}
There's nothing else to do. No classes to extend, no interfaces to implement, no complicated and confusing specifications to try to understand. Once you have copied the HelloWorld.jws file in the proper location, all you have to do is access it through the URL. Axis will do its magic, and you should be able to see it. If you want to test it some more, add "?method=sayHello" at the end of the URL, and you should be getting a reply.
A very nice feature is the automatic generation of the WSDL document. You can get the WSDL for the service by appending ?wsdl after the service URL. This allows your clients to generate their stubs (or use a dynamic proxy) so they can access your service.
Now, if you do need to deploy more complicated services, you can still use Axis. A good example would be to support a complex type or you want to be able to reuse the same class as a RMI service. In this case, you will need to research the Axis WSDD file format. This file format describes what your service looks like and what data types are supported. I have used this approach to integrate different tools within Sun. I don't really have the space to elaborate too much on this, but I'll provide links to articles that will help you get a good idea on how to do this.
Other great features of Axis includes generating the WSDD and WSDL files from Java classes, generating stubs from WSDL, some monitoring utilities that allow you to see what is being received from and sent too the clients. It has been a pleasure to work with so far. It has allowed me to quickly prototype a web service and to deploy it a lot faster and easier than trying other approaches.
Resources:- Axis Project home page. A lot of good stuff. This is the place to get more information on the framework and to get your greedy little hands on it. A note of interest is the existance of an Axis C++ project also
- Further Readings has a lot of links to articles and presentations on Axis.
- A Gentle Introduction to SOAP provides a good start on how to use Axis.
-- Fred
( Jul 12 2004, 02:03:17 PM MDT ) PermalinkComments are closed for this entry.


