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 PrintStream out = System.out;
17 out.println( "usage: org.opensrf.test.TestClient "+
18 "<osrfConfigFile> <service> <method> [<JSONparam1>, <JSONparam2>]");
22 Sys.bootstrapClient(args[0], "/config/opensrf");
23 String service = args[1];
24 String method = args[2];
26 /** build the client session and send the request */
27 ClientSession session = new ClientSession(service);
28 List<Object> params = new ArrayList<Object>();
31 for(int i = 3; i < args.length; i++) /* add the params */
32 params.add(new JSONReader(args[i]).read());
37 long start = new Date().getTime();
38 Request request = session.request(method, params);
40 while( (result = request.recv(60000)) != null ) {
41 /** loop over the results and print the JSON version of the content */
43 if(result.getStatusCode() != 200) { /* make sure the request succeeded */
44 out.println("status = " + result.getStatus());
45 out.println("status code = " + result.getStatusCode());
49 out.println("result JSON: " + new JSONWriter(result.getContent()).write());
51 out.println("Request round trip took: " + (new Date().getTime() - start) + " ms.");