Spring Semester 2003


Lecture Notes 27: XML-RPC and true interoperability

I am going to create a folder xmlrpc for all the work:

frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman
frilled.cs.indiana.edu%mkdir xmlrpc
frilled.cs.indiana.edu%cd xmlrpc
frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc
frilled.cs.indiana.edu%ls -l
total 0
frilled.cs.indiana.edu%
Now, the question is: what do we put in there?

Take a look at this page:

http://www.xmlrpc.com
and from it check the How-to (Eric Kidd's):
http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto.html
We are going to focus on Chapter 8: Using XML-RPC with Java.

Following the link for Hannes Walln÷fer's implementation:

http://classic.helma.at/hannes/xmlrpc/
we find out that Helma has moved, to become the Apache XML-RPC Project.

http://xml.apache.org/xmlrpc/
Latest release of the project can be downloaded from this location:
http://xml.apache.org/dist/xmlrpc/
So far so good; what next?

Well, I download the following two files .

[   ] xmlrpc-1.1.tar.gz         06-Mar-2002 11:49  157K  GZIP compressed file
[   ] xmlrpc-1.1.tar.gz.md5     06-Mar-2002 11:52   52   GZIP compressed file
Here's my result:
frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc
frilled.cs.indiana.edu%ls -l
total 169
-rw-------   1 dgerman  faculty    161173 Nov 28 22:17 xmlrpc-1.1.tar.gz
-rw-------   1 dgerman  faculty        52 Nov 28 22:17 xmlrpc-1.1.tar.gz.md5
frilled.cs.indiana.edu%
Now, what do I do?

Here's what:

frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc
frilled.cs.indiana.edu%ls -l
total 169
-rw-------   1 dgerman  faculty    161173 Nov 28 22:17 xmlrpc-1.1.tar.gz
-rw-------   1 dgerman  faculty        52 Nov 28 22:17 xmlrpc-1.1.tar.gz.md5
frilled.cs.indiana.edu%gunzip *.gz
frilled.cs.indiana.edu%ls -l
total 1345
-rw-------   1 dgerman  faculty   1361920 Nov 28 22:17 xmlrpc-1.1.tar
-rw-------   1 dgerman  faculty        52 Nov 28 22:17 xmlrpc-1.1.tar.gz.md5
frilled.cs.indiana.edu%tar xvf *.tar
xmlrpc-1.1/
xmlrpc-1.1/docs/
xmlrpc-1.1/docs/apidocs/
xmlrpc-1.1/docs/apidocs/org/
xmlrpc-1.1/docs/apidocs/org/apache/
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/class-use/
xmlrpc-1.1/docs/images/
xmlrpc-1.1/README.txt
xmlrpc-1.1/LICENSE
xmlrpc-1.1/xmlrpc-1.1.jar
xmlrpc-1.1/xmlrpc-1.1-applet.jar
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/package-tree.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcClient.CallData.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcClientLite.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcClient.Worker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/AsyncCallback.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcClientLite.HttpClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcClientLite.LiteWorker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/AuthenticatedXmlRpcHandler.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/Echo.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/AuthDemo.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/Invoker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpc.Value.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcServer.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/WebServer.AddressMatcher.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpc.XmlWriter.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/ServerInputStream.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/WebServer.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/WebServer.Connection.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcServer.Worker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/Formatter.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/WebServer.Runner.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcException.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpc.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcHandler.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/Base64.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/class-use/XmlRpcProxyServlet.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/package-summary.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcClientLite.LiteWorker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcServer.Worker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/Base64.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/SimpleXmlRpcClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/XmlRpcSupport.Value.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/XmlRpcException.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/JSXmlRpcApplet.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/XmlRpcApplet.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/SimpleXmlRpcClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/XmlRpcSupport.XmlWriter.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/class-use/XmlRpcSupport.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/package-use.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/XmlRpcSupport.XmlWriter.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/XmlRpcException.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/XmlRpcApplet.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/package-tree.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/package-frame.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/package-summary.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/XmlRpcSupport.Value.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/JSXmlRpcApplet.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/applet/XmlRpcSupport.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/SecureXmlRpcClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/package-tree.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/package-frame.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/package-summary.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/class-use/SecureWebServer.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/class-use/SecureXmlRpcClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/class-use/SecurityConstants.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/class-use/SecurityTool.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/SecureWebServer.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/SecurityConstants.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/SecurityTool.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/secure/package-use.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcClient.CallData.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/WebServer.Runner.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/WebServer.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/ServerInputStream.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcProxyServlet.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/Echo.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcHandler.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/Formatter.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/WebServer.Connection.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpc.Value.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/AsyncCallback.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcClient.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcServer.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcClient.Worker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcClientLite.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/package-frame.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/Invoker.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/package-use.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/WebServer.AddressMatcher.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/AuthDemo.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcException.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/AuthenticatedXmlRpcHandler.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpc.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpc.XmlWriter.html
xmlrpc-1.1/docs/apidocs/org/apache/xmlrpc/XmlRpcClientLite.HttpClient.html
xmlrpc-1.1/docs/apidocs/stylesheet.css
xmlrpc-1.1/docs/apidocs/overview-frame.html
xmlrpc-1.1/docs/apidocs/index.html
xmlrpc-1.1/docs/apidocs/help-doc.html
xmlrpc-1.1/docs/apidocs/serialized-form.html
xmlrpc-1.1/docs/apidocs/index-all.html
xmlrpc-1.1/docs/apidocs/deprecated-list.html
xmlrpc-1.1/docs/apidocs/overview-tree.html
xmlrpc-1.1/docs/apidocs/overview-summary.html
xmlrpc-1.1/docs/apidocs/packages.html
xmlrpc-1.1/docs/apidocs/allclasses-frame.html
xmlrpc-1.1/docs/apidocs/package-list
xmlrpc-1.1/docs/client.html
xmlrpc-1.1/docs/images/feather.gif
xmlrpc-1.1/docs/images/xmlrpc-logo.gif
xmlrpc-1.1/docs/images/xml-logo.gif
xmlrpc-1.1/docs/server.html
xmlrpc-1.1/docs/cvs.html
xmlrpc-1.1/docs/parser.html
xmlrpc-1.1/docs/download.html
xmlrpc-1.1/docs/lists.html
xmlrpc-1.1/docs/types.html
xmlrpc-1.1/docs/changes.html
xmlrpc-1.1/docs/index.html
frilled.cs.indiana.edu%
OK, let's not get overwhelmed, shall we?

Perhaps we only need a couple of files of all these.

frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc
frilled.cs.indiana.edu%ls -l
total 1346
drwx------   3 dgerman  faculty       512 Mar  6  2002 xmlrpc-1.1
-rw-------   1 dgerman  faculty   1361920 Nov 28 22:17 xmlrpc-1.1.tar
-rw-------   1 dgerman  faculty        52 Nov 28 22:17 xmlrpc-1.1.tar.gz.md5
frilled.cs.indiana.edu%mkdir frontier
frilled.cs.indiana.edu%cd frontier
frilled.cs.indiana.edu%ls
frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc/frontier
frilled.cs.indiana.edu%
We now need two files:

A client can be found at this location:

http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto-java-server.html
A client can be found at this location:

http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto-java-client.html
Here are my steps:

frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc/frontier
frilled.cs.indiana.edu%emacs JavaClient.java 
frilled.cs.indiana.edu%cat JavaClient.java
import java.util.Vector;
import java.util.Hashtable;
import helma.xmlrpc.*;

public class JavaClient {
    
    // The location of our server.
    private final static String server_url =
	"http://xmlrpc-c.sourceforge.net/api/sample.php";
    
    public static void main (String [] args) {
	try {
	    
	    // Create an object to represent our server.
	    XmlRpcClient server = new XmlRpcClient(server_url);
	    
	    // Build our parameter list.
	    Vector params = new Vector();
	    params.addElement(new Integer(5));
	    params.addElement(new Integer(3));
	    
	    // Call the server, and get our result.
	    Hashtable result =
		(Hashtable) server.execute("sample.sumAndDifference", params);
	    int sum = ((Integer) result.get("sum")).intValue();
	    int difference = ((Integer) result.get("difference")).intValue();
	    
	    // Print out our result.
	    System.out.println("Sum: " + Integer.toString(sum) +
			       ", Difference: " +
			       Integer.toString(difference));
	    
	} catch (XmlRpcException exception) {
	    System.err.println("JavaClient: XML-RPC Fault #" +
			       Integer.toString(exception.code) + ": " +
			       exception.toString());
	} catch (Exception exception) {
	    System.err.println("JavaClient: " + exception.toString());
	}
    }
}
We attempt compilation of the client:
frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc/frontier
frilled.cs.indiana.edu%ls -ld ../xml*/*.jar
-rw-------   1 dgerman  faculty     24912 Mar  6  2002 ../xmlrpc-1.1/xmlrpc-1.1-applet.jar
-rw-------   1 dgerman  faculty     57460 Mar  6  2002 ../xmlrpc-1.1/xmlrpc-1.1.jar
frilled.cs.indiana.edu%setenv CLASSPATH ~/xmlrpc/xmlrpc-1.1/xmlrpc-1.1.jar:.
frilled.cs.indiana.edu%echo $CLASSPATH
/u/dgerman/xmlrpc/xmlrpc-1.1/xmlrpc-1.1.jar:.
frilled.cs.indiana.edu%ls -l
total 4
-rw-------   1 dgerman  faculty      1293 Nov 28 22:27 JavaClient.java
frilled.cs.indiana.edu%javac JavaClient.java
JavaClient.java:3: package helma.xmlrpc does not exist
import helma.xmlrpc.*;
^
JavaClient.java:15: cannot resolve symbol
symbol  : class XmlRpcClient 
location: class JavaClient
	    XmlRpcClient server = new XmlRpcClient(server_url);
            ^
JavaClient.java:15: cannot resolve symbol
symbol  : class XmlRpcClient 
location: class JavaClient
	    XmlRpcClient server = new XmlRpcClient(server_url);
                                      ^
JavaClient.java:33: cannot resolve symbol
symbol  : class XmlRpcException 
location: class JavaClient
	} catch (XmlRpcException exception) {
                 ^
4 errors
frilled.cs.indiana.edu%emacs JavaClient.java
We make a single (predictable) change:
frilled.cs.indiana.edu%diff JavaClient.java JavaClient.java~
3c3
< import org.apache.xmlrpc.*;
---
> import helma.xmlrpc.*;
frilled.cs.indiana.edu%
And the client is now ready to work:

frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc/frontier
frilled.cs.indiana.edu%ls -l
total 4
-rw-------   1 dgerman  faculty      1298 Nov 28 22:34 JavaClient.java
-rw-------   1 dgerman  faculty      1293 Nov 28 22:33 JavaClient.java~
frilled.cs.indiana.edu%diff JavaClient.java JavaClient.java~
3c3
< import org.apache.xmlrpc.*;
---
> import helma.xmlrpc.*;
frilled.cs.indiana.edu%echo $CLASSPATH
/u/dgerman/xmlrpc/xmlrpc-1.1/xmlrpc-1.1.jar:.
frilled.cs.indiana.edu%javac JavaClient.java
frilled.cs.indiana.edu%java JavaClient
Sum: 8, Difference: 2
frilled.cs.indiana.edu%
Why should we be happy?

(As a matter of fact, why shouldn't we?)

The truth is, though, that this is very exciting.

Can we use a Perl client, too?

frilled.cs.indiana.edu%pwd
/nfs/moose/home/user3/dgerman/xmlrpc/frontier
frilled.cs.indiana.edu%vi perlClient
frilled.cs.indiana.edu%ls -l
total 7
-rw-------   1 dgerman  faculty      1567 Nov 28 22:40 JavaClient.class
-rw-------   1 dgerman  faculty      1298 Nov 28 22:34 JavaClient.java
-rw-------   1 dgerman  faculty      1293 Nov 28 22:33 JavaClient.java~
-rw-r--r--   1 dgerman  faculty       432 Nov 28 22:45 perlClient
frilled.cs.indiana.edu%cat perlClient
#!/usr/bin/perl
use Frontier::Client;
    
# Make an object to represent the XML-RPC server.
$server_url = 'http://xmlrpc-c.sourceforge.net/api/sample.php';
$server = Frontier::Client->new(url => $server_url);
    
# Call the remote server and get our result.
$result = $server->call('sample.sumAndDifference', 5, 3);
$sum = $result->{'sum'};
$difference = $result->{'difference'};
   
print "Sum: $sum, Difference: $difference\n";
frilled.cs.indiana.edu%chmod 755 perlClient
frilled.cs.indiana.edu%./perlClient
Sum: 8, Difference: 2
frilled.cs.indiana.edu%
Now, exciting as this may be, can we also produce a server?

The answer is yes, and we will show how in a second.

Another thing worth mentioning is that

Also, hashtables (not primitive types) have been passed back and forth.

Let us now focus on the issue of creating a server.

I have grouped a minimal number of files on the class web site (see below).

Go there and copy the files in a folder in your account:

burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/xmlrpc
burrowww.cs.indiana.edu% cp /l/www/classes/a348/fall2002/xmlrpc/* . 
burrowww.cs.indiana.edu% ls -l
total 61
-rw-r--r--   1 dgerman  faculty      1287 Nov 28 23:11 JavaClient.java
-rw-r--r--   1 dgerman  faculty       858 Nov 28 23:11 JavaServer.java
-rw-r--r--   1 dgerman  faculty       432 Nov 28 23:11 perlClient
-rw-r--r--   1 dgerman  faculty     57460 Nov 28 23:11 xmlrpc-1.1.jar
burrowww.cs.indiana.edu% 
Modulo a minor CLASSPATH setting we're ready to compile:
burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/xmlrpc
burrowww.cs.indiana.edu% ls -l
total 61
-rw-r--r--   1 dgerman  faculty      1287 Nov 28 23:11 JavaClient.java
-rw-r--r--   1 dgerman  faculty       858 Nov 28 23:11 JavaServer.java
-rw-r--r--   1 dgerman  faculty       432 Nov 28 23:11 perlClient
-rw-r--r--   1 dgerman  faculty     57460 Nov 28 23:11 xmlrpc-1.1.jar
burrowww.cs.indiana.edu% setenv CLASSPATH ./xmlrpc-1.1.jar:$CLASSPATH
burrowww.cs.indiana.edu% javac JavaClient.java
burrowww.cs.indiana.edu% javac JavaServer.java
burrowww.cs.indiana.edu% cat JavaServer.java
import java.util.Hashtable;
import org.apache.xmlrpc.*;

public class JavaServer {
    
    public JavaServer () {
        // Our handler is a regular Java object. It can have a
        // constructor and member variables in the ordinary fashion.
        // Public methods will be exposed to XML-RPC clients.
    }
    
    public Hashtable sumAndDifference (int x, int y) {
        Hashtable result = new Hashtable();
        result.put("one: ", new Integer(x * y)); // notice the changes for both 
        result.put("two: ", new Integer(x * x - y * y)); // the names and values
        return result; // although what comes back is still a Hashtable 
    } // the matching of the keys, however is fundamental 
    
    public static void main (String [] args) {
        try {
            
            // Invoke me as .
            WebServer server = new WebServer(Integer.parseInt(args[0]));
            server.addHandler("sample", new JavaServer());
            
        } catch (Exception exception) {
            System.err.println("JavaServer: " + exception.toString());
        }
    }
}
burrowww.cs.indiana.edu%
Notice that we instruct the server to start on a port provided on the command line.

I start my server on 10603 (which is listed as my 5th port on the students and ports page).

burrowww.cs.indiana.edu% java JavaServer 10603

And the server stays there...

Meanwhile from where the client was (after a few minor changes):

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/fall2002/xmlrpc
frilled.cs.indiana.edu%ls -l
total 61
-rw-r--r--   1 dgerman  faculty      1420 Nov 29 00:17 JavaClient.java
-rw-r--r--   1 dgerman  faculty       853 Nov 29 00:02 JavaServer.java
-rwx------   1 dgerman  faculty       426 Nov 29 00:02 perlClient
-rw-r--r--   1 dgerman  faculty     57460 Nov 28 23:10 xmlrpc-1.1.jar
frilled.cs.indiana.edu%cat JavaClient.java
import java.util.Vector;
import java.util.Hashtable;
import org.apache.xmlrpc.*;

public class JavaClient {
    
    // The location of our server.
    private final static String server_url =
	"http://burrowww.cs.indiana.edu:10603/RPC2";
    
    public static void main (String [] args) {
	try {
	    
	    // Create an object to represent our server.
	    XmlRpcClient server = new XmlRpcClient(args[0]);

	    // Build our parameter list.
	    Vector params = new Vector();
	    params.addElement(new Integer(args[1]));
	    params.addElement(new Integer(args[2]));
	    
	    // Call the server, and get our result.
	    Hashtable result =
		(Hashtable) server.execute("sample.sumAndDifference", params);

	    System.out.println("Receiving: " + result); 

	    int one = 0, two = 0; 

	    try {
	        one = ((Integer) result.get("one: ")).intValue();
		two = ((Integer) result.get("two: ")).intValue();
	    } catch (Exception e) { System.out.println("Something went wrong."); } 

	    // Print out our result.
	    System.out.println("One: " + Integer.toString(one) +
			       ", Two: " + Integer.toString(two));
	    
	} catch (XmlRpcException exception) {
	    System.err.println("JavaClient: XML-RPC Fault #" +
			       Integer.toString(exception.code) + ": " +
			       exception.toString());
	} catch (Exception exception) {
	    System.err.println("JavaClient: " + exception.toString());
	}
    }
}

frilled.cs.indiana.edu%javac JavaClient.java
frilled.cs.indiana.edu%java JavaClient http://burrowww.cs.indiana.edu:10603/RPC2 5 4 
Receiving: {two: =9, one: =20}
One: 20, Two: 9
frilled.cs.indiana.edu%
So we see that this almost looks like the communication between a web browser and a web server.

And since browsers and servers need not be written in the same language

frilled.cs.indiana.edu%pwd
/nfs/grouchy/home/user2/www/classes/a348-dger/fall2002/xmlrpc
frilled.cs.indiana.edu%ls -ld perl*
-rwx------   1 dgerman  faculty       432 Nov 29 00:39 perlClient
frilled.cs.indiana.edu%cat perlClient
#!/usr/bin/perl
use Frontier::Client;
    
# Make an object to represent the XML-RPC server.
$server_url = $ARGV[0]; # 'http://xmlrpc-c.sourceforge.net/api/sample.php';
$server = Frontier::Client->new(url => $server_url);
    
# Call the remote server and get our result.
$result = $server->call('sample.sumAndDifference', $ARGV[1], $ARGV[2]);

$one = $result->{'one: '};
$two = $result->{'two: '};

print "One: $one, Two: $two\n";
frilled.cs.indiana.edu%./perlClient http://burrowww.cs.indiana.edu:10603/RPC2 5 4
One: 20, Two: 9
frilled.cs.indiana.edu%
... the use of this (http) paradigm in distributed computing is a big plus.


Last updated: Apr 22, 2003 by Adrian German for A348/A548