1 package org.opensrf.test;
4 import org.opensrf.util.*;
5 import org.opensrf.net.http.*;
9 import java.util.Arrays;
11 public class TestGateway {
13 public static void main(String[] args) {
15 if (args.length == 0) {
16 System.err.println("Please provide a gateway URL: e.g. http://example.org/osrf-gateway-v1");
22 // configure the connection
23 HttpConnection conn = new HttpConnection(args[0]);
25 Method method = new Method("opensrf.system.echo");
26 method.addParam("Hello, Gateway");
27 method.addParam(new Integer(12345));
28 method.addParam(new Boolean(true));
29 method.addParam(Arrays.asList(8,6,7,5,3,0,9));
32 HttpRequest req = new GatewayRequest(conn, "opensrf.math", method).send();
34 while ( (resp = req.recv()) != null) {
35 System.out.println("Sync Response: " + resp);
39 for (int i = 0; i < 10; i++) {
40 final int ii = i; // required for nested class
41 HttpRequest req2 = new GatewayRequest(conn, "opensrf.math", method);
44 new HttpRequestHandler() {
46 // called once per response
47 public void onResponse(HttpRequest req, Object resp) {
48 System.out.println("Async Response: " + ii + " : " + resp);
51 // called after all responses have been received
52 // used primarily when you don't know how many responses will be returned
53 public void onComplete(HttpRequest req) {
54 System.out.println("Async Request complete : " + ii);
58 public void onError(HttpRequest req, Exception ex) {
59 if (ex instanceof java.io.IOException)
60 System.err.println("Trouble communicating with gateway server!");
67 } catch (java.net.MalformedURLException ex) {
68 System.err.println("Malformed Gateway URL! " + args[0]);
71 } catch (java.io.IOException ex) {
72 System.err.println("Trouble communicating with gateway server!");