Database Reference
In-Depth Information
ways easier to use than the Apache library. At the time of writing, the latest version
was 1.1.1.
The Redstone XML-RPC library offers two methods of use to a client (as does the
Apache library):
Classic XML-RPC client API ( Example 13-9 )
Basically, you tell the client about the server method and the parameters that you
wish to send, and then make a call to that method with the client against the
server. The client returns an object, which you then interrogate and cast to get
your result.
Example 13-9. Redstone classic XML-RPC client
final URL url = new URL ( "http://localhost:8080/exist/xmlrpc" );
final XmlRpcClient rpc = new XmlRpcClient ( url , true );
final Object result = rpc . invoke (
"existsAndCanOpenCollection" , new Object [] { "/db" });
Dynamic proxy XML-RPC client API ( Example 13-10 )
This is a much more modern approach than the classic one and much easier to
use. Basically, your server defines a Java interface (i.e., the interface
org.exist.xmlrpc.RpcAPI for eXist), and you make a copy of that interface to
your client application. You then ask the XML-RPC library to create a proxy to
the server using that interface. The client gives you a standard Java object, which
implements the interface. You can then use this Java object just like any other,
and all the client/server communication is hidden from you. When you call a
function on the object, the client takes care of all of the communication with the
server and returns the result.
Example 13-10. Redstone dynamic proxy XML-RPC client
final URL url = new URL ( "http://localhost:8080/exist/xmlrpc" );
final RpcAPI rpc = ( RpcAPI ) XmlRpcProxy . createProxy (
url , "Default" , new Class [] { RpcAPI . class }, true );
final Boolean result = rpc . existsAndCanOpenCollection ( "/db" );
Search WWH ::




Custom Search