Top Navigation
Show Content

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

A: Let's try and deploy an Axis2 based simple web service in our own custom webapp. The first thing we need is an entry for the Axis2 Servlet in our web.xml. See snippet below for such an entry and a mapping for the url as well.

<web-app>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>
org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
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.
<serviceGroup>
<service name="BookService"
targetNamespace="http://ws.apache.org/axis2/samples/book/">
<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>
<operation name="findBook">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
</service>
</serviceGroup>
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-INF
| web.xml
|
\---services
\---BookService
\---META-INF
services.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.
\---book
| pom.xml
| README
|
\---src
+---main
| | log4j.properties
| |
| \---samples
| \---demo
| Book.java
| BookService.java
|
+---test
\---webapp
\---WEB-INF
| web.xml
|
\---services
\---BookService
\---META-INF
services.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:
http://yourhost:port/axis2/services/BookService?wsdl

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Very helpful, thanks

This is one of the most useful articles I've seen here, not least because of the provision of a Maven2 POM which helps get all the dependencies in place. Also, it's very concise, heavy on example code, and above all it works!

Weblogic 8.1SP4

I tried your sample and it does not work!

I tried also with axis1.1.1 and the services and modules list are empty!

The only way I succeed to have embeded services is to place the services.xml directly in the WEB-INF directory. But I Axis2 is unbale to load the services and modules respectively from the WEB-INF/services and WEB-INF/modules. I tried to explode also the aar and the mar with the same result. the other problem is that when I use the ?wsd parameter on the service, I obtain an error telling to put the wsdl in the META-INF and it is the case!

Did someone succed in deploying the axis2 engine with embeded new service from a war file (not exploded) in Weblogic 8.1?

This post actually save me

This post actually save me $50. I was supposed to hire a programmer to do this on my website until I found this tutorial on Google. Thank you sir.

Drug Detox

Does not work

I spend the whole day getting this to work, But it did not. Any ideas? DS Downloads

Embedding multiple WS?

Could you please also explain the layout, especially regarding services.xml location, for a case where there's a service group containig multiple services. I have to expose several classes in an existing application as webservices; it would be most convenient to keep corresponding services separately.

 Thank you,
Alex.

I did actually see something

I did actually see something about this somewhere. It made a lot of sense to me then, especiall in relation to a gotomypc promo code limit.

How to Embed an Axis2 based

Hi Dims,

 

This is very nice and usefule article . But i am not able to download book.zip. Could you send me the book.zip? Thanks.

 

Hailong

Oops!

Looks like the url got moved. try this one for now till we fix the file location on the server-side. <br>

http://wso2.org/article-old/book.zip

Still no book.zip

Hi,

I still can't get the example.

I can download the book.zip file from the article but it only contains META-INF/Manifest file.

I tried to download the zip from that other link, but I get a 404 Not Found page. :(

How to Embed an Axis2 based

I found the next problem when I access to
http://localhost:5800/axis2/services/BookService

problem: Please enable REST support in WEB-INF/conf/axis2.xml and WEB-INF/web.xml

I don't know what it means, somebody can help me please

Sotes

Deployment Problem

Hi guys,

when I feed my tomcat (5.5.20) with the successfully build war from the book.zip I get following error:

Jul 27, 2007 1:30:29 PM org.apache.axis2.deployment.ServiceBuilder populateService
SEVERE: Error in schema generating samples.demo.BookService
java.lang.ClassNotFoundException: samples.demo.BookService
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at org.apache.ws.java2wsdl.SchemaGenerator.(SchemaGenerator.java:70)
at org.apache.axis2.deployment.util.Utils.fillAxisService(Utils.java:209)
at org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:149)
at org.apache.axis2.deployment.ServiceGroupBuilder.populateServiceGroup(ServiceGroupBuilder.java:91)
at org.apache.axis2.deployment.repository.util.ArchiveReader.buildServiceGroup(ArchiveReader.java:84)
at org.apache.axis2.deployment.repository.util.ArchiveReader.processServiceGroup(ArchiveReader.java:145)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:620)
at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:195)
at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:207)
at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:155)
at org.apache.axis2.deployment.DeploymentEngine.loadServices(DeploymentEngine.java:91)
at org.apache.axis2.deployment.WarBasedAxisConfigurator.loadServices(WarBasedAxisConfigurator.java:142)
...

Any ideas?

Cheers,
Dirk

This worked for me too.

This worked for me too (Axis2 1.3, Tomcat 5.5.23). The jars went to webapp's lib directory. Now it's fully spring loaded. Thanks.

I tried a similar excersize with CXF and did not have much luck based on their documentation. The sad part is that there isn't as much following to that project as there is after Axis2. It makes it hard locating other working examples of the basic setup.

 

class not found error

the problem is axis can't found the service class BookService, check the ubication of the file

 

Sotes

Undeploying, hot deploying embedded Axis2 service

What's up with Axis2 classloader? When i undeploy my webapp, the jars stick around, and hence a full undeployment doesn't occur. A redeployment can't occur after that either. I end up recycling the server. Any possible programmatic work around? Am i supposed to do some classloading trick...something was mentioned on Axis2's website about that when running "inside the aar".

 

Rename axis2.war ?

Hi! Great tutorial!
I managed to create the "axis2.war" and it runs perfectly.
But now I want to rename it - say into "book.war". When I do so I can address the wsdl at "http://yourhost:port/book/services/BookService?wsdl".

So far so good- but how can I make Axis to generate in the wsdl the endpoints correctly? These unfortunately stay at:

soap:address location="http://yourhost:port/axis2/services/BookService" .

Many thanks in advance!

Best,
George

Jsp problem

I followed the instructions in this, and I get:

 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: File "/axis2-web/listSingleService.jsp" not found
org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:111)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

javax.servlet.ServletException: File "/axis2-web/listSingleService.jsp" not found
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.axis2.transport.http.AbstractAgent.renderView(AbstractAgent.java:116)
org.apache.axis2.transport.http.ListingAgent.processListService(ListingAgent.java:197)
org.apache.axis2.transport.http.ListingAgent.handle(ListingAgent.java:89)
org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:109)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 
 

I also get this when trying with a maven-less build. I understand that the jsps are missing, but why, shouldn't maven have magically included them?

 

Also, I tried adding them manually to my alternative, non-maven try and that did not seem to help. I saw a reference saying I should simply add the axis2-web folder under my WEB-INF.

Did you ever solved this problem?

Hello!
I just wonder if you ever solved this problem?
If you solved it how did you do it?

Best regards
Fredrik

Axis2 1.3 compatible with WebSphere 6.0.2.x?

 

 
Hello,
            Is Axis2 1.3 compatible with WebSphere 6.0.2.x?  I found an example, http://wso2.org/library/90 , which works like a champ on Tomcat 5.5 where I can deploy it and hit the wsdl.  The problem is trying to hit the wsdl with WebSphere 6.0.2.x, I just get a 404.  I have looked at the server logs and it starts fine with no errors.  The only suspicious entries in the log are
 
[3/26/08 16:42:55:934 EDT] 00000021 ApplicationMg A   WSVR0200I: Starting application: axis2_war
[3/26/08 16:42:56:293 EDT] 00000021 WebGroup      A   SRVE0169I: Loading Web Module: axis2.war.
[3/26/08 16:42:57:527 EDT] 00000021 DeploymentEng I org.apache.axis2.deployment.DeploymentEngine prepareRepository no modules directory found , new one created
[3/26/08 16:42:57:871 EDT] 00000021 SystemOut     O [JAM] Warning: You are running under a pre-1.5 JDK.  JSR175-style source annotations will not be available
[3/26/08 16:42:58:043 EDT] 00000021 ServletWrappe A   SRVE0242I: [axis2_war] [/axis2] [AxisServlet]: Initialization successful.
[3/26/08 16:42:58:059 EDT] 00000021 VirtualHost   I   SRVE0250I: Web Module <null> has been bound to default_host[*:9080,*:80,*:9443].
[3/26/08 16:42:58:074 EDT] 00000021 ApplicationMg A   WSVR0221I: Application started: axis2_war
 
Any help or information would be greatly appreciated

Same problem using WebSphere 5.1

Hi nas7,

I have the exact the same problem, only using the WebSphere 5.1.
Did you find a solution? If so could you reply. I will try the same than.

Any help is welcome from other users.

Kind Regards,

Tuno

I keep having issues too, no

I keep having issues too, no matter what I try I keep getting errors popping up. I have been trying to get it working for a couple days now... might have to end up hiring some computer whiz to do it pretty soon

Jack, non chexsystems banks

jsp problem

hi

i am getting same error what is solution of this error

Does not work on OC4J either

I am trying to deploy the book.zip on an OC4J (10.1.3.1) container. After building it successfully, I deploy it. The OC4J container says deployment went fine. But when I access the wsdl mentioned above I get the 404- /axis2/services/BookService not found Error. It looks like OC4j is trying to look for a listServices.jsp file and of course it is not there? Why would this happen and I how would I fix it? Any suggestions?

Can you give me some more guidance on this topic?

Hi,

Thanks for this great and useful article.

Recently I need to add a SOAP server service using Axis2 to my web application.
I think the approach mentioned in your article is what I need, but I don't understand it very well.
Would you be so kind to give me some guidance?

My questions are.

1. Are those mentioned in yoru article the only things need to be done to embed Axis2 to my web applicaiton?
2. Since I'm adding a SOAP server serivce, is there anything more I should do?
For example, where to define the SOAPAction etc.?
3. There is a command '$ mvn install war:war' to build the war file.
I'm using Windows XP, can I do the same thing?

I'm a newbie on Axis. I'd really appreciate it if you can elaborate more on this topic.

thansk in advance,

-Tian Chi

Regarding these examples

and many more

I am able to run these examples and get to

http://yourhost:port/axis2/services/BookService?wsdl

but what do I need to do in order to get to:

http://yourhost:port/axis2/services/BookService/getBooks

or
http://yourhost:port/axis2/services/BookService/findBook?isbn="test"

Thanks.

Thanks, very powerfull article.

I spent few hours for searching some good articles about Spring + Maven + Webservice, and finally I have founded it here.
Thanks a lot.

What is your solution? I

What is your solution? I still don't have one.
Thanks
- James @ auto insurance quotes

Why Can I not see my custom web service listed from Axis2 Admin

I am using the link for learning:

https://www.wso2.org/library/90

Why can I not see getBooks and findBooks method of my new service (BookService) in the url above?

Ax2
|
---src
|
---samples.demo
|
---Book.java
----BookService.java
WebContent
|
----WEB-INF
|
---lib (has all jars from Axis 2)
|
----services
|
----BookService
|
----META-INF
|
---services.xml

///////////////////
package samples.demo;

public class Book {
private String title;
private String isbn;
private String author;

public String getIsbn() {
return isbn;
}

public void setIsbn(String isbn) {
this.isbn = isbn;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}
}
///////////////////
package samples.demo;

public class BookService {
private Book onlyBook;

public BookService() {
onlyBook = new Book();
onlyBook.setAuthor("Dan Diephouse");
onlyBook.setTitle("Using Axis2");
onlyBook.setIsbn("0123456789");
}

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

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

return null;
}
}
////////////////
services.xml

Book sample service

samples.demo.BookService

/////////////////////////
web.xml

<?xml version="1.0" encoding="UTF-8"?>

Axis2WebWs

Apache-Axis Servlet
AxisServlet
org.apache.axis2.transport.http.AxisServlet
1

AxisServlet
/servlet/AxisServlet

AxisServlet
*.jws

AxisServlet
/services/*

/////////////////

I have successfully deployed axis2.war. I can successfully see:

http://localhost:9081/axis2/services/listServices

which only shows getVersion

My question:

Why can I not see getBooks and findBooks method of my new service (BookService) in the url above?

I can successfully see WSDL under:

http://localhost:9081/Ax2/services/BookService?wsdl

Axis 2 service deploy

Hi,

i need a help on how to deploy services as a separate war file.

I am working on web application. i am going to write few services with in this web application.

can i include these service files(class files and service.xml) to the existing web application war file?

I dont want to use axis2/services in the below url.

http://localhost:9081/axis2/services/listServices

I want service url like below.

http://localhost:8080/api_commercialization-1.0.0.0/soap/DocDelivery?WSDL

is it possible to cretae like above?

if possible could you please help me how to achive this..

thanks in advance

Regards,
chinna

Technology News

Technology News

Thanks for this, although html language is bit confusing. You explained so well.

Deploying .aar with EJB .jar in Glassfish

Hi All!

Thanx for the tutorial, it is really helpful.

However I cannot solve a problem with the help of it. I am new to Axis2 and I want to deploy my webservice in glassfish. My problem is that from my webservice I would like to call an EJB class, so if I uderstood it right, I should deploy my webservice with this jar file somehow (or in it?). The whole application (consists of more war files) is in an ear file.

Could you, please, explain, how I can deploy my .aar in/with a .jar? (I did not find any help on the matter)

Thank you really much in advance!

Regards,
Anna

Thank you for such a nice site with good ideas:

Best wii fit games playable at
wii fit games have some fun with wii ,
if you really need to lookup for number at
duns number lookup can
help you in lookup task for sure , but for sure you need some good school
sonography schools this
school is the best I think , and you can watch your new
lcd with
lcd tv wall mount
while mounting them to your wall to watch lcd tv.

example works, but i 'can't get original wsdl (1.1)

i've been using this approach with a service for over a year and it works great (on Tomcat, WebSphere, and Weblogic) - except that i can't get the original wsdl.

i can reach my app via http://myhostname/myapp/services/myservice

i want to get the original wsdl from http://myhostname/myapp/services/myservice?wsdl

at present, invoking this url in a web browser produces this message:

"Unable to generate WSDL 1.1 for this service. If you wish Axis2 to automatically generate the WSDL 1.1, then please +set useOriginalwsdl as false in your services.xml"

invoking http://myhostname/myapp/services/myservice?wsdl2 succeeds, but i need to return the 1.1 wsdl.
in Tomcat, he original wsdl file is deployed to .../tomcat/webapps/myapp/WEB-INF/services/myapp/myservice/META-INF

i've searched online and found 2 hints:

1) in services.xml, set both "useOriginalwsdl" and "modifyUserWSDLPortAddress" to true.
This doesn't work. When i invoke http://myhostname/myapp/services/myservice?wsdl i get the error mentioned above.

If i set "useOriginalwsdl" to false, i get a wsdl but it doesn't match the original closely enough to be useful for dynamic clients.

2) add a file named "wsdl.list" containing the name of the wsdl file to META-INF.
This makes no difference.

Any ideas most appreciated!

Same problem here

I've had the same problem and tried all the above but had no result. The only difference is that I was trying to deploy on a Weblogic with the axis servlet...

Eventually I gived up and if needed the WSDL is sent via e-mail :( (Yes, I know: lame!)

I would also much appreciate any ideas or comments on how to make this work...

Thanks.

FIXED (was example works, but i 'can't get original wsdl (1.1))

A bit more digging through the Axis2 user list mail archives did the trick:

The value of the "name" attribute of the "service" tag in the wsdl file MUST match the same tag/attribute in the wsdl file.

e.g., both must be <service name="myService">

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.