| 44 | | |
| | 44 | == Examples == |
| | 45 | |
| | 46 | === Server side === |
| | 47 | |
| | 48 | - The server side defines an API to be used remotely over XML-RPC. Additionaly an implementation |
| | 49 | of the API is hosted on the server-side |
| | 50 | |
| | 51 | {{{ |
| | 52 | interface Api { |
| | 53 | String getStatusMessage( int code ); |
| | 54 | } |
| | 55 | |
| | 56 | class Impl implements Api { |
| | 57 | public String getStatusMessage( int code ) {...} |
| | 58 | } |
| | 59 | }}} |
| | 60 | |
| | 61 | - register implementation as XML-RPC handler with the server |
| | 62 | |
| | 63 | {{{ |
| | 64 | WebServer xmlRpcServer = new WebServer( port ); |
| | 65 | xmlRpcServer.addHandler( "handlerId", XmlRpcHandlerFactory.createHandlerFor( new Impl() ); |
| | 66 | xmlRpcServer.start(); |
| | 67 | }}} |
| | 68 | |
| | 69 | === Client side === |
| | 70 | |
| | 71 | - create a remote client the use the API by simply calling a single method |
| | 72 | |
| | 73 | {{{ |
| | 74 | Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); |
| | 75 | String msg = remote_api.getStatusMessage( 42 ); |
| | 76 | ... |
| | 77 | }}} |