more java gateway user/berick/test-osrf-java-http-gatway
authorBill Erickson <berick@esilibrary.com>
Wed, 29 Feb 2012 14:35:40 +0000 (09:35 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 29 Feb 2012 14:35:40 +0000 (09:35 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/java/org/open_ils/test/TestGateway.java

index 3d3a1ef..19d2bf7 100644 (file)
@@ -8,52 +8,43 @@ import org.open_ils.idl.*;
 
 import java.util.Map;
 import java.util.HashMap;
+import java.util.List;
 import java.net.URL;
 import java.net.HttpURLConnection;
 import java.io.InputStream;
 import java.io.BufferedInputStream;
 
-/*
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.IOException;
-import java.net.URI;
-import java.lang.StringBuffer;
-import java.util.List;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.HashMap;
-import java.math.BigInteger;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-*/
-
 public class TestGateway {
     
     private static final String idlUrl = "http://dev198.esilibrary.com/reports/fm_IDL.xml";
     private static IDLParser idlParser = null;
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws java.net.MalformedURLException {
 
+        System.out.println("Loading IDL...");
         loadIDL();
+        System.out.println("Done loading IDL.");
 
-        GatewayConnection conn = new GatewayConnection("http", "dev198.esilibrary.com");
+        // configure the connection
+        HttpConnection conn = new HttpConnection("http://dev198.esilibrary.com/osrf-gateway-v1");
 
-        Method method = new Method("opensrf.system.echo");
-        Map pmap = new HashMap<String, String>();
-        pmap.put("foo", "bar");
-        pmap.put("baz", "São Paulo");
-        method.addParam("hello, yall j;lkj a;sldkfj as;ldfkja sd;flkajs df;alsdjfk as;l");
-        method.addParam(pmap);
+        // create a stub biblio.record_entry
+        OSRFObject bre = new OSRFObject("bre");
+        bre.put("id", new Integer(123));
+        bre.put("marc", "<huzzah/>");
 
+        Method method = new Method("opensrf.system.echo");
+        method.addParam(bre);
 
-        for (int i = 0; i < 100; i++) {
+        for (int i = 0; i < 50; i++) {
             final int ii = i;
-            GatewayRequest req = conn.request("open-ils.auth", method);
+            HttpRequest req = new GatewayRequest(conn, "open-ils.auth", method);
             req.sendAsync(
-                new GatewayRequestHandler() {
-                    public void onComplete(Object payload) {
-                        System.out.println("response " + ii + " : " + payload.toString());
+                new HttpRequestHandler() {
+                    public void onResponse(HttpRequest req, Object resp) {
+                        List respList = (List) resp;
+                        OSRFObject bre = (OSRFObject) respList.get(0);
+                        System.out.println("response " + ii + " : bre echoed with ID " + bre.get("id") + " and marc " + bre.get("marc"));
                         System.out.flush();
                     }
                 }
@@ -74,14 +65,6 @@ public class TestGateway {
         } catch (Exception ex) {
             ex.printStackTrace();
         }
-
-        /*
-        OSRFObject bre = new OSRFObject("bre");
-        bre.put("id", new Integer(1));
-        bre.put("tcn_value", "FooBoo");
-        bre.put("marc", "<adfhkl/>");
-        System.out.println(new JSONWriter(bre).write());
-        */
     }
 }