diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 01bbf2e7c..9ff33d54c 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes since 4.3 ALPHA1 ------------------- +* [HTTPCLIENT-1311] Interrupt flag is not preserved where InterruptedException is caught. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-1312] Zero length content entities with a Content-Encoding header cause an I/O error when an attempt is made to consume such entity. Contributed by Oleg Kalnichevski diff --git a/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java b/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java index 3e37baef6..6f8908e69 100644 --- a/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java +++ b/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java @@ -27,6 +27,7 @@ package org.apache.http.conn; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.apache.http.HttpClientConnection; @@ -63,6 +64,6 @@ public interface ConnectionRequest extends Cancellable { * if the calling thread is interrupted while waiting */ HttpClientConnection get(long timeout, TimeUnit tunit) - throws InterruptedException, ConnectionPoolTimeoutException; + throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException; } diff --git a/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java index 38aa16d3e..b24d424da 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java @@ -162,7 +162,8 @@ public class AutoRetryHttpClient implements HttpClient { log.trace("Wait for " + nextInterval); Thread.sleep(nextInterval); } catch (final InterruptedException e) { - throw new InterruptedIOException(e.getMessage()); + Thread.currentThread().interrupt(); + throw new InterruptedIOException(); } } else { return response; diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java index 597bf2342..6f81bec8f 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java @@ -420,9 +420,8 @@ public class DefaultRequestDirector implements RequestDirector { try { managedConn = connRequest.getConnection(timeout, TimeUnit.MILLISECONDS); } catch(final InterruptedException interrupted) { - final InterruptedIOException iox = new InterruptedIOException(); - iox.initCause(interrupted); - throw iox; + Thread.currentThread().interrupt(); + throw new InterruptedIOException(); } if (HttpConnectionParams.isStaleCheckingEnabled(params)) { diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java b/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java index bdd1b62d8..adeb03f8f 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java @@ -223,7 +223,7 @@ public class PoolingHttpClientConnectionManager public HttpClientConnection get( final long timeout, - final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { + final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { return leaseConnection(future, timeout, tunit); } @@ -234,7 +234,7 @@ public class PoolingHttpClientConnectionManager protected HttpClientConnection leaseConnection( final Future future, final long timeout, - final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException { + final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { CPoolEntry entry; try { entry = future.get(timeout, tunit); @@ -246,14 +246,6 @@ public class PoolingHttpClientConnectionManager this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute())); } return CPoolProxy.newProxy(entry); - } catch (final ExecutionException ex) { - Throwable cause = ex.getCause(); - if (cause == null) { - cause = ex; - } - final InterruptedException intex = new InterruptedException(); - intex.initCause(cause); - throw intex; } catch (final TimeoutException ex) { throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool"); } diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java index 91db53a9a..c4d05b618 100644 --- a/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java @@ -29,6 +29,7 @@ package org.apache.http.impl.execchain; import java.io.IOException; import java.io.InterruptedIOException; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; @@ -167,7 +168,14 @@ public class MainClientExec implements ClientExecChain { final int timeout = config.getConnectionRequestTimeout(); managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS); } catch(final InterruptedException interrupted) { + Thread.currentThread().interrupt(); throw new RequestAbortedException("Request aborted", interrupted); + } catch(final ExecutionException ex) { + Throwable cause = ex.getCause(); + if (cause == null) { + cause = ex; + } + throw new RequestAbortedException("Request execution failed", cause); } context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn); diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java index 9b5d50c78..9fcc25de9 100644 --- a/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java @@ -30,6 +30,7 @@ package org.apache.http.impl.execchain; import java.io.IOException; import java.io.InterruptedIOException; import java.net.URI; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; @@ -128,7 +129,14 @@ public class MinimalClientExec implements ClientExecChain { final int timeout = config.getConnectionRequestTimeout(); managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS); } catch(final InterruptedException interrupted) { + Thread.currentThread().interrupt(); throw new RequestAbortedException("Request aborted", interrupted); + } catch(final ExecutionException ex) { + Throwable cause = ex.getCause(); + if (cause == null) { + cause = ex; + } + throw new RequestAbortedException("Request execution failed", cause); } final ConnectionHolder releaseTrigger = new ConnectionHolder(log, connManager, managedConn); diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java index b9df54391..f8a1bc737 100644 --- a/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java @@ -82,7 +82,8 @@ public class ServiceUnavailableRetryExec implements ClientExecChain { this.log.trace("Wait for " + nextInterval); Thread.sleep(nextInterval); } catch (final InterruptedException e) { - throw new InterruptedIOException(e.getMessage()); + Thread.currentThread().interrupt(); + throw new InterruptedIOException(); } } else { return response; diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java index 8596fdff2..d6a33c443 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java @@ -32,6 +32,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -82,14 +83,14 @@ public class TestConnectionManagement extends LocalServerTestBase { final HttpClientConnectionManager mgr, final HttpRoute route, final long timeout, - final TimeUnit unit) throws ConnectionPoolTimeoutException, InterruptedException { + final TimeUnit unit) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException { final ConnectionRequest connRequest = mgr.requestConnection(route, null); return connRequest.get(timeout, unit); } private static HttpClientConnection getConnection( final HttpClientConnectionManager mgr, - final HttpRoute route) throws ConnectionPoolTimeoutException, InterruptedException { + final HttpRoute route) throws ConnectionPoolTimeoutException, ExecutionException, InterruptedException { final ConnectionRequest connRequest = mgr.requestConnection(route, null); return connRequest.get(0, null); }