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) throws java.net.MalformedURLException {
15 if (args.length == 0) {
16 System.err.println("Please provide a gateway URL: e.g. http://example.org/osrf-gateway-v1");
20 // configure the connection
21 HttpConnection conn = new HttpConnection(args[0]);
23 Method method = new Method("opensrf.system.echo");
24 method.addParam("Hello, Gateway");
25 method.addParam(new Integer(12345));
26 method.addParam(new Boolean(true));
27 method.addParam(Arrays.asList(8,6,7,5,3,0,9));
30 HttpRequest req = new GatewayRequest(conn, "opensrf.math", method).send();
32 while ( (resp = req.recv()) != null) {
33 System.out.println("Sync Response: " + resp);
36 // exceptions are captured instead of thrown,
37 // primarily to better support async requests
39 req.getFailure().printStackTrace();
44 for (int i = 0; i < 10; i++) {
45 final int ii = i; // required for nested class
46 HttpRequest req2 = new GatewayRequest(conn, "opensrf.math", method);
48 new HttpRequestHandler() {
49 public void onResponse(HttpRequest req, Object resp) {
50 System.out.println("Async Response: " + ii + " : " + resp);