Java Reference
In-Depth Information
Listing 11.3: Pig Latin Server's SOAP Response
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:translateResponse xmlns:ns1=
"http://www.httprecipes.com/1/11/soap/">
<return xsi:type="xsd:string">ellohay orldway</return>
</ns1:translateResponse></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can see, the translated text is returned.
It can be complex to build and parse SOAP requests and responses. Because of this, pro-
grammers often use a framework to help. In the next section, you will learn about the Apache
AXIS framework.
Using AXIS
If you need to access a SOAP based web service from Java, one of the easiest ways is to
use the AXIS framework. The Apache Foundation offers the AXIS framework. This frame-
work allows you to quickly construct Java objects that allow you to access a web service. You
can download the AXIS framework from the following URL:
http://ws.apache.org/axis/
Downloading and installing AXIS will provide you with a directory named
c:\axis-1_4\ or similar, depending on the current version. The first step is to run the
wsdl2java utility. This utility accepts the URL of a WSDL file, and generates Java classes
needed to access the web service.
The wsdl2java utility is written in Java; and it must be run, along with its required
JAR files. The following Java command would run the wsdl2java utility and process the
Pig Latin server.
java -cp lib\axis.jar;lib\commons-discovery-0.2.jar;lib\commons-
logging-1.0.4.jar;
lib\jaxrpc.jar;lib\log4j-1.2.8;lib\saaj.jar;lib\wsdl4j-1.5.1.jar
org.apache.axis.wsdl.WSDL2Java http://www.httprecipes.com/1/11/
soap/?wsdl
Search WWH ::




Custom Search