opensrf gateway tester
authorBill Erickson <berick@esilibrary.com>
Fri, 16 Mar 2012 13:55:52 +0000 (09:55 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 16 Mar 2012 13:55:52 +0000 (09:55 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/java/org/opensrf/test/TestGateway.java

index 031f890..967e929 100644 (file)
@@ -27,23 +27,31 @@ public class TestGateway {
         method.addParam(Arrays.asList(8,6,7,5,3,0,9));
 
         // sync test
-        HttpRequest req = new GatewayRequest(conn, "opensrf.math", method);
+        HttpRequest req = new GatewayRequest(conn, "opensrf.math", method).send();
         Object resp;
-        req.send();
         while ( (resp = req.recv()) != null) {
             System.out.println("Sync Response: " + resp);
         }
 
+        // exceptions are captured instead of thrown, 
+        // primarily to better support async requests
+        if (req.failed()) {
+            req.getFailure().printStackTrace();
+            return;
+        }
 
         // async test
-        HttpRequest req2 = new GatewayRequest(conn, "opensrf.math", method);
-        req2.sendAsync(
-            new HttpRequestHandler() {
-                public void onResponse(HttpRequest req, Object resp) {
-                    System.out.println("Async Response: " + resp);
+        for (int i = 0; i < 10; i++) {
+            final int ii = i; // required for nested class
+            HttpRequest req2 = new GatewayRequest(conn, "opensrf.math", method);
+            req2.sendAsync(
+                new HttpRequestHandler() {
+                    public void onResponse(HttpRequest req, Object resp) {
+                        System.out.println("Async Response: " + ii + " : " + resp);
+                    }
                 }
-            }
-        );
+            );
+        }
     }
 }