http://in.geocities.com/rsramsam/soapdemo.htm

 

       XML RPC with APACHE-SOAP1.2

        (published in DeveloperIQ..March-2004)

                 (www.developeriq.com)

 

 

 

R.S.RAMASWAMY,

(rsramsam@yahoo.co.in)

 

 

         Dave Winer was the creator of XML-RPC (UserLand software). Don Box of Developmentor was he lead architect for SOAP. Apache SOAP was originally developed by IBM and was known as IM-SOAP. IBM handed it over to Apache Foundation. The Apache Software Foundation is a non-profit or ‘not-for-profit’ organization, widely known for its Apache WebServer.

 

       (SOAP1.1 is known as ApacheSoap1.2 and incorporates SOAP with attachments. Readers are recommended to follow this up with the study of a very fine book, ‘Professional java WebServices’ by MackHendricks and Romin Irani (Wrox prss)…pages 63 to 67).

 

        Apache Soap has been given in an earlier CD from DeveloperIQ (March-2003). We can install it in C: drive. We have installed tomcat4 in F: drive.

 

1)Copy soap.jar file from soap22\lib into tomcat4\common\lib folder.

2)Copy soap.war file from soap22\webapps into tomcat4\webapps folder.

 

3) cd to f:\tomcat\bin

     set JAVA_HOME=D:\JDK1.3

     Start the tomcat server.

     >startup

   Open the browser and type as follows to verify the service:

   http://localhost:8080/soap/servlet/rpcrouter

 

    The output will be as follows:

    SOAP RPC ROUTER

   “Sorry I don’t speak via HTTP GET-you have to use HTTP Post to talk to me”

 

 

 

       There is no need to panic! This is as it should be!

4)Now let us create our project directory as

            >md e:\soapdemo

             >cd to e:\soapdemo

5)Set path as follows:

       soapdemo >set path=c:\windows\command;d:\jdk1.3\bin

6)Set classpath as follows:

 

 

     >set classpath=e:\soapdemo;

     f:\tomcat4\common\endorsed\xercesImpl.jar

     f:\tomcat4\common\endorsed\xmlParserAPIs.jar

     f:\tomcat4\common\lib\soap.jar

     f:\tomcat4\common\lib\mail.jar

     f:\tomcat4\common\lib\activation.jar

 

     (This should be typed in a single line).

7)Create webservice java file in the e:\soapdemo folder as shown  .

 

//  helloworld.java

public class helloworld

{

    public String getmessage()

    {

     return “Hello from apache 2.2-------“;

    }

}

 

8)Compile the above file.

9)Create a jar file, which contains the webservice java class file

           >jar cf helloworld.jar helloworld.class

10)Copy the helloworld.jar file into ‘Tomcat\common\lib’ folder

­­­­           >copy helloworld.jar f:\tomcat4\common\lib\

11)Create a deployment descriptor(.xml file) as follows:

      (

//  helloworldDD.xml

<?xml version=”1.0”?>

 

<isd:service

    xmlns:isd=

http://xml.apache.org/xml-soap/deployment

               id=”urn:helloworldservice”>

 

<isd:provider type=”java”

                      scope=”Application”

                 methods=”getMessage”>

<isd:java  class=”helloworld” static=”false” />

</isd:provider>

   <isd:faultListener>

        org.apache.soap.server.DOMFaultListener

   </isd:faultListener>

 

</isd:service>

 

 

11)Check the installations by entering the following command:

   >java org.apache.soap.server.ServiceManagerClient

     http://localhost:8080/soap/servlet/rpcrouter       list

(Type this in a continuous line).

 

12) We should not get any items listed! (The reason being, we have not yet deployed anything). Otherwise, something is wrong. You must check up thoroughly.

 

13.Deploy the service

   >java org.apche.soap.server.ServiceManagerClient

         http://localhost:8080/soap/servlet/rpcrouter deploy

         helloworldDD.xml

 

14)Query the attribute

    >java org.apche.soap.server.ServiceManagerClient

         http://localhost:8080/soap/servlet/rpcrouter query 

                            “urn:helloworldservice”

 

15)We are now ready to create and execute our client for this webservices. We will make the client a servlet.

// helloservlet.java

 

import org.apache.soap.Constants;

import java.net.*;

import org.apache.*;

import org.apache.soap.*;

 

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

 

public class helloservlet extends HttpServlet

{

   public void doPost(HttpServletRequest request,

                                   HttpServletResponse response)

                            throws ServletException,IOException

  {

       response.setContentType(“text/html”);

       PrintWriter   out=response.getWriter();

//======================================

  try

  {

     Call call = new Call();

     System.out.println(“point-1”);

    

     call.setTargetObjectURI(“urn:helloworldservice”);

   System.out.println(“point-2”);

 

   call.setMethodName(“getMessage”);

   System.out.println(“point-3”);

 

   call.setEncodingStyleURI(Consonants.NS-URI_SOAP_ENC);

   System.out.println(“point-4”);

 

  URL     url =

   new   URL(“http://localhost:8080/soap/servlet/rpcrouter”)

   System.out.println(“point-5”);

 

     Response    resp = call.invoke(url,” ”);

     System.out.println(“point-6”);

 

Parameter   pm = resp.getRetutnValue();

 

   System.out.println(pm.getValue());

   Out.println(pm.getValue());

  }

    catch(Exception e1){System.out.println(“”+e1);}

  }

}

}

 

// helloclientservlet.htm

 

<html>

<body>

DEMO FOR SOAP CLIENT AS A SERVLET <BR>

<form method=post

   action=”http://localhost:8080/soapdemo/servlet/helloservlet”>

<input type=submit>

</form>

</body>

</html>

 

We have already seen (in an earlier lesson) how we can compile and deploy our servlet in tomcat. Follow the procedure carefully.

    Invoke the html form and submit. We get the response due to webservices as “hello from Apache2.2.!”;

--------------------------------------------------------

 

(An important note on running a servlet in tomcat4)

 

Let us say that we want to create an application named as ‘greeterapp’

 

1.Ceate a folder named ‘greeterapp’ under tomcat4\webapps folder.

 cd to greeterapp folder.

 place greeter.htm in this folder.

The action field is

  “http://localhost:8080/greeterapp/servlet/greeter’

 

2.Create a folder named ‘WEB-INF’ under greeterapp folder. (be careful about naming this folder. It should be WEB-INF & not web-inf.)(Use capital letters.) place web.xml in this folder. Thw web.xml file is given below .

 

 

<?xml version=”1.0” encoding=”ISO-8859-1”?>

 

<!DOCTYPE web-app

           PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”

   “http://java.sun.com/dtd/web-app_2_3.dtd”>

   <web-app>

     <servlet>

       <servlet-name>greeter</servlet-name>

       <servlet-class>greeter</servlet-class>

      </servlet>

 

     <servlet-mapping>

       <servlet-name>greeter</servlet-name>

       <url-pattern>/servlet/greeter</url-pattern>

      </servlet-mapping>

   </web-app>

 

3.Create a folder named ‘classes’ under WEB-INF folder.

   Place your greeter.class(servlet class file)in this folder.

    We have installed tomcat4 in F: drive

 

   cd to tomcat41

   cd to bin

   set JAVA_HOME=D:\JDK141

   bin>startup

  

   This will start the server.Wait till you get the last line of console message as follows:

 

   JK running….etc.

 

 

 

                       HOME PAGE

 

 

 

 

1