Using XML-RPC compliant types in your API
If you use types in your remote calls which are XML-RPC compliant things are very easy:
Server side
- The server side defines an API to be used remotely over XML-RPC. Additionally an implementation of the API is hosted on the server-side
interface Api { String getStatusMessage( int code ); int[] getInts(); } class Impl implements Api { public String getStatusMessage( int code ) {...} public int[] getInts() { return new int[]{ 1,2,3 }; } }
- register implementation as XML-RPC handler with the server
WebServer xmlRpcServer = new WebServer( port ); xmlRpcServer.addHandler( "handlerId", XmlRpcHandlerFactory.createHandlerFor( new Impl() ) ); xmlRpcServer.start();
Client side
- create a remote client the use the API by simply calling a method like a local call.
Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); String msg = remote_api.getStatusMessage( 42 ); int[] ints = remote_api.getInts(); ...
Special type treatment
- conversions for types Integer, Double and Boolean to their primitive counterparts and vice versa is done automatically
- instead of solely using java type Vector for XML-RPC type ARRAY, also every type implementing Collection can be used (i.e., as return values).
- instead of solely using java type Hashtable for XML-RPC type STRUCT, also java type Map can be used.
- arrays of convertible types including their primitive counterparts (such as Integer, int, ...) can be used out-of-the-box
Last modified 17 years ago
Last modified on 07/02/07 18:00:38