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);
+ }
}
- }
- );
+ );
+ }
}
}