Developing Web Services Using Apache Axis2


These are the tools used in the tutorial.

1) Java Development Kit 1.4.2.x (Download)

2) Eclipse SDK 3.2.x (Download)

3) Apache Tomcat 4.1.x (Download)

4) Axis2 Web Application (Download)

5) Axis2 Eclipse Plugins (Download)

First download this two eclipse plugins and place them inside the dropins folder in eclipse. Other than the two plugins, we need the Axis2 runtime to deploy the developed Web services. We use the Axis2 Web Application which can be deployed in any popular servlet container. (You can download the Axis2 Web Application from the Axis2 Download page.) You have to just place it in the repository of the servlet container and run it. For example, if you are using Apache Tomcat, just copy the downloaded .war file, put it in the webapp folder, and start the servlet container.

PART 1 – The Bottom Up Approach in Web Services Development Using the Apache Axis2 Eclipse Plugin

  1. Start Eclipse SDK. First we need to create a JAVA project in Eclipse. (Follow the instruction on Eclipse SDK help.) You can give any name to the JAVA project, but for clarity, let us create a JAVA project called “TemperatureWebService”.In the Bottom Up Approach, we start with the service implementation and then build the deployable Web service component. We will be using the TemperatureConverter class definition as the logic for developing, deploying, and testing the Web service.
  2. Create a custom package ws.example appropriately and include the file in that package. Compile and build the project.
    package ws.example;
     * Temperature Converter Implementation Class
    public class TemperatureConverter {
     * util method to convert Celsius to Fahrenheit
     * @param cValue : double value of celsius
     * @return calculated value of fahrenheit
     public double c2fConvertion(double cValue) {
     return ((cValue * 9.0)/5.0 )+ 32.0;
     * util method to convert fahrenheit to celsius
     * @param fValue : double value of fahrenheit
     * @return calculated value of celsius
     public double f2cConvertion(double fValue) {
     return ((fValue - 32.0) * 5.0) / 9.0;
  3.  After successfully building the project, we will create the service archive using the Axis2 Eclipse Service Archiver Plugin. On the File menu, click New and then click Other to access the Axis2 wizards. Else, you can press Ctrl+N.
    Note : At any given time, you can go back through the wizards, change the settings, and even start the wizards all over again to create a different Web service on another JAVA project available in your workspace.image001
  4. Select the Axis2 Service archiver and click Next. You will see the Axis2 service definition selection page.image002On this page, select the output location of the “TemperatureWebService” Java project that we previously developed. Here we point to the service implementation classes. If there is more than one class, you only have to point to the JAVA project build location. The wizard includes all the implementation files. To be on the safe side, if you are going to expose a complex project as a Web service, it’s better to select the include .class files check box to omit unnecessary resource files that will increase the size of the deployable service archive that we are going to create.
  5. After selecting the correct output location, click Next.After selecting the correct output location, click Next.image003
    On this page, you can browse for the WSDL file. If you do not want to add a WSDL file to the service archive, select the Skip WSDL check box. Else you can select the Select WSDL check box, and specify the location of the WSDL file. We will skip the WSDL for the moment.
  6. Click NEXT
    image004This page is to add the libraries. The library name (with the full path) can be specified by either typing it or browsing for it. Once the library name with the full path is entered, click Add to add the library to the list. The added libraries should be displayed in the Added libraries list. You can add as many external libraries as you wish.If any added library has to be removed, select it from the Added libraries list and click Remove.
  7. For this example, we do not need any external libraries added to the generated service. Therefore, click Next to proceed to the next stepimage005This page is about the services.xml generation. If you have a custom services.xml file, you can select the services.xml file on this page by browsing for it or you can generate the service XML automatically. The browsing option is disabled when the Generate service xml automatically check box is selected.
  8. For this example, we use the automatically generated services.xml rather than a custom written one. Therefore, select the Generate service xml automatically check box, and then click Next.image006
    Note that this page will appear only if you selected to generate the services.xml automatically in the previous step. (If you selected a services.xml file, then you will be directed to the last page of the wizard.) After entering the correct service name and a valid fully qualified class name, load the existing methods of that class by clicking Load. If it is successfully loaded, you will see a table at the bottom of the page with the details of the loaded class. You can specify the methods to include in the services.xml by selecting the corresponding check boxes.
  9. Select the Search declared method only check box, to remove the inherited methods from the class. We do not need the inherited methods to be exposed and our only interest is in temperature conversion logic. Click Next to proceed to the last page of the wizard.image007
    On the last page of the wizard, specify the output file location and the output archive file name to complete the wizard. Note the location given in the example above. After specifying a name to identify the service that we will be deploying, we can directly guide the wizard to deploy this newly created Web service on any available Web service repository.Since we already have the Apache Axis2 Web application deployed on the servlet container, we can easily guide the wizard to deploy the service in the Axis2 Webapp (Axis2.war) inside Apache Tomcat. After deploying the Web application, the service repository will be available in the <TOMCAT_HOME>/webapp/axis2/WEB-INF/services folder.
  10. Click Finish to complete the steps in the wizard.
  11. Start the servlet container (in this case the Apache Tomcat), and navigate to http://localhost:8080/axis2 This will lead to the Axis2 Web application home page.image_b001image_b002



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s