Creating an axis webservice


Pre-Requisites
1) Tomcat 5.0
2) Apache axis 1.4
3) jdk 1.4.2

Copy the axis folder (inside D:\axis-1_4\webapps) into Tomcat webapps folder.

1) Create a simple java program
package com.samples.webservice;

class HelloWorld
{
public String displayName(String name) {
return “Hello ” + name;
}
}

2) Copy the class file along with the package structure into D:\Tomcat 5.0\webapps\axis\WEB-INF\classes folder.

3) Create a WSDD file – deploy.wsdd

3) Deploy it as a web Service
java -classpath E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\mail.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\
commons-logging-1.0.4.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\
lib\commons-discovery-0.2.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\
lib\saaj.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\activation.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\activation-1.1.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\mailapi_1_3_1.jar org.apache.axis.client.AdminClient deploy.wsdd

4) Access the service by using the url http://localhost:8080/axis/services/HelloWorld

5)Create a client program to access this service
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;

public class HelloWorldClient {
public static void main(String [] args) {
try {
String endpoint =
http://localhost:8080/axis/services/HelloWorld”;

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName( “displayName” );
call.addParameter( “op1”, XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType( XMLType.XSD_STRING );
String ret = (String) call.invoke( new Object[] { “Srikant !!” } );
System.out.println(“Sent ‘Srikant !!’, got ‘” + ret + “‘”);
} catch (Exception e) {
System.err.println(e.toString());
}
}
}

Compile it using —–
javac -classpath E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar HelloWorldClient.java

Run the program using —–
java -cp .;E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-logging-1.0.4.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-discovery-0.2.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\saaj.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\activation.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\mailapi_1_3_1.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\wsdl4j-1.5.1.jar HelloWorldClient

6) To generate Client program using WSDL File
a) java -cp .;E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-logging-1.0.4.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-discovery-0.2.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\saaj.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\activation.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\mailapi_1_3_1.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\wsdl4j-1.5.1.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\endorsed\xercesImpl-2.6.2.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\endorsed\xml-apis-2.6.2.jar org.apache.axis.wsdl.WSDL2Java testsap.wsdl

b) Compile the generated classes.

c) Write a standalone java file to invoke the client as follows

class TestHelloWorld
{
public static void main(String[] args)
{
try
{
System.out.println(“Hello World Starts!”);
helloworld.HelloWorldService hws = new helloworld.HelloWorldServiceLocator();
helloworld.HelloWorld hw = hws.getHelloWorld();
hw.displayName(“Srikant……..”);
System.out.println(“Hello World Ends!”);
}
catch (java.rmi.RemoteException rmiEx)
{
System.out.println(“RMI Exception is :: ” + rmiEx.getMessage());
}
catch (javax.xml.rpc.ServiceException serEx)
{
System.out.println(“Service Exception is :: ” + serEx.getMessage());
}
}
}

Compile this file :: javac -classpath .;./helloworld;E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar TestHelloWorld.java

d) Run this file
java -cp .;E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-logging-1.0.4.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-discovery-0.2.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\saaj.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\activation.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\mailapi_1_3_1.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\wsdl4j-1.5.1.jar TestHelloWorld

7) To generate WSDL file from a deployed service
java -cp .;E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\axis.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\jaxrpc.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-logging-1.0.4.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\commons-discovery-0.2.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\saaj.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\activation.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\mailapi_1_3_1.jar;
E:\Softwares\servers\apache-tomcat-5.5.25\webapps\axis\WEB-INF\lib\wsdl4j-1.5.1.jar org.apache.axis.wsdl.Java2WSDL -o helloworld.wsdl -l http://localhost:8080/axis/services/HelloWorld -n “urn:helloworld” -p”com.samples.webservice” “urn:helloworld” com.samples.webservice.HelloWorld

********************************************************************************************************
java -classpath D:\Dumps\Software\axis-1_4\lib\axis.jar;
D:\Dumps\Software\axis-1_4\lib\jaxrpc.jar;
D:\Dumps\Software\axis-1_4\lib\commons-logging-1.0.4.jar;
D:\Dumps\Software\axis-1_4\lib\commons-discovery-0.2.jar;
D:\Dumps\Software\axis-1_4\lib\saaj.jar;
D:\Dumps\Software\axis-1_4\lib\activation.jar;
D:\Dumps\Software\axis-1_4\lib\mailapi_1_3_1.jar;
D:\Dumps\Software\axis-1_4\lib\endorsed\xml-apis-2.6.2.jar;
D:\Dumps\Software\axis-1_4\lib\endorsed\xercesImpl-2.6.2.jar org.apache.axis.client.AdminClient deploy.wsdd

D:\Dumps\Software\axis-1_4\lib

java -cp .;D:\Dumps\Software\axis-1_4\lib\axis.jar;
D:\Dumps\Software\axis-1_4\lib\jaxrpc.jar;
D:\Dumps\Software\axis-1_4\lib\commons-logging-1.0.4.jar;
D:\Dumps\Software\axis-1_4\lib\commons-discovery-0.2.jar;
D:\Dumps\Software\axis-1_4\lib\saaj.jar;
D:\Dumps\Software\axis-1_4\lib\activation.jar;
D:\Dumps\Software\axis-1_4\lib\mailapi_1_3_1.jar;
D:\Dumps\Software\axis-1_4\lib\wsdl4j-1.5.1.jar;
D:\Dumps\Software\axis-1_4\lib\endorsed\xml-apis-2.6.2.jar;
D:\Dumps\Software\axis-1_4\lib\endorsed\xercesImpl-2.6.2.jar org.apache.axis.wsdl.Java2WSDL -o cureservice.wsdl -l http://localhost:8080/axis/services/CUREWebService -n “urn:CUREWebService” -p”com.cadence.cure.webservice” “urn:CUREWebService” com.cadence.cure.webservice.CUREWebService

java -cp .;D:\Dumps\Software\axis-1_4\lib\axis.jar;
D:\Dumps\Software\axis-1_4\lib\jaxrpc.jar;
D:\Dumps\Software\axis-1_4\lib\commons-logging-1.0.4.jar;
D:\Dumps\Software\axis-1_4\lib\commons-discovery-0.2.jar;
D:\Dumps\Software\axis-1_4\lib\saaj.jar;
D:\Dumps\Software\axis-1_4\lib\activation.jar;
D:\Dumps\Software\axis-1_4\lib\mailapi_1_3_1.jar;
D:\Dumps\Software\axis-1_4\lib\wsdl4j-1.5.1.jar;
D:\Dumps\Software\axis-1_4\lib\endorsed\xercesImpl-2.6.2.jar;
D:\Dumps\Software\axis-1_4\lib\endorsed\xml-apis-2.6.2.jar org.apache.axis.wsdl.WSDL2Java cureservice.wsdl

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s