Powered By Blogger

05 April, 2007

How to make Web Service with Axis 1.4 + Tomcat

I searched and searched and searched and when at last I couldn't find a good tutorial for this topic...I decided to read the manual and try some bit of fun myself making web services with Axis.
and I was thrilled to see that it was actually pretty simple so...I am gonna put it down here to be inscribed on the web world for posterity (atleast till the blogger.com server doesnt crash or something! :))

Anyways...
(Hopefully the setup is done...with Apache Axis and Tomcat)

Step 1: Make the simple server side program .java file.
It shd have the method that the client will call.

Lets say for example:


public class MyServerClass{

String MyServerMethod(String a){

System.out.println("Request Recieved");
return a+" ,this is what the client sent";

}
}


Now next step would be to compile it; a simple ' javac MyServerClass.java'.
The .class file that is generated...just put it in the Apache Tomcat - > webapps -> Axis ->web-inf->classes folder.


Impt to note: If you have put the class into a package then make sure u make the package in the classes folder before putting the .class file in it.

example:
package abc.cde.efg
public class MyServerClass{ ....

Then put the MyServerClass.class file that is generated on compilation into the
Apache Tomcat - > webapps -> Axis ->web-inf->classes ->abc->cde->efg folder. Make the 3 folders and then put the .class into the efg folder.

Step 1.5 : This is just a check
Hope the library of the Axis -> web-inf has the axis.jar etc jar files in it already!
If not best to goto axishomepage
and download the needed jars.

Step 2: Next thing to be done...
Deploying the web service on the Apache Tomcat Web Server.
We need to write the .wsdd file for this. The Web Service Deployment Descriptor is written in xml format. Its pretty easy.... you could have a look at the wsdd in this blog found it pretty good!

The things you need to modify in your wsdd would be
the service name
class Name

write it directly into a file called "deploy.wsdd"
Impt: If you have put ur class into a package make sure your
MyServerClass is changed to abc.cde.efg.MyServerClass in the className.

Now...the next thing to do is...
STARTUP the TOMCAT server!

make a .bat file in notepad and put in the following
java -cp c:\axis\lib\axis.jar;c:\axis\lib\saaj.jar;c:\axis\lib\xerces.jar;c:\axis\lib\activation.jar;c:\axis\lib\axis-ant.jar;c:\axis\lib\commons-discovery-0.2.jar;c:\axis\lib\commons-logging-1.0.4.jar;c:\axis\lib\jaxrpc.jar;c:\axis\lib\xercesImpl.jar;c:\axis\lib\xml-apis.jar;c:\axis\lib\wsdl4j-1.5.1.jar;c:\axis\lib\mailapi_1_3_1.jar;c:\axis\lib\javax.jms.jar;c:\axis\lib\log4j-1.2.8.jar org.apache.axis.client.AdminClient -lhttp://localhost/axis/services/AdminService deploy.wsdd

Dont change the other part just edit the name of your file if you have saved it different from deploy.wsdd.

Make sure you are in the folder where deploy.wsdd is present when you run the .bat file.

Step3:
Ok...now that this is done...

goto...http://localhost/axis/
and click on the List ...it will show you all the deployed web services!!

You can now make a simple client for this web service ...

Congrats! you now have an up and running webservice. *hurray!*

No comments: