Developing web services -part 1

This series on developing web services gives an insight on developing web service using Axis framework.A credit card validation example is done using the web service and the testing part is also shown in the example.

A web service is a network accessible interface to application functionality, built using standard Internet technologies.

The web services that we see deployed on the Internet today are HTML web sites. In these, the application services—the mechanisms for publishing, managing, searching, and retrieving content—are accessed through the use of standard protocols and data formats: HTTP and HTML. Client applications (web browsers) that understand these standards can interact with the application services to perform tasks like ordering books, sending greeting cards, or reading news. Because of the abstraction provided by the standards-based interfaces, it does not matter whether the application services are written in Java and the browser written in C++, or the application services deployed on a Unix box while the browser is deployed on Windows. Web services allow for cross-platform interoperability in a way that makes the platform irrelevant. Interoperability is one of the key benefits gained from implementing web services. Java and Microsoft Windows-based solutions have typically been difficult to integrate, but a web services layer between application and client can greatly remove friction.

Benefits of web service

The web service, a very well known open technology standard provides a number of benefits as listed below:

  • Increase competition among vendors, resulting in lower product costs.
  • Ease transition from one product to another, resulting in lower training costs.
  • Increase the ability for parties to interoperate, resulting in lower maintenance costs.
  • Ensure a greater degree of adoption and longevity for a standard. A large degree of usage from the vendors and the users leads to a higher degree of acceptance.

How do organizations move into web service

There are three main ways in which an organization can move into Web Services. These are as follows:

  1. Creating a new web service from scratch (Contract First): The developer creates the functionalities of the services as well as preparing a document to describe those services.
  2. Exposing an existing functionality through a web service (Code First): Here, the functionalities of the service already exist. Only the service description needs to be implemented.
  3. Integrating web services from other vendors or business partners (Meet in the Middle): There are instances where using a service implemented by another is more feasible than building from scratch. On these occasions, the organization will be required to integrate others’ or even business partners’ Web Services.

The real utility of the Web Service concept is present in the second and the third methods, which leads to other Web Services and applications that can be used in existing applications.

 

Code first approach versus contract first approach

Code first (Bottom Up) approach allows you to reuse your investment by exposing your existing application. Credit Card System is an existing Application with Proven business value. Competitive pressure is moving Credit Card System to expose some of this business functionality Like (Credit Card Number Validation) as web service. The implementation class already exists, all that is needed is to create a WSDL and expose the class as web service.

Contract First (Top Down) often termed as “Pure Approach” is the correct way to build new web service from scratch. This Approach starts with the WSDL (the contract) by defining operation message and so forth. Then you build the endpoint interface and finally the implementation class.

Axis2 architecture

Axis2 is built upon a modular architecture that consists of core modules and non-core modules. The core engine is said to be a pure SOAP processing engine (there is not any JAX-PRC concept burnt into the core). Every message coming into the system has to be transformed into a SOAP message before it is handed over to the core engine. An incoming message can either be a SOAP message or a non-SOAP message (REST JSON or JMX). But at the transport level, it will be converted into a SOAP message. When Axis2 was designed, the following key rules were incorporated into the architecture to achieve a highly flexible and extensible SOAP processing engine:

  • Separation of logic and state to provide a stateless processing mechanism. (This is because web services are stateless.)
  • A single information model in order to enable the system to suspend and resume.
  • Ability to extend support to newer web service specifications with minimal changes made to the core architecture.

The Apache Axis2 architecture is built on the foundation of a SOAP engine. This engine accepts SOAP messages, parses them, and calls the appropriate methods and functions in the web service. At this level of detail, Axis is just like every other web services engine. The uniqueness of this product, and every other product, lies in how a developer would go about organizing the processing so that the message can be responded to properly.

Example I – Credit card validation web service using AXIS2

This is a simple Credit Card Validation web service with Code First Approach, where user will input the 16 digit credit card number to validate it and also to find out the credit card vendor. To setup and run this example one need to know few things given below:

Eclipse IDE: An integrated development environment (IDE) is an all-in-one tool for writing, editing, compiling, and running computer programs. And Eclipse provides an excellent integrated development environment. You can find the latest release of eclipse in www.eclipse.org.

Tomcat web server 5.5 or above: The Tomcat servlet engine is an open-source package developed as part of the Apache Software Foundation’s Jakarta project. It is the official reference implementation for both the servlet and JSP specifications. Tomcat can act as a stand-alone Web server and also as a servlet/JSP engine. You can download the latest release of Tomcat from http://tomcat.apache.org/download-60.cgi.

Axis2:

(Binary Distribution): An Axis2 binary distribution consists of all the relevant third-party libraries, a set of samples, and the Axis2 runtime. Installing a binary distribution involves extracting ZIP archive files into a desired location. Once we download and extract the binary distribution, then we will be able to see a set of subdirectories inside it (bin, lib, samples, repository, webapp).

(War distribution): The Axis2 WAR distribution is useful for deploying Axis2 in application servers such as Tomcat, Jboss, Weblogic, and so on. We can deploy the Axis2 WAR file into an application server, and check whether it works by typing the server address in a browser. For an example, if you deploy the Axis2 WAR file in Apache Tomcat, by typing http://localhost:8080/axis2, we can figure out whether Axis2 is up and running.

We can download the latest Axis2 release from http://ws.apache.org/axis2/download.cgi. Each Axis2 release consists of four main release artifacts or distributions:

  • Binary distribution
  • WAR distribution
  • Source distribution
  • JAR distribution

Set up the Environment

  1. Install JDK 1.5 or above in your system.
  2. After downloading Axis2 file (war version) extract the zip file to any local directory. After extracting you will find axis2.war file. Copy the file and paste it to the <TOMCAT_HOME>webapp| directory, then start Tomcat. As shown in Figure 1. Tomcat startup console. After this go the <TOMCAT_HOME>webapps| directory, inside this you will find a new directory named axis2, which indicates that the axis2.war file is deployed successfully.
  3. Download and extract Axis2 binary Distribution to a directory, which will be referred as <AXIS2_HOME>.