Java Reference
In-Depth Information
LISTING 20.3
Continued
8: String title;
9: String description;
10:
11: public static void main(String arguments[]) {
12: SiteClient client = new SiteClient();
13: try {
14: Vector response = client.getRandomSite();
15: // Report the results
16: if (response.size() > 0) {
17: client.url = response.get(1).toString();
18: client.title = response.get(2).toString();
19: client.description = response.get(3).toString();
20: System.out.println(“URL: “ + client.url
21: + “\nTitle: “ + client.title
22: + “\nDescription: “ + client.description);
23: }
24: } catch (IOException ioe) {
25: System.out.println(“IO Exception: “ + ioe.getMessage());
26: ioe.printStackTrace();
27: } catch (XmlRpcException xre) {
28: System.out.println(“XML-RPC Exception: “ + xre.getMessage());
29: }
30: }
31:
32: public Vector getRandomSite()
33: throws IOException, XmlRpcException {
34:
35: // Create the client
36: XmlRpcClient client = new XmlRpcClient(
37: “http://localhost:4413/”);
38: // Create the parameters for the request
39: Vector params = new Vector();
40: // Send the request and get the response
41: Vector result = (Vector) client.execute(“dmoz.getRandomSite”,
42: params);
43: return result;
44: }
45: }
20
The SiteClient application makes a connection to the XML-RPC server and calls the
dmoz.getRandomSite() method on the server with no arguments. This method returns a
Vector that contains four strings: “ok” (to show that the request was fulfilled) and the
site's URL, title, and description.
 
Search WWH ::




Custom Search