diff --git a/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java b/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java index f07bf02..703294d 100644 --- a/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java +++ b/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java @@ -155,67 +155,72 @@ public class HTTPClientInvoker extends RemoteClientInvoker final HttpURLConnection conn = createURLConnection(validatedUrl, metadata); - int simulatedTimeout = getSimulatedTimeout(configuration, metadata, conn); - - if (simulatedTimeout <= 0) - { - return makeInvocation(conn, validatedUrl, invocation, metadata, marshaller, unmarshaller, true); - } - else - { - if (log.isTraceEnabled()) log.trace("using simulated timeout: " + simulatedTimeout); - class Holder {public Object value;} - final Holder resultHolder = new Holder(); - final Map finalMetadata = metadata; - - Runnable r = new Runnable() + try { + int simulatedTimeout = getSimulatedTimeout(configuration, metadata, conn); + + if (simulatedTimeout <= 0) { - public void run() + return makeInvocation(conn, validatedUrl, invocation, metadata, marshaller, unmarshaller, true); + } + else + { + if (log.isTraceEnabled()) log.trace("using simulated timeout: " + simulatedTimeout); + class Holder {public Object value;} + final Holder resultHolder = new Holder(); + final Map finalMetadata = metadata; + + Runnable r = new Runnable() { - try - { - resultHolder.value = useHttpURLConnection(conn, invocation, finalMetadata, marshaller, unmarshaller); - if (log.isTraceEnabled()) log.trace("result: " + resultHolder.value); - } - catch (Exception e) + public void run() { - resultHolder.value = e; - if (log.isTraceEnabled()) log.trace("exception: " + e); + try + { + resultHolder.value = useHttpURLConnection(conn, invocation, finalMetadata, marshaller, unmarshaller); + if (log.isTraceEnabled()) log.trace("result: " + resultHolder.value); + } + catch (Exception e) + { + resultHolder.value = e; + if (log.isTraceEnabled()) log.trace("exception: " + e); + } } + }; + + // BasicThreadPool timeout mechanism depends on the interrupted status of + // the running thread. + Thread.interrupted(); + + ThreadPool pool = getTimeoutThreadPool(); + WaitingTaskWrapper wrapper = new WaitingTaskWrapper(r, simulatedTimeout); + if (log.isTraceEnabled()) log.trace("starting task in thread pool"); + pool.runTaskWrapper(wrapper); + if (log.isTraceEnabled()) log.trace("task finished in thread pool"); + + Object result = resultHolder.value; + if (result == null) + { + if (log.isDebugEnabled()) log.debug("invocation timed out"); + Exception cause = new SocketTimeoutException("timed out"); + throw new CannotConnectException("Can not connect http client invoker.", cause); + } + else if (result instanceof IOException) + { + throw (IOException) result; + } + else if (result instanceof RuntimeException) + { + throw (RuntimeException) result; + } + else + { + if (log.isTraceEnabled()) log.trace("returning result: " + result); + return result; } - }; - - // BasicThreadPool timeout mechanism depends on the interrupted status of - // the running thread. - Thread.interrupted(); - - ThreadPool pool = getTimeoutThreadPool(); - WaitingTaskWrapper wrapper = new WaitingTaskWrapper(r, simulatedTimeout); - if (log.isTraceEnabled()) log.trace("starting task in thread pool"); - pool.runTaskWrapper(wrapper); - if (log.isTraceEnabled()) log.trace("task finished in thread pool"); - - Object result = resultHolder.value; - if (result == null) - { - if (log.isDebugEnabled()) log.debug("invocation timed out"); - Exception cause = new SocketTimeoutException("timed out"); - throw new CannotConnectException("Can not connect http client invoker.", cause); - } - else if (result instanceof IOException) - { - throw (IOException) result; - } - else if (result instanceof RuntimeException) - { - throw (RuntimeException) result; - } - else - { - if (log.isTraceEnabled()) log.trace("returning result: " + result); - return result; } } + finally { + conn.disconnect(); + } } protected Object makeInvocation(HttpURLConnection conn, String url, Object invocation,