1 package org.opensrf.test;
3 import org.opensrf.util.*;
7 import java.util.ArrayList;
8 import java.io.PrintStream;
11 public class TestClient {
13 public static void main(String args[]) throws Exception {
15 /** which opensrf service are we sending our request to */
17 /** which opensrf method we're calling */
19 /** method params, captures from command-line args */
21 /** knows how to read JSON */
23 /** opensrf request */
27 /** start time for the request */
30 PrintStream out = System.out;
33 out.println( "usage: org.opensrf.test.TestClient "+
34 "<osrfConfigFile> <service> <method> [<JSONparam1>, <JSONparam2>]");
38 /** connect to the opensrf network, default config context
39 * for opensrf_core.xml is /config/opensrf */
40 Sys.bootstrapClient(args[0], "/config/opensrf");
42 /* grab the server, method, and any params from the command line */
45 params = new ArrayList<Object>();
46 for(int i = 3; i < args.length; i++)
47 params.add(new JSONReader(args[i]).read());
50 /** build the client session */
51 ClientSession session = new ClientSession(service);
53 /** kick off the timer */
54 start = new Date().getTime();
56 /** Create the request object from the session, method and params */
57 request = session.request(method, params);
59 while( (result = request.recv(60000)) != null ) {
60 /** loop over the results and print the JSON version of the content */
62 if(result.getStatusCode() != 200) {
63 /** make sure the request succeeded */
64 out.println("status = " + result.getStatus());
65 out.println("status code = " + result.getStatusCode());
69 /** JSON-ify the resulting object and print it */
70 out.println("\nresult JSON: " + new JSONWriter(result.getContent()).write());
73 /** How long did the request take? */
74 out.println("Request round trip took: " + (new Date().getTime() - start) + " ms.");