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