Setup of Web Services using Tomcat and SOAP (AXIS)
Setup of Axis
This document will describe Web Services using Apache Axis
and WSIF. The Axis tools will be used to create a web service on the server, and
WSIF will be used (in addition to Axis) on the client. Axis will be used to
generate the Java files that support SOAP as indicated below.
This
software does not make as lightweight clients as the NetDBLite example. This
client code is lighter on the client than the JBoss examples. This is not
extremely light because the client needs SOAP/XML software loaded to the client.
See the Tomcat
setup guide for more information about the tools, installation and extraction.
To setup Tomcat see WebTomcatSetup
. Download and extract Axis from Apache (I used version 1.0, rc2). Copy
the axis directory from the axis/webapps directory into the tomcat/webapps
directory.
Uncomment the servlet-mapping for AdminServlet in the
tomcat/webapps/WEB-INF/web.xml file. This makes the "Administer Axis" link work
correctly.
Make a source file with an interface. This
example uses mypackage.MyClass and mypackage.MyClassImpl. The Ant/Axis build
will use the interface file (MyClass) and create Java files to make a SOAP
messages.
Setup the Axis build
Define some information so that ant can run axis.
Add the following to the ant.properties file.
axis.home=d:/netdb/apache group/xml-axis-rc2
In Eclipse, under Window Preferences-Ant-Runtime, add a classpath to point
to the project's output build/classes folder. Add a classpath folder to point to
the axis/lib/jaxrpc.jar, wsdl4j.jar, commonslogging.jar, commonsdiscovery.jar,
saaj.jar, and axis.jar.
Add the following under the project element of
the build.xml file.
Make the tempsrc directory. Add the following under the prepare target.
<mkdir dir="${tempsrc.build}"/>
Clean the tempsrc directory. Add the folowing under the clean target.
<delete dir="${tempsrc.build}"/>
Make a target to create a WSDL file from the source Java interface files.
Add the following below the compile target of the build.xml. For some strange
reason, the output must start with "../" and not "./".
Compile the Java files that were created by the makeWSDLJava target. The
axis-wsdl2java Ant task will create an empty Impl (server side SOAP) file, which
we will overwrite before we compile. It is probably best if the axis-wsdl2java
task is used to create files in separate client and server directories, and not
to create the Impl files, but we haven't tried this yet.
We will have two deployment directories for this project. One will be the
project deployment directory and will contain the servlets, html, and jsp files.
The other will be for the web services and will be placed under the webapps/axis
directory. Add another property for the axis (web service) deployment.
Change the "dist" target "depends" clause to the following.
depends="prepare,compileWSDLJava,compile,jar
Copy the axis.jar, jaxrpc.jar, saaj.jar and commons-discovery.jar from
the axis lib to the NetDBSoap/lib directory. This contains the client web
service code. The copy can be put under the prepare target as shown below.
Remember to restart Tomcat after copying these jars.
Deploy the service to axis. Make a deploy.bat file like the following
and put into the webapps/axis directory.
@echo off
set AXIS_LIB=.\WEB-INF\lib
set CLASSPATH=%AXIS_LIB%\axis.jar
set CLASSPATH=%CLASSPATH%;%AXIS_LIB%\jaxrpc.jar
set CLASSPATH=%CLASSPATH%;%AXIS_LIB%\commons-discovery.jar
set CLASSPATH=%CLASSPATH%;%AXIS_LIB%\commons-logging.jar
set CLASSPATH=%CLASSPATH%;%AXIS_LIB%\saaj.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\common\lib\xerces.jar
java org.apache.axis.client.AdminClient %AXIS_LIB%\netdbsoap\deploy.wsdd
pause
The client java source may have to be compiled
separately from the server java, because the order of compilation may have to be
that the server client stubs are built before the client source is compiled. The
client code could be run from a jsp file, or from some client application. See
below for information about applets.
The client classes are generated
from the axis-wsdl2java element, and client code can use these classes and will
look something like the following.
MyClassServiceLocator mcsl = new MyClassServiceLocator();
server.netdbsoap.MyClass mc = rssl.getMyClass();
mc.myFunction();
Alternatively, the code can look something like the following.
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(
http://localhost:8080/axis/services/MyClass"));
call.setOperationName(new QName("netdbsoap.server", "myFunction"));
call.invoke(new Object[] {});
The client code can be put into a .jsp file. Then if this .jsp file is
referenced from the index.html file this link can be used to test. http://localhost:8080/NetDBSoap
Monitor the SOAP messages using the following link. This tool will not
work until it has been deployed, and your app deployment is modified (in
web.xml) to route messages. http://localhost:8080/axis/SOAPMonitor
Axis does not work well for applets or client beans because the jars are
large, and it will create security exceptions if the applet is not signed. It is
probably better to make an applet/servlet pair, where the servlet is the client
to the web server. The default policies for an unsigned applet will create an
exception of: org.apache.commons.logging.LogConfigurationException and
java.security.AccessControlException: access denied
(java.util.PropertyPermission org.apache.commons.discovery.log.level read).
Then also remember to add it to the <object codebase="..." > in the
jsp or html page. Also add all of the required axis client jars to the object
tag, and to a place accessible to the client in the Tomcat directories.
WSIF
It is possible to build client side software that work remotely or
locally without rewriting the client code. The Apache WSIF can use a protocol
such as SOAP, or call directly locally with Java code.
References
Using Axis with Ant -
http://nagoya.apache.org/wiki/apachewiki.cgi?AxisProjectPages/AxisAntTasks
Using Axis -
http://student.bii.a-star.edu.sg/~auyw/archive/webservice2.html
An Axis
plugin for Eclipse - http://www.improve-technologies.com/alpha/axis/