Magazine
 
Quick Review:Ajax
 
Deploy Web services in Apache Geronimo
 
  • Apache Axis 1.1 or later. (See Resources for the Apache Axis Web link.)
  • The Web Services Description Language (WSDL) for the Web service. (See Resources for a link to download the WSDL.)
  • An AWS subscription ID from Amazon so you can use their Web services. (See Resources
    for a link to register for the free ID.)

Set up your environment

The next series of steps guides you through setting up your environment by downloading the elements listed above as follows:

  • Install the JDK into C:\jdk_142_05. Set the JAVA_HOME to this directory.
  • Extract Apache Axis into C:\axis1-2, and define AXIS_HOME as this directory.
  • Copy the WSDL file into the AXIS_HOME directory.
  • Register for the AWS subscription ID.

Now that you have the basic environment ready to go, you can start generating the code to consume the Web service.

Generate the Java code from the WSDL

First, generate the Java code that will consume the Web service from the WSDL file. Apache Axis comes with a utility called WSDL2Java that performs this task for you. To run this tool, make sure the following Java Archive (JAR) files are in your classpath. The sample setenv.bat script shown in Listing 1 does this for you.

Listing 1. Setenv.bat
set AXIS_HOME=c:\axis-1-2
set CLASSPATH=.
set CLASSPATH=%AXIS_HOME%\lib\axis.jar;%CLASSPATH%
set CLASSPATH=%AXIS_HOME%\lib\commons-discovery.jar;%CLASSPATH%
set CLASSPATH=%AXIS_HOME%\lib\commons-logging.jar;%CLASSPATH%
set CLASSPATH=%AXIS_HOME%\lib\jaxrpc.jar;%CLASSPATH%
set CLASSPATH=%AXIS_HOME%\lib\saaj.jar;%CLASSPATH%
set CLASSPATH=%AXIS_HOME%\lib\log4j-1.2.8.jar;%CLASSPATH%
set CLASSPATH=%AXIS_HOME%\lib\wsdl4j.jar;%CLASSPATH%

Now, from the AXIS_HOME directory, run the following command to generate the Java code:
java org.apache.axis.wsdl.WSDL2Java AWSECommerceService.wsdl

This process takes a few seconds to create a directory called com under AXIS_HOME. Now you can start creating a Web Archive (WAR) file that you will eventually deploy on Geronimo. Create a directory called C:\amazon-client. You'll use this directory to store the code for the WAR file. Under this directory, create a directory called WEB-INF and a directory called src. Copy the com directory from your AXIS_HOME to C:\amazon-client\WEB-INF\src. This code is the basic code for consuming a Web service. For now, you don't need to go into the details of this code.

Write code to consume the Web service

Next, write a client to the Web service. In this example, you'll write a simple Java class that calls the appropriate classes that were generated using WSDL2Java. (Tools such as Eclipse and IBM® Rational® Application Developer generate a stubbed version of this code for you automatically. Thus, I won't spend much time on the specifics of how to write this code.)

 
May 2008 | Java Jazz Up | 23
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37 Download PDF