Home

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.

Start Tomcat and run http://127.0.0.1:8080/axis/ to test.

Make some Java source code

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.
  <path id="axis.classpath"> <fileset dir="${axis.home}/lib">
    <include name="**/*.jar" /></fileset>
  </path>
  <taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
Make a tempsrc directory for intermediate files.
  <property name="build.home"     value="build"/>
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 "./".
  <target name = "makeWSDL" depends="compile">
    <axis-java2wsdl classname = "mypackage.MyClass"
    location="http://localhost:8080/axis/services/MyClass"
    namespace="netdbsoap.server"
    output="../${app.name}/${build.home}/myclass.wsdl"/>
  </target>
Make a target to create some Java client and server stub files source from the WSDL file. Add the following below the makeWSDL target.
  <target name="makeWSDLJava" depends="makeWSDL">
    <axis-wsdl2java output="${tempsrc.build}"
    	deployscope="Session" serverside="true"
	verbose="true" url="../${app.name}/${build.home}/myclass.wsdl" >
    	<mapping namespace="http://axis.apache.org/ns/interop" package="interop" />
    </axis-wsdl2java>
  </target>
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.
  <!-- Copy our Impl file over the wsdl2java impl file. --> 
  <delete dir="${tempsrc.build}/server/netdbsoap" includes="*Impl.java"/>
  <copy todir="${tempsrc.build}/server/netdbsoap">
    	<fileset dir="src/server/netdbsoap"/></copy>
  <target name="compileWSDLJava" depends="makeWSDLJava">
    <javac srcdir="${tempsrc.build}" destdir="${build.classes}"
           classpath="${build.classes}"
           debug="on" optimize="off" deprecation="off"/>
  </target>
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.
  <property name="deploy.axis" value="${tomcat.home}/webapps/axis"/>
Change the "dist" target to copy some classes to both the deploy.home and deploy.axis.
    <copy todir="${deploy.axis}/WEB-INF/classes/netdbsoap/server">
    	<fileset dir="${build.classes}/netdbsoap/server"/></copy>
    <copy todir="${deploy.axis}/WEB-INF/classes/server">
    	<fileset dir="${build.classes}/server"/></copy>
    <copy todir="${deploy.axis}/WEB-INF/classes/server/netdbsoap">
    	<fileset dir="${tempsrc.build}/server/netdbsoap/"
	includes="*.wsdd"/></copy>
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.
    <copy todir="${deploy.home}/WEB-INF/lib">
    	<fileset dir="${deploy.axis}/WEB-INF/lib"/></copy>

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


Test using the following link: http://127.0.0.1:8080/axis/services/MyClass
To see the SOAP message information use the following link. http://127.0.0.1:8080/axis/services/MyClass?wsdl

Writing Client Code

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).

A small soap library for applets is available here. http://www.extreme.indiana.edu/xgws/xsoap

If you want to use the client classes from an applet or bean on the client, then it is best to package it into a jar like the following.
   <jar jarfile="${build.lib}/RackService.jar">
      <fileset dir="${build.classes}" includes="server/netdbsoap/*" />
   </jar>
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/ 1
Hosted by www.Geocities.ws