java gateway : wrap all onFoo handlers in try
authorBill Erickson <berick@esilibrary.com>
Mon, 19 Mar 2012 13:10:23 +0000 (09:10 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 19 Mar 2012 13:10:23 +0000 (09:10 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/java/org/opensrf/net/http/HttpConnection.java

index 588abb7..c40b9f9 100644 (file)
@@ -37,7 +37,9 @@ public class HttpConnection {
     }
 
     /** 
-     * Set the maximum number of actively communicating threads allowed 
+     * Set the maximum number of actively communicating (async) threads allowed.
+     *
+     * This has no effect on synchronous communication.
      */
     public void setMaxThreads(int max) {
         maxThreads = max;
@@ -70,25 +72,22 @@ public class HttpConnection {
         Runnable r = new Runnable() {
             public void run() {
                 Object response;
-                boolean failed = false;
 
                 try {
                     request.send();
                     while ((response = request.recv()) != null)
                         request.handler.onResponse(request, response);
 
+                    request.handler.onComplete(request);
+
                 } catch (Exception ex) {
                     request.handler.onError(request, ex);
-                    failed = true;
 
                 } finally {
                     // server communication has completed
                     activeThreads--;
                 }
 
-                if (!failed)
-                    request.handler.onComplete(request);
-
                 if (activeThreads < maxThreads) {
                     try {
                         manageAsyncRequest(pendingThreadQueue.remove());