Tuesday, April 18, 2006

Some Apache Axis Notes

* Here are some of my notes while debugging an Axis service. I'm
editing them a bit to make them more general. Hopefully these
will be useful if you are looking for a quick guide.

* I realize you can do all of this with Maven or Ant, but
sometimes you just have to roll up your sleeves and do stuff
on the command line.

* Get a clean tomcat and install axis. I'm using Axis 1.3 for
historical reasons.

* You will need to get activation.jar to make axis happy.

* I'm also using Tomcat 5.5.12 and Java 1.5.

* I separated client and server code into separate directories. Here is the
file listing.

[gateway@gridfarm002 ws_GenericScript]$ ls -l
total 32
drwxr-xr-x 2 gateway gateway 4096 Apr 17 23:02 bin
drwxrwxr-x 3 gateway gateway 4096 Apr 18 11:03 client
-rw-r--r-- 1 gateway gateway 1765 Apr 18 11:01 deploy.wsdd
drwxrwxr-x 2 gateway gateway 4096 Apr 18 11:00 Junk
-rw-r--r-- 1 gateway gateway 169 Apr 17 22:59 README
drwxrwxr-x 3 gateway gateway 4096 Apr 18 11:05 server
-rw-r--r-- 1 gateway gateway 676 Apr 18 11:01 undeploy.wsdd
-rw-r--r-- 1 gateway gateway 2629 Apr 17 23:03 ws_generator.jar
[gateway@gridfarm002 ws_GenericScript]$

[gateway@gridfarm002 ws_GenericScript]$ pwd
[gateway@gridfarm002 ws_GenericScript]$ ls -l server/genericScript/
total 12
-rw-r--r-- 1 gateway gateway 5088 Apr 17 21:40 GenericScriptImpl.java
-rw-r--r-- 1 gateway gateway 125 Apr 17 14:36 GenericScript.java
[gateway@gridfarm002 ws_GenericScript]$

[gateway@gridfarm002 ws_GenericScript]$ ls -l client/genericScript/client/
total 4
-rw-r--r-- 1 gateway gateway 981 Apr 17 21:37 GenericScriptClient.java

* Copied activation.jar and the application specific
ws_generator.jar into axis/WEB-INF/lib

* Set my classpath to include the Axis jars and the ws_generator.jar:
export $TOMCAT_HOME=/path/to/tomcat/
export CP=`echo $TOMCAT_HOME/webapps/axis/WEB-INF/lib/*.jar | tr ' ' ':'

Note I don't use CATALINA_HOME since this will cause problems if set as environment
variable. Also, I use $CP instead of $CLASSAPTH to avoid CLASSPATH problems.

* I decided that the server code (GenericScriptImpl.java), needed some simple sanity
checking methods, so I added these:

public void emptyTest() {
System.out.println(this.toString()+" empty test called");

public String echoTest(String toEcho) {
System.out.println(this.toString()+" echo test called");
return toEcho;

* Compile the server code into axis. Make sure the classes directory exists.
javac -d $TOMCAT_HOME/webapps/axis/WEB-INF/classes/ -classpath $CP server/genericScript/*.java

* Start tomcat and deploy the service. I'm using the following simplified deploy.wsdd:

<deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/"
<service name="GenericScript" provider="java:RPC" >
<parameter name="className" value="genericScript.GenericScriptImpl" />
<parameter name="allowedMethods" value="*" />

* I use the following deploy command:
[gateway@gridfarm002 ws_GenericScript]$ java -classpath $AXIS_LIB org.apache.axis.client.AdminClient -lhttp://gf2.ucs.indiana.edu:8080/axis/services/GenericScript deploy.wsdd

* Pointed browser at the service lister to verify that the service was deployed:
http://gf2.ucs.indiana.edu:8080/axis/servlet/AxisServlet. This is linked from the
main Axis page: http://gf2.ucs.indiana.edu:8080/axis/.

* To undeploy the service, the simplest thing to do is shutdown tomcat, edit server-config.wsdd, and
cut out the service description for the no-longer-desired service. Then restart tomcat and
check the listings.


* Now we can turn to the client. We need to generate client stubs from the WSDL. I just downloaded
this from the Axis service for simplicity: http://gf2.ucs.indiana.edu:8080/axis/services/GenericScript?wsdl.
Saved this to a file. The UNIX wget method is useful here.

* I then executed the following command in the ws_GenericScript (i.e. main) directory.

java -classpath $CP org.apache.axis.wsdl.WSDL2Java -o ./client -p genericScript.ws GenericScript.wsdl

The -p option specifies the package/directory structure for the generated files and -o specifies
the directory where the stubs are coughed up.

* Now I compile the client and the client stubs. Compile the stubs first and then compile the client.
Here is the command for compiling the client:

javac -d /tmp/ -classpath $CP client/genericScript/ws/*.java

Note I'm putting these in the /tmp/ directory. This is just to keep it separate from the service

* I next compiled the client application that uses the stubs. I used this command:
javac -d /tmp/ -classpath $CP:/tmp/ client/genericScript/client/*.java

* Note the key parts of the client application are these:

String theUrl="http://path/to/service/";
genericScript.ws.GenericScriptImplService eosService=
new genericScript.ws.GenericScriptImplServiceLocator();
genericScript.ws.GenericScriptImpl eos=
eosService.getGenericScript(new URL(theUrl));

No comments: