WSO2 SUMMIT 2020   ·   Building an Integrated API Supply Chain   ·   Register Now!

How to Embed an Axis2 based Web Service in your Webapp?

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Davanum Srinivas
  • 17 May, 2006

<display-name>Apache-Axis Servlet</display-name>

Next, We need a simple web service. Let's pick a Book service with 2 operations findBook and getBooks Snippet from BookService.java:

    public Book[] getBooks() {
return new Book[]{onlyBook};

public Book findBook(String isbn) {
if (isbn.equals(onlyBook.getIsbn()))
return onlyBook;

return null;

Next we need a deployment descriptor for the BookService. As you can see, you can deploy a POJO using RPCMessageReceiver and you can specify a namespace for the schema as well as for the web service itself.

<service name="BookService"
<description>Book sample service</description>
<schema schemaNamespace="http://ws.apache.org/axis2/samples/book/xsd/"/>
<parameter name="ServiceClass" locked="false">samples.demo.BookService</parameter>
<operation name="getBooks">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
<operation name="findBook">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>

Next, do we really need to create an aar? An aar is useful for hot deployment and service isolation, but this is an embedded scenario, so we go with the "Exploded deployment option" which means that we create a directory structure inside our WEB-INF as follows:

| web.xml

Usually we would have dropped a BookService.aar in the services directory, here we create a directory named BookService and drop the deployment descriptor (services.xml) inside the META-INF directory under it. Hmm, did we forget something? Yes, how about an easy build environment using maven2? Here's the layout of our files for maven2.

| pom.xml
| | log4j.properties
| |
| \---samples
| \---demo
| Book.java
| BookService.java
| web.xml

All the jars needed as dependencies are automatically downloaded by maven2 from the Apache and Ibiblio respositories. So you don't even have to download Axis2 dist to build and deploy this sample. All you need to do is unzip the zip below and run

$ mvn install war:war

then rename the resultant war as axis2.war and drop it into any servlet engine. Once your servlet engine starts, you can view the wsdl for your service at:


Enjoy! Please drop an email to axis-dev@ws.apache.org if you run into problems or have comments.

Please download the entire zip here: book.zip