天天看点

Java Web services and Apache Tomcat

Java Web services and Apache Tomcat

There are a number of solutions for deploying Web services when using the Tomcat application deployment platform. This section covers how to install the Axis toolkit.

Web services with Tomcat

There are a number of alternatives for running Web services with Tomcat. Tomcat itself is only a container and communication system for providing the connectivity between an application and an HTTP request.

To actually support Web services with Tomcat, you need an additional suite of libraries that provide the Web service interface—including handling all of the serialization of data to and from the Web service format (which is XML) into the "messages" that are exchanged between the server and the client.

Although there are many toolkits available for this, let's stick with Apache and use the Axis toolkit, which provides a Simple Object Access Protocol (SOAP) implementation for Web services.

Axis provides a full-blown Web service implementation, whereby you must compile and build your Java application using the Axis libraries to provide the Web services and a simplified solution for exposing an existing class directly using the Axis toolkit without having to redevelop any additional code. Unfortunately, the simplified method is not available, so you need to build an alternative interface around the original classes and methods.

Using Axis

To install Axis, download the Axis package from the Apache Axis Web site (see Resources).

  1. Unpack the Axis download package using Zip or Tar/Gzip, depending on which package you downloaded.
  2. Copy the webapps/axis directory to the webapps directory of the Tomcat installation.
  3. Shutdown Tomcat if it is already running.
  4. Startup Tomcat.

Once Tomcat has restarted, you need to visit the Axis installation home page, http://localhost:8080/axis/, to confirm that the service is up and running.

There is a checking service built into this page that can tell you if you need any more Java .jar files or other elements to complete your installation.

Validation showed that you were missing the activation.jar file and provided the link to obtain it. After putting the JAR in $CATALINA_HOME/ lib and stopping and restarting Tomcat, validation passed. Validation also recommended mail.jar and xmlsec.jar as optional, and links were provided to obtain the JARs.

Before deploying the Web service, you need to build and define the WSDL and then build the Java classes that return the actual information. Luckily, writing WSDL is easy with the right tools and, with the right tools, it can even generate a large proportion of the code for you.

from : http://www.ibm.com/developerworks/aix/tutorials/au-javaphpaix4/section3.html