Version 3 (modified by lauer, 18 years ago) (diff) |
---|
Using XML-RPC compliant types in your API
If you use types in your remote calls wich are XML-RPC compliant things are very easy:
Server side
- The server side defines an API to be used remotely over XML-RPC. Additionaly an implementation of the API is hosted on the server-side
interface Api { String getStatusMessage( int code ); } class Impl implements Api { public String getStatusMessage( int code ) {...} }
- 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 ); ...
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.