2012/06/15
15 Jun, 2012

Apache Axis2 Integration with Eclipse

  • Harshana Martin
  • ATL - WSO2

Applies To:

WSO2 Developer Studio 2.0.0
Eclipse Helios SR2 3.6.2
Apache Axis2 1.6.2

Table of Content

  1. Installing WSO2 Developer Studio
  2. Top Down Web Service Implementation
  3. Bottom Up Web Service Implementation
  4. Deploy Web Service in Axis2

Installing WSO2 Developer Studio

WSO2 Developer Studio installation guide can be found from here [1]. After installing WSO2 Developer Studio we can continue to implement the Axis2 Web Services with it.

Top Down Web Service Implementation

There are 2 methods to implement Axis2 Web Services. First method we are going to discuss here is known as Top Down approach. In top down web service implementation first thing you implement is the WSDL (Web Service Description Language) file which defines the Web Service contract. WSDL file defines all the information about the Web Service and how the clients can access the Web Service, etc.

Once you finish the implementing your WSDL file, you can use this WSDL file to generate Axis2 web service.

1. Select File -> New -> Other

NewOption

2. From the New Wizard, first select and expand the WSO2 Category and once you expand it, you will see a set of sub categories and select Service Hosting sub category. When you select that sub category, it will show a set of options. From these options select Axis2 Service Project and click on Next.

New12

3. Now you will see the New Axis2 Service wizard and and in this wizard page you can select which approach you are going to use to implement the Web Service. Since we are going to implement from the Top Down approach, we use Create New Axis2 Web Service using WSDL file option. Then click on Next again.

New13

4. In the next wizard page you can point to your WSDL file and you need to provide a name for your Axis2 Service Project. This Project name will be used as the Axis2 Service name as well.

New14

5. You can click on the Browse button and it will open up the a File System Browser. From this browser you can select the WSDL file you want to create your web Service.

New15

6. As we mentioned in the Step 4, you need to provide a project name for your Axis2 Service as well. you need to enter that name in the Project Name text box in this wizard page. Then click on Next button.

New16"

7. Now you will get the Axis2 Service Configuration options page. In this page you can configure Axis2 service related configurations such as Port Name, Binding Type, package for service, Service Style (Sync, Async), Unpacking, Wrapping, etc. We have included most widely used options in this wizard page. Once you set all the Service generation options, click on Finish button.

New17

8. After you click on Finish, Axis2 Service generation task will be executed and it will create a new Axis2 Project with a Axis2 Service related classes in your workspace. This Axis2 Service project will have the name you have provided in previous steps.

New18

9. Apart from the classes, this Axis2 service generation process will generate the services.xml file which is the configuration file for the Axis2 Web Service as well. You can see that in the image below.

New19"

10. Now you have generated the Web Service classes and the services.xml configuration file, you can complete the web service operation logic implementations in these classes. Once you are done with the service operation logic implementations, you are able to generate the Deployable Axis2 Service Artifact (.aar) file from this project and deploy it in Axis2 Server. Please follow the section on Deploy Web Service in Axis2 for more information.

Bottom Up Web Service Implementation

As we mentioned in a previous section, there are 2 well known approaches to implement Axis2 Web Services and in the previous section of this article we described about one of them, top Down Implementation. In this section we are going to discuss about the other approach which is well knwon as Bottom UP Web Service Implementation.

In this Bottom Up implementation, instead of implementing the Web Service operation logic at the end of the Top down approach, we first implement the Web Service operation logic in classes and then create the service from these POJO (Plain Old Java Object) classes. Hence first step is to create the classes in the project and then implement web service operations in there.

In this section of this article we are going to discuss about creating an Axis2 web service from this approach.

1. Follow step 1 and 2 of Top Down approach and select New Axis2 Project wizard from the new wizard list.

2. In the New Axis2 Project wizard, now we select first option, Create New Axis2 Service option. Then click on Next.

Bup1

3. In the next wizard page, you need to enter few information related to your Axis2 web service such as Project Name which is again going to be your Axis2 Service name. Then you need to enter the package and the Class name for your POJO.

These information is used to generate the Axis2 service and the Axis2 service configuration file, services.xml.

Once you complete these information click on Finish.

Bup2"

4. Now you will see that tool has created the new Axis2 project with the name you have entered and there is a Java Class with the full qualified name you have entered. This class is your POJO class and you need to define your Web Service operations in this class. Just like a normal java application you can do the implementations.

Please keep in mind that Web Services are Stateless when you are implementing these operations.

Bup3

5. In the image below, you can see that we have implemented our web Service logic in the class tool has created. Once you are done with the implementation, you have successfully implemented your web Service.

Bup4

You can export the Axis2 Web service deployable archive (.aar) file from this project and deploy this Axis2 service in your Axis2 Web service engine. For more information look at the Deploy Web Service in Axis2 section on this article.

Deploy Web Service in Axis2

Axis2 web services are normally exported as Axis2 Service Archives with the file extension "aar". So to deploy an Axis2 web service, you need to make aar file out of this Axis2 Service. WSO2 Developer Studio tools supports generating Axis2 services to deploy on Apache Axis2 Web service engine. as a part of these tools, it supports implementing Axis2 Service Archives as well.

There are 2 methods to generate the aar file for your Axis2 web service with WSO2 Developer Studio. We are going to discuss those 2 methods in the next sections.

  1. Export the Axis2 Service Project from Developer Studio IDE
  2. Build the Axis2 Service Project with Apache Maven build tool

Export the Axis2 Service Project from Developer Studio IDE

First approach to get a Axis2 Service Archive is to use the Artifact Export option in Developer Studio IDE. This mechanism allows you to generate the aar file for your Axis2 Service project to a selected location in your file system.

This section in this tutorial explains about using Artifact Export option in Developer Studio.

1. Right click on your Axis2 Service Project and Select Export Project as Deployable Archive option.

build1

2. Now you will get the Export dialog and there you can select the Project you want to Export and the export location. Once you click on Finish, Developer Studio will generate the Axis2 Service Archive in the location you have pointed.

build2

Build the Axis2 Service Project with Apache Maven build tool

Next approach to generate the Axis2 Service Archive without using Developer Studio is to use Apache Maven build tool. For each and every Axis2 Service Project, Developer Studio generates a Maven Project Object Model which is commonly known as Maven pom file. This file contains the maven related configuration for your project.>

In this section of the article explains how to use Maven build tool to generate the Axis2 Service Archive. Please note that you need to install Apache Maven tool in your system prior to using this option.

1. Image below shows the Maven pom file generated for your Axis2 Service Project.

build3

2. Go to the location of the project from your console and provide the command mvn clean install to generate the Axis2 Service Archive.

build4

Now you have successfully generated the Axis2 Service Archive (aar) for your web service. You can copy this file to Axis2 hot deployment folder and your web service will be deployed in the Axis2 Web service engine.

build5

build6

If you have any question regarding the steps of this article, please feel free to make a comment or drop a mail to [email protected] mailing list. We are happy to assist you.

References:

  1. https://wso2.org/project/developer-studio/docs/install_guide.html

Author

Harshan Eranga Martin,
Senior Sfoware Engineer,
WSO2 Inc

 

About Author

  • Harshana Martin
  • ATL
  • WSO2