You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rpc-dev@xml.apache.org by Bob Withers <bw...@pobox.com> on 2002/11/16 01:07:50 UTC
Type safe XML-RPC
Hi,
First, I'm fairly new to XML-RPC but I wanted to thank you developers. The
Apache xmlrpc implementation is very nice. Small, simple, and
elegant. Congratulations on a job well done.
In my use of your tool I was interested in a higher level interface to the
transport mechanism that provided type safety and simpler calling
conventions similar to EJB and RMI. I built a small class that is layered
on top of Apache xmlrpc which provides this. This class, XmlRpcProxy.java,
is a layer on top of the existing xmlrpc codebase and requires no
modifications to support its operation.
For those interested the source is available here:
http://www.ruffboy.com/code/XmlRpcProxy.zip
as a zip for or here:
http://www.ruffboy.com/code/XmlRpcProxy.java.gz
as a gzip.
It can also be accessed via ftp at:
ftp://ftp.ruffboy.com/pub
with a user id of "anonymous".
Following is the class javadoc comment describing the operation.
Thanks again for your efforts and for listening.
Regards,
Bob
/**
* Create a proxy which implements a user defined interface allowing
* XML-RPC methods to be invoked in a type safe manner.
* <br>
* An example of the use of this class:
*
* <pre>
* import org.apache.xmlrpc.XmlRpcException;
*
* public interface MyRemoteMethod
* {
* public String doSomething(int age, String name)
* throws XmlRpcException;
* }
* </pre>
*
* In client code:
*
* <pre>
* try
* {
* MyRemoteMethod remote = (MyRemoteMethod)
* XmlRpcProxy.getProxy(url,
MyRemoteMethod.class);
* String retVal = remote.doSomething(22, "Pete Holmes");
* System.out.println("Return is: " + retVal);
* }
* catch (XmlRpcException e)
* {
* e.printStackTrace();
* }
* </pre>
*
* This can be implemented on the server by having a handler which
implements
* the user defined interface:
*
* <pre>
* class MyHandler implements MyRemoteMethod
* {
* public String doSomething(int age, String name)
* {
* return(name + " is " + age + " years old.");
* }
* }
* </pre>
*
* This handler is then identified to the XML-RPC server via:
*
* <pre>
* XmlRpcServer svr = ....
* svr.addHandler(MyRemoteMethod.class.getName(), new MyHandler());
* </pre>
*
* @author Bob Withers bwit@pobox.com
*/