Creating an axis webservice

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_4webapps) 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.0webappsaxisWEB-INFclasses folder.

3) Create a WSDD file – deploy.wsdd

3) Deploy it as a web Service
java -classpath E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibmail.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlib
commons-logging-1.0.4.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INF
libcommons-discovery-0.2.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INF
libsaaj.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibactivation.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibactivation-1.1.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibmailapi_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:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar HelloWorldClient.java

Run the program using —–
java -cp .;E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-logging-1.0.4.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-discovery-0.2.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibsaaj.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibactivation.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibmailapi_1_3_1.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibwsdl4j-1.5.1.jar HelloWorldClient

6) To generate Client program using WSDL File
a) java -cp .;E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-logging-1.0.4.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-discovery-0.2.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibsaaj.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibactivation.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibmailapi_1_3_1.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibwsdl4j-1.5.1.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibendorsedxercesImpl-2.6.2.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibendorsedxml-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:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar TestHelloWorld.java

d) Run this file
java -cp .;E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-logging-1.0.4.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-discovery-0.2.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibsaaj.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibactivation.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibmailapi_1_3_1.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibwsdl4j-1.5.1.jar TestHelloWorld

7) To generate WSDL file from a deployed service
java -cp .;E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibaxis.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibjaxrpc.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-logging-1.0.4.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibcommons-discovery-0.2.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibsaaj.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibactivation.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibmailapi_1_3_1.jar;
E:Softwaresserversapache-tomcat-5.5.25webappsaxisWEB-INFlibwsdl4j-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:DumpsSoftwareaxis-1_4libaxis.jar;
D:DumpsSoftwareaxis-1_4libjaxrpc.jar;
D:DumpsSoftwareaxis-1_4libcommons-logging-1.0.4.jar;
D:DumpsSoftwareaxis-1_4libcommons-discovery-0.2.jar;
D:DumpsSoftwareaxis-1_4libsaaj.jar;
D:DumpsSoftwareaxis-1_4libactivation.jar;
D:DumpsSoftwareaxis-1_4libmailapi_1_3_1.jar;
D:DumpsSoftwareaxis-1_4libendorsedxml-apis-2.6.2.jar;
D:DumpsSoftwareaxis-1_4libendorsedxercesImpl-2.6.2.jar org.apache.axis.client.AdminClient deploy.wsdd

D:DumpsSoftwareaxis-1_4lib

java -cp .;D:DumpsSoftwareaxis-1_4libaxis.jar;
D:DumpsSoftwareaxis-1_4libjaxrpc.jar;
D:DumpsSoftwareaxis-1_4libcommons-logging-1.0.4.jar;
D:DumpsSoftwareaxis-1_4libcommons-discovery-0.2.jar;
D:DumpsSoftwareaxis-1_4libsaaj.jar;
D:DumpsSoftwareaxis-1_4libactivation.jar;
D:DumpsSoftwareaxis-1_4libmailapi_1_3_1.jar;
D:DumpsSoftwareaxis-1_4libwsdl4j-1.5.1.jar;
D:DumpsSoftwareaxis-1_4libendorsedxml-apis-2.6.2.jar;
D:DumpsSoftwareaxis-1_4libendorsedxercesImpl-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:DumpsSoftwareaxis-1_4libaxis.jar;
D:DumpsSoftwareaxis-1_4libjaxrpc.jar;
D:DumpsSoftwareaxis-1_4libcommons-logging-1.0.4.jar;
D:DumpsSoftwareaxis-1_4libcommons-discovery-0.2.jar;
D:DumpsSoftwareaxis-1_4libsaaj.jar;
D:DumpsSoftwareaxis-1_4libactivation.jar;
D:DumpsSoftwareaxis-1_4libmailapi_1_3_1.jar;
D:DumpsSoftwareaxis-1_4libwsdl4j-1.5.1.jar;
D:DumpsSoftwareaxis-1_4libendorsedxercesImpl-2.6.2.jar;
D:DumpsSoftwareaxis-1_4libendorsedxml-apis-2.6.2.jar org.apache.axis.wsdl.WSDL2Java cureservice.wsdl

Post Tagged with

Leave a Reply

Your email address will not be published. Required fields are marked *