| | 1 | == Using XML-RPC compliant types in your API == |
| | 2 | |
| | 3 | If ypu use types in your remote calls wich are XML-RPC compliant things are very easy: |
| | 4 | |
| | 5 | '''Server side''' |
| | 6 | |
| | 7 | - The server side defines an API to be used remotely over XML-RPC. Additionaly an implementation |
| | 8 | of the API is hosted on the server-side |
| | 9 | |
| | 10 | {{{ |
| | 11 | interface Api { |
| | 12 | String getStatusMessage( int code ); |
| | 13 | } |
| | 14 | |
| | 15 | class Impl implements Api { |
| | 16 | public String getStatusMessage( int code ) {...} |
| | 17 | } |
| | 18 | }}} |
| | 19 | |
| | 20 | - register implementation as XML-RPC handler with the server |
| | 21 | |
| | 22 | {{{ |
| | 23 | WebServer xmlRpcServer = new WebServer( port ); |
| | 24 | xmlRpcServer.addHandler( "handlerId", XmlRpcHandlerFactory.createHandlerFor( new Impl() ); |
| | 25 | xmlRpcServer.start(); |
| | 26 | }}} |
| | 27 | |
| | 28 | '''Client side''' |
| | 29 | |
| | 30 | - create a remote client the use the API by simply calling a single method |
| | 31 | |
| | 32 | {{{ |
| | 33 | Api remote_api = XmlRpc.createClient( Api.class, "handlerId", host, port ); |
| | 34 | String msg = remote_api.getStatusMessage( 42 ); |
| | 35 | ... |
| | 36 | }}} |
| | 37 | |