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