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:
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:
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 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:
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.
(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:
Set up the Environment