Google
 

Thursday, August 23, 2007

August 16, 2007








A Quick Implementation Guide for Web Services using Axis






























Table of Contents



1.Introduction 3

2.What are Web Services? 3

3.The Web Services Architecture 4

4.The Basic Web Services Stack 4

5.Introduction to Axis 6

6.Software Requirements 6

7.A Quick implementation of Web Services using Axis 6

8.Conclusion 14

9.References 14


  1. Introduction


This document provides basic overview on Web Services and explains how quick web services can be implemented using Apache Axis.

  1. What are Web Services?

Web services are distributed applications that expose an XML Interface defined in XML

  • Loosely Coupled

  • Platform and implementation neutral

  • Coarse Grained

  • Ability to be synchronous and asynchronous

  • Supports Remote Procedure Calls (RPCs)

  • Support for Document Exchange


    • XML Based

      • By using XML as data representation layer for all web services protocols and technologies that are created, these technologies are interoperable at a core level



    • Loosely Coupled

      • The concept of an interface to be thoroughly applied.

      • The web services offered or the implementation may change but the interfaces must strive to remain the same.


    • Coarse Grained

      • Businesses must strive that the interfaces they expose are coarse grained.

      • Web services offer a natural way to define coarse grained services that access the right amount of business logic.


    • Ability to be synchronous and asynchronous

      • To say the least both semantics are absolutely vital.


    • Supports Remote Procedure Calls(RPCs)

      • Web services allow clients to invoke procedures, functions, and methods on remote objects using XML-based RPC.

      • Remote procedures expose input and output parameters that web services must support.

      • It is also vital to translate XML based calls to native platform calls.(EJBs , RMI, .NET)


    • Support for Document Exchange

      • One of the key advantages of XML is its generic way of representing not only data but also complex documents.

  1. The Web Services Architecture

There can be tremendous benefits to web services. We have heard of interoperability between platforms, ability to invoke a web service over a ubiquitous network technology, and so on.


So what is it?? Let’s take a look at a conceptual model.


  • Web Services are self-contained, modular applications that can be described, published, located, and invoked over a network, generally, the World Wide Web.


  • The Web Services architecture describes three roles: Service provider, Service requester and Service broker; and three basic operations: publish, find and bind. A network component can play any or all of these roles.



  • A Web Services architecture implementation should allow for incremental security and quality of service models facilitated by configuring a set of environmental prerequisites (for example, authentication mechanism, billing, and so on) to control and manages the interactions.


  • Web Services can be dynamically composed into applications stemming from capabilities-based look-up at runtime, instead of the traditional static binding. The dynamic nature of the collaborations allow the implementations to be platform- and programming language-neutral, and communications mechanism-independent, while creating innovative products, processes, and value chains.

  1. The Basic Web Services Stack

Now let’s understand Web Services Stack. Basic Web Services Stack contains:

    • Simple Object Access Protocol (SOAP).

    • Web Services Definition Language (WSDL).

    • Universal Description, Discovery, and Integration (UDDI).



  • SOAP

    • Provides a standard packaging structure for transporting XML documents over a variety of standard Internet Technologies.

    • Also defines encoding and binding standards for encoding non-XML RPC invocation in XML for transport.

    • Heterogeneous platforms become interoperable

    • The Basic SOAP Structure



  • WSDL

Another XML grammar that describes the interface of the Web Service. You may want to compare it only in concept to the “Remote Interface” of Java RMI or the “Interface Definition Language File (IDL)” for RPC. More specifically it standardizes how a web service represents the input and output parameters of an invocation externally. I.e. The function structure, the nature of invocation (in, in/out, etc), and the service protocol binding. And since it is XML grammar, don’t need to say it is interoperable to anyone who understands the grammar.


WSDL in the Eco System


  • UDDI

    • UDDI provides a world wide registry of web services for advertisements, discovery, and integration purposes.

    • UDDI could be dynamic or static and a Business Analysts and technologists could use UDDI to search for available web services.

    • The UDDI Business Registry provides a place for a company to programmatically describe their services and business processes and their preferred methods for conducting business.

  1. Introduction to Axis


The Apache extensible Interaction System (Axis) is basically a SOAP engine. It represents a framework for constructing SOAP processors such as clients, servers, or gateways. Axis is an Apache open-source project and is written in Java.


Besides being a SOAP engine, Axis also includes the following features:

  • A server that plugs into servlet engines such as Web Sphere Application Server or Apache Tomcat

  • Extensive support for the Web service description language (WSDL)

  • Tools that generate Java classes from WSDL and vice versa (WSDL2Java and Java2WSDL).

  • A tool for monitoring TCP/IP packets


TCP/IP monitoring is a very efficient tool for Web services’ debugging and troubleshooting.

  1. Software Requirements

Web server: Apache Jakarta Tomcat v4.1
JDK: Sun J2SE v1.4.2
Platform: Microsoft Windows XP


Implementation on Web logic Server can refer following link.


http://ws.apache.org/axis/java/install.html#WebLogic8.1

  1. A Quick implementation of Web Services using Axis

(8 Steps procedure):


Apache Axis alleviates the development of Web Services. This implementation is explained using Tomcat Server.


  1. Download Apache axis from the following URL.

http://archive.apache.org/dist/ws/axis/1_1/axis-1_1.zip

This URL downloads Apache Axis v1.1 zip file for Windows.


  1. Unzip the file at your convenient folder and you would see following folder structure after unzipping.



  1. Now we will have to deploy axis as Web Application in Tomcat Web Server. Copy axis folder under webapps folder to your Tomcat webapps folder.


  1. Set the Environment Variables

AXIS_HOME = C:Tomcatwebappsaxis

AXIS_LIB = %AXIS_HOME%WEB-INFlib

AXISCLASSPATH = %AXIS_LIB%axis.jar;%AXIS_LIB%axis-ant.jar;%AXIS_LIB%commons-discovery.jar; %AXIS_LIB%commons-logging.jar; %AXIS_LIB%jaxrpc.jar; %AXIS_LIB%saaj.jar; %AXIS_LIB%log4j-1.2.8.jar; %AXIS_LIB%wsdl4j.jar


Add %AXISCLASSPATH% to system CLASSPATH and environment variables entries look like the snap shot below.




Now the Axis setup and installation is ready to launch any web service.


To confirm that everything set correct,

    • Start Tomcat Server

    • Run this JSP.

http://localhost:8080/axis/happyaxis.jsp

This jsp confirms that all required axis Jars are in CLASSPATH and if there are any mandatory jars missing it would warn.


Above screen shot shows that installation and setup are successful.


  1. Let’s create a Service now, copy and save below code as TemperatureConverter.jws in %TOMCAT_HOME%/axis folder.


public class TemperatureConverter {


public float celsiusToFahrenheit (float celsius) {

float fahrenheit = (celsius *9/5)+32;

return fahrenheit;

}


public float fahrenheitToCelsius(float farenheit) {

float celsius = ((farenheit-32)*5/9);

return celsius;

}


}



  1. Now lets Check whether Service has been deployed or not and lets generate the WSDL for our Web Service.


  • Check for Service

http://localhost:8080/axis/TemperatureConverter.jws



  • Generate WSDL for our TemparatureConverter Web Service.

http://localhost:8080/axis/TemperatureConverter.jws?wsdl


Axis has generated WSDL for TemperatureConverter Web Service that we have deployed.


Now everything set correct and web service is ready.


  1. Start TCP Monitor (tcpmon) to view SOAP Messages that are exchanged between Server and Web Service Client.


Run following command at prompt.


C:> java org.apache.axis.utils.tcpmon

You would see the following screen


We should select a local port which tcpmon will monitor for incoming connections, a target host where it will forward such connections, and the port number on the target machine which should be "tunneled" to. Then click "add".

You should then notice another tab appearing in the window for your new tunneled connection. Looking at that panel, you'll see something like this.



Now each time a SOAP connection is made to the local port, you will see the request appear in the "Request" panel, and the response from the server in the "Response" panel. Tcpmon keeps a log of all request/response pairs, and allows you to view any particular pair by selecting an entry in the top panel. You may also remove selected entries, or all of them, or choose to save to a file for later viewing.


  • Now, Our Web Services Client should connect to port 8010, which is redirected to 8080 port by TCP Monitor.

  • If you don’t want to use TCP Monitor skip Step 7.


  1. Let’s write a Web Services Client to connect server.


import java.net.MalformedURLException;

import java.rmi.RemoteException;

import javax.xml.rpc.ParameterMode;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

import org.apache.axis.encoding.XMLType;


/**

* @author V.V.Nagesh Akula

*/

public class TempConverterClient {

public static void main(String[] args) {

Float ret=null;

try {

String method = null;

method = "celsiusToFahrenheit";

Float f1 = new Float("30");

Service service = new Service();

Call call = (Call) service.createCall();

// Use port 8010, if you use TCP Monitor

// Use Port 8080, if you don’t use TCP Monitor

call.setTargetEndpointAddress(new java.net.URL(

"http://localhost:8010/axis/TemperatureConverter.jws"));

call.addParameter( "op1", XMLType.XSD_FLOAT, ParameterMode.IN );

call.setOperationName(method);

call.setReturnType(XMLType.XSD_FLOAT);

ret = (Float) call.invoke(new Object[] {f1});

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (RemoteException e) {

e.printStackTrace();

} catch (ServiceException e) {

e.printStackTrace();

}


System.out.println("Got result : " + ret);


}


}


  • Console output that you would get after running Web Service Client.



























  • You would see SOAP messages that are exchanged, in TCP Monitor.





  1. Conclusion


This document gives a basic understanding of Web Services and a quick implementation of Web Services using Apache Axis Framework.


  1. References

http://ws.apache.org/axis/

Page 14 of 14

No comments: