[Opensrf-commits] r1055 - in trunk/src/java: . org/opensrf/test

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Jul 21 16:50:47 EDT 2007


Author: erickson
Date: 2007-07-21 16:50:19 -0400 (Sat, 21 Jul 2007)
New Revision: 1055

Modified:
   trunk/src/java/Makefile
   trunk/src/java/org/opensrf/test/TestClient.java
Log:
added a bunch of comments to the test client to help explain the api
made the makefile 'run' command more verbose



Modified: trunk/src/java/Makefile
===================================================================
--- trunk/src/java/Makefile	2007-07-21 20:46:08 UTC (rev 1054)
+++ trunk/src/java/Makefile	2007-07-21 20:50:19 UTC (rev 1055)
@@ -35,7 +35,7 @@
 jar:	opensrf
 	rm -f opensrf.jar
 	echo "creating opensrf.jar"
-	jar cvf opensrf.jar -C .lib org/opensrf/
+	jar cf opensrf.jar -C .lib org/opensrf/
 
 # only prints the first 30 lines of errors
 slim:
@@ -49,7 +49,7 @@
 	@echo -e "\nTruncating at 30 lines"
 
 run:
-	@$(JAVA) -cp $(JAVA_LIBS) $(JAVA_EXE) $(JAVA_ARGS)
+	$(JAVA) -cp $(JAVA_LIBS) $(JAVA_EXE) $(JAVA_ARGS)
 
 deps:
 	mkdir -p ext

Modified: trunk/src/java/org/opensrf/test/TestClient.java
===================================================================
--- trunk/src/java/org/opensrf/test/TestClient.java	2007-07-21 20:46:08 UTC (rev 1054)
+++ trunk/src/java/org/opensrf/test/TestClient.java	2007-07-21 20:50:19 UTC (rev 1055)
@@ -12,42 +12,65 @@
 
     public static void main(String args[]) throws Exception {
 
+        /** which opensrf service are we sending our request to */
+        String service; 
+        /** which opensrf method we're calling */
+        String method;
+        /** method params, captures from command-line args */
+        List<Object> params;
+        /** knows how to read JSON */
+        JSONReader reader;
+        /** opensrf request */
+        Request request;
+        /** request result */
+        Result result;
+        /** start time for the request */
+        long start;
+        /** for brevity */
         PrintStream out = System.out;
+
         if(args.length < 3) {
             out.println( "usage: org.opensrf.test.TestClient "+
                 "<osrfConfigFile> <service> <method> [<JSONparam1>, <JSONparam2>]");
             return;
         }
 
+        /** connect to the opensrf network,  default config context 
+         * for opensrf_core.xml is /config/opensrf */
         Sys.bootstrapClient(args[0], "/config/opensrf");
-        String service = args[1];
-        String method = args[2];
 
-        /** build the client session and send the request */
-        ClientSession session = new ClientSession(service);
-        List<Object> params = new ArrayList<Object>();
-        JSONReader reader;
-
-        for(int i = 3; i < args.length; i++) /* add the params */
+        /* grab the server, method, and any params from the command line */
+        service = args[1];
+        method = args[2];
+        params = new ArrayList<Object>();
+        for(int i = 3; i < args.length; i++) 
             params.add(new JSONReader(args[i]).read());
 
 
-        Result result;
+        /** build the client session */
+        ClientSession session = new ClientSession(service);
 
-        long start = new Date().getTime();
-        Request request = session.request(method, params);
+        /** kick off the timer */
+        start = new Date().getTime();
 
+        /** Create the request object from the session, method and params */
+        request = session.request(method, params);
+
         while( (result = request.recv(60000)) != null ) { 
             /** loop over the results and print the JSON version of the content */
 
-            if(result.getStatusCode() != 200) { /* make sure the request succeeded */
+            if(result.getStatusCode() != 200) { 
+                /** make sure the request succeeded */
                 out.println("status = " + result.getStatus());
                 out.println("status code = " + result.getStatusCode());
                 continue;
             }
 
-            out.println("result JSON: " + new JSONWriter(result.getContent()).write());
+            /** JSON-ify the resulting object and print it */
+            out.println("\nresult JSON: " + new JSONWriter(result.getContent()).write());
         }
+        
+        /** How long did the request take? */
         out.println("Request round trip took: " + (new Date().getTime() - start) + " ms.");
     }
 }



More information about the opensrf-commits mailing list