]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/test/TestClient.java
fixed some doc strings. added sample makefile
[OpenSRF.git] / src / java / org / opensrf / test / TestClient.java
1 package org.opensrf.test;
2 import org.opensrf.*;
3 import org.opensrf.util.*;
4 import org.opensrf.net.xmpp.*;
5 import java.io.PrintStream;
6 import java.util.Map;
7 import java.util.Date;
8
9
10 public class TestClient {
11     public static void main(String args[]) throws Exception {
12         
13         PrintStream out = System.out;
14
15         try {
16
17             /** setup the config parser */
18             String configFile = args[0];
19             Config config = new Config("/config/opensrf");
20             config.parse(configFile);
21             Config.setConfig(config);
22
23             /** Connect to jabber */
24             String username = Config.getString("/username");
25             String passwd = Config.getString("/passwd");
26             String host = (String) Config.getFirst("/domains/domain");
27             int port = Config.getInt("/port");
28             XMPPSession xses = new XMPPSession(host, port);
29             xses.connect(username, passwd, "test-java-client");
30             XMPPSession.setGlobalSession(xses);
31     
32             /** build the client session and send the request */
33             ClientSession session = new ClientSession("opensrf.settings");
34             Request request = session.request(
35                 "opensrf.settings.host_config.get", 
36                 new String[] {args[1]}
37             );
38
39             Result result = request.recv(10000);
40             if(result == null) {
41                 out.println("no result");
42                 return;
43             }
44
45             out.println("status = " + result.getStatus());
46             out.println("status code = " + result.getStatusCode());
47
48             out.println("setting config memcache server(s) = " +
49                 new JSONWriter(
50                     Utils.findPath( (Map) result.getContent(), 
51                     "/cache/global/servers/server")
52                 ).write());
53
54
55         } catch(ArrayIndexOutOfBoundsException e) {
56             out.println("usage: org.opensrf.test.TestClient <osrfConfigFile> <domain>");
57             return;
58         }
59     }
60 }
61
62
63