Apache Axis2 Integration with Eclipse
By Harshana Martin
- 15 Jun, 2012
|WSO2 Developer Studio||2.0.0|
|Eclipse Helios SR2||3.6.2|
Table of Content
- Installing WSO2 Developer Studio
- Top Down Web Service Implementation
- Bottom Up Web Service Implementation
- Deploy Web Service in Axis2
WSO2 Developer Studio installation guide can be found from here . After installing WSO2 Developer Studio we can continue to implement the Axis2 Web Services with it.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
- Export the Axis2 Service Project from Developer Studio IDE
- Build the Axis2 Service Project with Apache Maven build tool
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.
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.
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.
2. Go to the location of the project from your console and provide the command mvn clean install to generate the Axis2 Service Archive.
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.
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.
Harshan Eranga Martin,
Senior Sfoware Engineer,