Search This Blog

Tuesday, January 26, 2010

Web Service with Tomcat

//with tomcat


software

*****************************************************************

1. axis2.war from [ axis2-1.5.1-war.zip ] deploy into tomcat

2. axis2-1.5.1-bin.zip extract into d:\axis2-1.5.1-bin

3. set environment


AXIS2_HOME=d:\axis2-1.5.1-bin

PATH=d:\axis2-1.5.1-bin\bin;

CLASS_PATH=d:\axis2-1.5.1-bin\lib\*

TOMCAT_HOME=d:\tomcat6.0


*****************************************************************





1. service program

~~~~~~~~~~~~~~~~~~~~~~~~~~~


d:\temp\aaxis\com\abi> edit HelloWorld.java


package com.abi;

public class HelloWorld {

public String sayHello(String name) {

return "Hello " + name;

}

}



2. services.xml

~~~~~~~~~~~~~~~~~~~~~~~~~~~


d:\temp\aaxis\META-INF> edit services.xml


<service>
   <description>
      This is my first service, which says hello
   </description>
   <parameter name="ServiceClass">com.abi.HelloWorld</parameter>
   <operation name="sayHello">
      <messageReceiver
      class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
   </operation>
</service>







3. D:\temp\aaxis> jar cvf HelloWorld.aar *
~~~~~~~~~~~~~~~~~~~~~~~~~~~

4. copy that HelloWorld.aar into tomcat/webapps/axis2/WEB-INF/services

5. restart tomcat

6. http://localhost:8080/axis2/

7. http://localhost:8080/axis2/services/listServices

8. http://localhost:8080/axis2/services/HelloWorld?wsdl //copy this url

9. D:\temp\aaxis>wsdl2java -uri http://localhost:8080/axis2/services/HelloWorld?wsdl -o client

10. write client program
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

d:\temp\aaxis\client\src\com\abi> edit Test.java

package com.abi;
import com.abi.*;
import com.abi.HelloWorldStub.SayHello;
public class Test {
public static void main(String[] args) throws Exception {
HelloWorldStub stub = new HelloWorldStub();
//Create the request

com.abi.HelloWorldStub.SayHello request = new com.abi.HelloWorldStub.SayHello();

request.setArgs0("vijay Kumar");
//Invoke the service
com.abi.HelloWorldStub.SayHelloResponse response = stub.sayHello(request);
System.out.println("Response : " + response.get_return());
}
}


11. compile with auto generate ant via wsdl2java tool
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


D:\temp\aaxis\client> ant
OR
(manual) D:\temp\aaxis>edit build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="antwsdl2java" default="gen" basedir=".">
<path id="axis2.classpath">
<fileset dir="D:/temp/axis2">
  <include name="**/*.jar" />
  </fileset>
  </path>
<target name="gen">
  <taskdef name="axis2-wsdl2java" classname="org.apache.axis2.tool.ant.AntCodegenTask" classpathref="axis2.classpath" />
  <axis2-wsdl2java wsdlfilename="http://localhost:8080/axis2/services/HelloWorld?wsdl" output="d:/temp/aaxis" />
  </target>
  </project>



// RUN Manual Script and write the client program and then do steps for execute
D:\temp\aaxis> ant

12. //Execute the client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

D:\temp\aaxis\build\classes>java -Djava.ext.dirs=D:/axis2-1.5.1/lib/ com.abi.Test

No comments:

Hit Counter


View My Stats