]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/test/TestClient.java
added a settings server client and test. made the global config object wrapped in...
[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 java.util.Map;
5 import java.util.Date;
6 import java.util.List;
7 import java.util.ArrayList;
8 import java.io.PrintStream;
9
10
11 public class TestClient {
12
13     public static void main(String args[]) throws Exception {
14
15         PrintStream out = System.out;
16         if(args.length < 3) {
17             out.println( "usage: org.opensrf.test.TestClient "+
18                 "<osrfConfigFile> <service> <method> [<JSONparam1>, <JSONparam2>]");
19             return;
20         }
21
22         Sys.bootstrapClient(args[0], "/config/opensrf");
23         String service = args[1];
24         String method = args[2];
25
26         /** build the client session and send the request */
27         ClientSession session = new ClientSession(service);
28         List<Object> params = new ArrayList<Object>();
29         JSONReader reader;
30
31         for(int i = 3; i < args.length; i++) /* add the params */
32             params.add(new JSONReader(args[i]).read());
33
34
35         Result result;
36
37         long start = new Date().getTime();
38         Request request = session.request(method, params);
39
40         while( (result = request.recv(60000)) != null ) { 
41             /** loop over the results and print the JSON version of the content */
42
43             if(result.getStatusCode() != 200) { /* make sure the request succeeded */
44                 out.println("status = " + result.getStatus());
45                 out.println("status code = " + result.getStatusCode());
46                 continue;
47             }
48
49             out.println("result JSON: " + new JSONWriter(result.getContent()).write());
50         }
51         out.println("Request round trip took: " + (new Date().getTime() - start) + " ms.");
52     }
53 }
54
55
56