Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML-RPC Cvičení 8 - DS 2006. Úvod XML RPC Volání vzdálených podprogramů.

Similar presentations


Presentation on theme: "XML-RPC Cvičení 8 - DS 2006. Úvod XML RPC Volání vzdálených podprogramů."— Presentation transcript:

1 XML-RPC Cvičení 8 - DS 2006

2 Úvod XML RPC Volání vzdálených podprogramů

3 XML typy XML-RPC typeSimplest Java typeMore complex Java type i4intjava.lang.Integer int java.lang.Integer boolean java.lang.Boolean stringjava.lang.String double java.lang.Double dateTime.iso8601java.util.Date structjava.util.Hashtable arrayjava.util.Vector base64byte[] nil (extension)null

4 Klient public class GetSetClient { public static void main(String args[]) { if (args.length < 1) { System.out.println( "Usage: java GetSetClient [get | set] [value]"); System.exit(-1); } String getOrSet=new String(args[0]); if (!((getOrSet.equals("get")) || (getOrSet.equals("set")))) { System.out.println( "First argument must be get or set"); System.exit(-1); }

5 Klient try { // Create the client, identifying the server XmlRpcClient client = new XmlRpcClient("http://localhost:8899/"); //get local host IP address InetAddress address=InetAddress.getLocalHost( ); String ipAddress=address.toString( ); // Create the request parameters using user input Vector params = new Vector( ); params.addElement(ipAddress); if (getOrSet.equals("set")) { Integer newValue=new Integer(args[1]); params.addElement(newValue); }

6 Klient // Issue a request Object result=null; if (getOrSet.equals("set")) { result = client.execute("getSet.setValue", params); } else { result = client.execute("getSet.getValue", params); } // Report the results System.out.println("The response was: " + result.toString( )); } catch (IOException e) { System.out.println("IO Exception: " + e.getMessage( )); } catch (XmlRpcException e) { System.out.println("Exception within XML-RPC: " + e.getMessage( )); }

7 Server public class GetSetServer { public static void main(String[] args) { if (args.length < 1) { System.out.println( "Usage: java GetSetServer [port]"); System.exit(-1); } try { // Start the server, using built-in version System.out.println("Attempting to start XML-RPC Server..."); WebServer server = new WebServer(Integer.parseInt(args[0]));

8 Server // Register our handler class as area server.addHandler("getSet", new GetSetHandler(20)); System.out.println( "Registered GetSetHandler class to getSet."); System.out.println("Now accepting requests. (Halt program to stop.)"); } catch (IOException e) { System.out.println("Could not start server: " + e.getMessage( )); }

9 Handler public class GetSetHandler { protected int value; public GetSetHandler(int initialValue) { value=initialValue; } public int getValue(String requester) { return value; } public int setValue(String requester, int newValue) { value=newValue; return value; }

10 Download Jakarta Commons - The Commons is a Jakarta subproject focused on all aspects of reusable Java components. Commons Proper - A repository of reusable Java components. Commons Codec - General encoding/decoding algorithms (for example phonetic, base64, URL). http://mirror.styx.cz/apache/jakarta/commons/codec/binaries/comm ons-codec-1.3.zip http://mirror.styx.cz/apache/ws/xmlrpc/http://mirror.styx.cz/apache/ws/xmlrpc/xmlrpc-current-bin.tar.gz


Download ppt "XML-RPC Cvičení 8 - DS 2006. Úvod XML RPC Volání vzdálených podprogramů."

Similar presentations


Ads by Google