Implementing Web Services Using Axis 2 Framework
Scope
This document is NOT intended to be used as a reference for WebServices, SOAP or Axis. Also, we are not going to talk about WSDL authoring.
Our aim here is to create simple Axis2 WebService (Server), given a WSDL file, using the Eclipse IDE. This document is to serve as a quick reference guide which enlists all the steps you need to undertake to achieve the aforementioned objective.
The WebService that we create is an extension of traditional HelloWorld WebService, in that; we show how to handle exceptions.
You can create both, synchronous and asynchronous Clients for consumption of this WebService. (For Java Client, please refer next BOK in the series named “Implementing Web Services Client Using Axis 2 Framework.doc”.)
Pre-requisites
1. You should have a good understanding of WebServices and SOAP. (In case you don’t have time for a detailed study, we have trifine these in very abstract terms. Refer next section.)
2. You should know how to write a WSDL or at least should have one ready for use. (Refer next section for an overview. We have attached the WSDL file we used for demonstration.)
Some useful definitions:-
2.1 Web Services
In this age of distributed computing, it is often required that a system interacts with other, heterogeneous, systems over the network. For instance, say, we have a Website and we need to implement search functionality in it. This search takes a string as input and generates a list of URLs, much like what Google search engine does. Now since, we have this functionality already implemented and working fine, wouldn’t it be nice to use this functionality directly and not implement it from scratch? Of course, in order to achieve this, Google needs to expose this functionality for our use and we need to devise some way to consume it. If Google complies, imagine how could we achieve this? WebServices is one of the answers to this question and considered by many as best fit.
In WebServices, one of the communicating parties will expose its services and the other will try to consume it. The functionality exposed can be viewed as a set of methods that the consumer can invoke remotely (a remote interface). The details of request parameters, response, the exposed methods and the identity or the address of the implementation needs to be pre-defined and agreed upon. These service details are defined generally in a contract file called the WSDL (WebService definition Language) file. This is an XML file which enlists all the operations (methods), messages (input and output parameters), the underlying message protocol (e.g. SOAP) and the binding (basically, the URL) information for the WebService. Both the communicating parties need to have this file in order to invoke and implement the WebService. WebServices follow well defined architecture (namely, SOA and REST) and there is a set of well defined steps that the communicating parties need to undertake, to actually locate and invoke the WebServices. Explaining these steps is beyond the scope of this document.
2.2 SOAP (Simple Object Access Protocol)
SOAP is an XML based message protocol (or set of rules), that governs how two objects on heterogeneous systems communicate. It builds upon already existing HTTP and XML specifications. HTTP (Hypertext Transfer Protocol) and (XML) Extensible Markup Language are used as mechanisms for exchanging information.
The SOAP specification defines how to encode an HTTP header and an XML file so that information can be passed between the two communicating parties. To rephrase, the information passed between the systems are nothing but SOAP messages (XML document adhering to SOAP specifications). In a way, you can view CORBA, RMI etc. as peers of SOAP.
Since, it uses HTTP SOAP is firewall friendly. SOAP can also be bound to different protocols like SMTP, JMS, etc. The current specification is 1.1.
2.3 Axis So, with the premise established hitherto, we can imagine different systems exposing their functionality as WebServices and SOAP messages being passed (to invoke them and receive responses). In order to construct and interpret SOAP messages, we need to have some sort of SOAP engine on the actual (Client and Server) systems. AXIS is a SOAP engine. AXIS2 also provides tools and framework that helps its users with following tasks:
- Send and Receive SOAP messages
- Facilitates creation of WebServices
- Auto generation of classes for both and server implementation from WSDL.(We will concentrate on this aspect)
- Creation and consumption of RESTful WebServices.
2.4 WSDL (Web Services Definition Language)
As the name suggests, WSDL is used to define your WebServices. It is an XML based Interface Definition Language. Basically, it is a document defining the functionality offered by a WebService and format of messages along with binding details of a service. In order to use a WebService, the consumer system needs to have a copy of the WSDL document.
3 Installing and setting up Axis2 Runtime in Eclipse · Please refer following link to install and setup Axis2 runtime
http://ws.apache.org/axis2/1_0/installationguide.html
· After you have done with the above step, set preferences in Eclipse IDE as described below:
Click on Window à Preferences à Web Services à Axis 2 Preferences à Specify the Axis 2 runtime location.
This document is NOT intended to be used as a reference for WebServices, SOAP or Axis. Also, we are not going to talk about WSDL authoring.
Our aim here is to create simple Axis2 WebService (Server), given a WSDL file, using the Eclipse IDE. This document is to serve as a quick reference guide which enlists all the steps you need to undertake to achieve the aforementioned objective.
The WebService that we create is an extension of traditional HelloWorld WebService, in that; we show how to handle exceptions.
You can create both, synchronous and asynchronous Clients for consumption of this WebService. (For Java Client, please refer next BOK in the series named “Implementing Web Services Client Using Axis 2 Framework.doc”.)
Pre-requisites
1. You should have a good understanding of WebServices and SOAP. (In case you don’t have time for a detailed study, we have trifine these in very abstract terms. Refer next section.)
2. You should know how to write a WSDL or at least should have one ready for use. (Refer next section for an overview. We have attached the WSDL file we used for demonstration.)
Some useful definitions:-
2.1 Web Services
In this age of distributed computing, it is often required that a system interacts with other, heterogeneous, systems over the network. For instance, say, we have a Website and we need to implement search functionality in it. This search takes a string as input and generates a list of URLs, much like what Google search engine does. Now since, we have this functionality already implemented and working fine, wouldn’t it be nice to use this functionality directly and not implement it from scratch? Of course, in order to achieve this, Google needs to expose this functionality for our use and we need to devise some way to consume it. If Google complies, imagine how could we achieve this? WebServices is one of the answers to this question and considered by many as best fit.
In WebServices, one of the communicating parties will expose its services and the other will try to consume it. The functionality exposed can be viewed as a set of methods that the consumer can invoke remotely (a remote interface). The details of request parameters, response, the exposed methods and the identity or the address of the implementation needs to be pre-defined and agreed upon. These service details are defined generally in a contract file called the WSDL (WebService definition Language) file. This is an XML file which enlists all the operations (methods), messages (input and output parameters), the underlying message protocol (e.g. SOAP) and the binding (basically, the URL) information for the WebService. Both the communicating parties need to have this file in order to invoke and implement the WebService. WebServices follow well defined architecture (namely, SOA and REST) and there is a set of well defined steps that the communicating parties need to undertake, to actually locate and invoke the WebServices. Explaining these steps is beyond the scope of this document.
2.2 SOAP (Simple Object Access Protocol)
SOAP is an XML based message protocol (or set of rules), that governs how two objects on heterogeneous systems communicate. It builds upon already existing HTTP and XML specifications. HTTP (Hypertext Transfer Protocol) and (XML) Extensible Markup Language are used as mechanisms for exchanging information.
The SOAP specification defines how to encode an HTTP header and an XML file so that information can be passed between the two communicating parties. To rephrase, the information passed between the systems are nothing but SOAP messages (XML document adhering to SOAP specifications). In a way, you can view CORBA, RMI etc. as peers of SOAP.
Since, it uses HTTP SOAP is firewall friendly. SOAP can also be bound to different protocols like SMTP, JMS, etc. The current specification is 1.1.
2.3 Axis So, with the premise established hitherto, we can imagine different systems exposing their functionality as WebServices and SOAP messages being passed (to invoke them and receive responses). In order to construct and interpret SOAP messages, we need to have some sort of SOAP engine on the actual (Client and Server) systems. AXIS is a SOAP engine. AXIS2 also provides tools and framework that helps its users with following tasks:
- Send and Receive SOAP messages
- Facilitates creation of WebServices
- Auto generation of classes for both and server implementation from WSDL.(We will concentrate on this aspect)
- Creation and consumption of RESTful WebServices.
2.4 WSDL (Web Services Definition Language)
As the name suggests, WSDL is used to define your WebServices. It is an XML based Interface Definition Language. Basically, it is a document defining the functionality offered by a WebService and format of messages along with binding details of a service. In order to use a WebService, the consumer system needs to have a copy of the WSDL document.
3 Installing and setting up Axis2 Runtime in Eclipse · Please refer following link to install and setup Axis2 runtime
http://ws.apache.org/axis2/1_0/installationguide.html
· After you have done with the above step, set preferences in Eclipse IDE as described below:
Click on Window à Preferences à Web Services à Axis 2 Preferences à Specify the Axis 2 runtime location.