January 15, 2012

Deploying an Apache Axis2 Web Service - Hello World Example

1) Setup Apache Axis2 in the web application - follow the steps here

2) Create a POJO - HelloWorldService.java - in the src folder of the web application

package info.icontraining.ws.axis2;

public class HelloWorld {
   public String sayHello(String name) {
      return "Hello " + name;
   }
}

3) In the WebContent/WEB-INF/services folder, create a new folder and name it 'HelloWorld'.
In this folder create a sub-folder and name it 'META-INF'.
In the META-INF folder create a new XML file - name it 'services.xml'.

4) Add the following configuration to the services.xml file created in the step above,

<service>
   <parameter name="ServiceClass" locked="false">info.icontraining.ws.axis2.HelloWorld</parameter>
   <operation name="sayHello">
      <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
   </operation> 
</service>

5) Now go to the build/classes folder of the web application. Copy the folder named 'info' and paste it into the services/HelloWorld folder created in step 3.

So, now in the services/HelloWorld folder, there are 2 folders - META-INF and info
The META-INF folder contains the services.xml file.
The info folder contains the following hierarchy of sub-folders - icontraining/ws/axis2/HelloWorldService.class

6) Deploy the Web Application to the server, and access the following URL in the browser,

http://localhost:8080/WebAppName/services/listServices

The HelloWorld service will be present in the list of services.

7) Invoke the Web Service with the following URL in the browser,

http://localhost:8080/WebAppName/services/HelloWorld/sayHello?name=dinesh

No comments:

Post a Comment