39.2. SUN Web Service

39.2.1. Axis Classes Generation

To call a web service, first generate Axis classes. The generated classes will allow a web service to be called using the static method.

For this step, download the file AirService.wsdl that corresponds to the SUN web service description or use the URL containing this file.

Then use the command:

java org.apache.axis.wsdl.WSDL2java <file_name>

This command generates four Java files:

AirService.java: the service interface.

AirServiceLocator.java: the service implementation

AirServiceServantInterface: the endpoint interface

AirServiceServantInterfaceBindingStub.java: the stub class

To call the SUN web service, instantiate the service implementation. Then call the method getAirService() to get the end point, and call the appropriate method.

 
AirService airService=new AirServiceLocator();
AirServiceServantInterface interface=airService getAirService();
Object result=interface.<method>;

39.2.2. JSP Files

The file Part2_site.zip contains the web application that uses the SUN web service.

It includes several JSP files that must be modified to use the Axis classes.

As an example, make the following replacements in the index.jsp file:

// Get our port interface
AirPack.AirClientGenClient.AirService service = 
       new AirPack.AirClientGenClient.AirService_Impl();
AirPack.AirClientGenClient.AirServiceServantInterface port = 
       service getAirServiceServantInterfacePort();

// Get the stub and set it to save the HTTP log.
AirPack.AirClientGenClient.AirServiceServantInterface_Stub stub = 
       (AirPack.AirClientGenClient.AirServiceServantInterface_Stub) port;
java.io.ByteArrayOutputStream httpLog = 
       new java.io.ByteArrayOutputStream();
stub._setTransportFactory
   (new com.sun.xml.rpc.client.http.HttpClientTransportFactory(httpLog));

// Get the end point address and save it for the error page.
String endPointAddress = (String) 
       stub._getProperty(stub.ENDPOINT_ADDRESS_PROPERTY);
request.setAttribute("ENDPOINT_ADDRESS_PROPERTY", endPointAddress);

by

// Get our port interface
AirService_pkg.AirService service = new AirService_pkg.AirServiceLocator();
AirService_pkg.AirServiceServantInterface port = 
         service getAirServiceServantInterfacePort();

Additionally, the exception:

throw new com.sun.xml.rpc.client.ClientTransportException(null, 
  new Object[] {e}); 

is replaced by:

throw new Exception(e);

39.2.3. Web Application

Finally, create the web application (jonas-web.xml) and reuse the web.xml that is in Part2_site.zip. Then, build the web application, which contains:

META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/jonas-web.xml
WEB-INF/lib/
WEB-INF/lib/CruiseManager.jar
WEB-INF/classes/
WEB-INF/classes/AirService_pkg/
WEB-INF/classes/AirService_pkg/AirServiceServantInterface.class
WEB-INF/classes/AirService_pkg/AirServiceServantInterfaceBindingStub.class
WEB-INF/classes/AirService_pkg/AirService.class
WEB-INF/classes/AirService_pkg/AirServiceLocator.class
PalmTree.jpg
aboutus.jsp
air_icon.gif
airbook.jsp
airclient.jsp
airdates.jsp
airdone.jsp
airlist.jsp
clear.gif
crubook.jsp
crudone.jsp
cruise_icon.gif
cruises.jsp
flights.jsp
index.jsp
nwcl_banner.gif
nwcl_banner_a.gif
nwcl_styles.css
WEB-INF/web.xml