How to Embed an Axis2 based Web Service in your Webapp?
Submitted on May 17, 2006 - 05:17. Story : Project :
Q: 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>Next, We need a simple web service. Let's pick a Book service with 2 operations findBook and getBooks Snippet from BookService.java:
<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>
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>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:
<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>
\---WEB-INFUsually 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.
| web.xml
|
\---services
\---BookService
\---META-INF
services.xml
\---bookAll 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
| 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
$ mvn install war:warthen 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
(1 vote)
»
- Login or register to post comments
- Printer friendly version
- 22402 reads
Tag Cloud
Apache Rampart
Apache Synapse
Axis2
Axis2
Axis2/C
Rampart/C
Axis2/C
WSF/C
data services
ESB
ESB
Identity Solution
Rampart/Java
Sandesha2/Java
Synapse/Java
Axis2/Java
ESB/Java
AXIOM/Java
WSAS/Java
Mashup Server
Mule
OpenID
open source
PHP
WSF/PHP
POJO
Proxy Services
rampart
Rampart
Registry
REST
Sandesha2
security
SOA
soap
Spring
Synapse
Synapse
Training
webinar
Web Services
WS-Security
WSAS
WSAS
wsdl
wsf
WSF/C
WSF/PHP
WSO2
WSO2 WSF/PHP











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?
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.
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!
http://wso2.org/article-old/book.zip
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
root cause
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.
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
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?