Tuesday, April 10, 2012

Say 'Hello' to Apache Axis2

During the vacation i read some articles and books about various interesting topics which i like most. I read about axis2 also. And i decided to write a post which will help a person without any clue about axis2.

What is apache axis2
"Apache Axis2™ is a Web Services / SOAP / WSDL engine, the successor to the widely used Apache Axis SOAP stack. There are two implementations of the Apache Axis2 Web services engine - Apache Axis2/Java and Apache Axis2/C"

This post is related to Apache Axis2/Java. We will write a simple Java class and make it a service. 
You can download Apache Axis2 from here

 * The service implementation class
public class HelloService {

* The sayHello method will be exposed as the 
* sayHello operation of the web service
public String sayHello(String value) {
return "Hello"+value;

Save the above class as HelloService.java

Each Axis2 service must have a services.xml file which will inform Axis2 about the service. Following is the services.xml file for the HelloService Web service.

<parameter name="ServiceClass" 
<operation name="sayHello">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>

Save it as services.xml .

These should be packaged according to a format in order to be deployed in Axis2.

Create a directory called  "package".  mkdir package.
Next , compile the HelloService.java class and move the HelloService.class file to the package directory.

Now create a META-INF directory within the 'package' and copy the services.xml file in to META-INF directory.

javac HelloService.java -d package/

Change the directory to package and use the following command to create the axis2 archive file.

jar -cvf HelloService.aar *

Copy the HelloService.aar to axis2-1.6.0/repository/services and the service will be listed

No comments:

Post a Comment