implemented client bootstrap. created a status object to model connection statuses...
[OpenSRF.git] / src / java / org / opensrf / test / TestClient.java
index 8cd7865..df6db94 100644 (file)
@@ -1,61 +1,48 @@
 package org.opensrf.test;
 import org.opensrf.*;
 import org.opensrf.util.*;
-import org.opensrf.net.xmpp.*;
-import java.io.PrintStream;
 import java.util.Map;
 import java.util.Date;
+import java.util.List;
+import java.util.ArrayList;
+import java.io.PrintStream;
 
 
 public class TestClient {
     public static void main(String args[]) throws Exception {
         
         PrintStream out = System.out;
+        String service;
+        String method;
 
         try {
+            Sys.bootstrapClient(args[0], "/config/opensrf");
+            service = args[1];
+            method = args[2];
+        } catch(ArrayIndexOutOfBoundsException e) {
+            out.println( "usage: org.opensrf.test.TestClient "+
+                "<osrfConfigFile> <service> <method> [<JSONparam1>, <JSONparam2>]");
+            return;
+        }
 
-            /** setup the config parser */
-            String configFile = args[0];
-            Config config = new Config("/config/opensrf");
-            config.parse(configFile);
-            Config.setConfig(config);
-
-            /** Connect to jabber */
-            String username = Config.getString("/username");
-            String passwd = Config.getString("/passwd");
-            String host = (String) Config.getFirst("/domains/domain");
-            int port = Config.getInt("/port");
-            XMPPSession xses = new XMPPSession(host, port);
-            xses.connect(username, passwd, "test-java-client");
-            XMPPSession.setGlobalSession(xses);
-    
-            /** build the client session and send the request */
-            ClientSession session = new ClientSession("opensrf.settings");
-            Request request = session.request(
-                "opensrf.settings.host_config.get", 
-                new String[] {args[1]}
-            );
-
-            Result result = request.recv(10000);
-            if(result == null) {
-                out.println("no result");
-                return;
-            }
-
-            out.println("status = " + result.getStatus());
-            out.println("status code = " + result.getStatusCode());
+        /** build the client session and send the request */
+        ClientSession session = new ClientSession(service);
+        List<Object> params = new ArrayList<Object>();
+        JSONReader reader;
 
-            out.println("setting config memcache server(s) = " +
-                new JSONWriter(
-                    Utils.findPath( (Map) result.getContent(), 
-                    "/cache/global/servers/server")
-                ).write());
+        for(int i = 3; i < args.length; i++) /* add the params */
+            params.add(new JSONReader(args[i]).read());
 
+        Request request = session.request(method, params);
 
-        } catch(ArrayIndexOutOfBoundsException e) {
-            out.println("usage: org.opensrf.test.TestClient <osrfConfigFile> <domain>");
-            return;
+        Result result;
+        long start = new Date().getTime();
+        while( (result = request.recv(60000)) != null ) {
+            out.println("status = " + result.getStatus());
+            out.println("status code = " + result.getStatusCode());
+            out.println("result JSON: " + new JSONWriter(result.getContent()).write());
         }
+        out.println("Request took: " + (new Date().getTime() - start));
     }
 }