From: erickson Date: Sat, 21 Jul 2007 20:50:19 +0000 (+0000) Subject: added a bunch of comments to the test client to help explain the api X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=88e23705ea5f26e96256695218bc3467b6484058;p=opensrf%2Fbjwebb.git added a bunch of comments to the test client to help explain the api made the makefile 'run' command more verbose git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1055 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/java/Makefile b/src/java/Makefile index 844c7c5..eeaa928 100644 --- a/src/java/Makefile +++ b/src/java/Makefile @@ -35,7 +35,7 @@ opensrf: deps 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 @@ check: @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 diff --git a/src/java/org/opensrf/test/TestClient.java b/src/java/org/opensrf/test/TestClient.java index 2625053..866ea0c 100644 --- a/src/java/org/opensrf/test/TestClient.java +++ b/src/java/org/opensrf/test/TestClient.java @@ -12,42 +12,65 @@ public class TestClient { 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 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 "+ " [, ]"); 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 params = new ArrayList(); - 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(); + 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); + + /** kick off the timer */ + start = new Date().getTime(); - long start = new Date().getTime(); - Request request = session.request(method, params); + /** 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."); } }