hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1441414 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/conn/ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/main/java/org/apache/http/impl/conn/ httpclient/src/main/java/org/apache/...
Date Fri, 01 Feb 2013 12:06:34 GMT
Author: olegk
Date: Fri Feb  1 12:06:33 2013
New Revision: 1441414

URL: http://svn.apache.org/viewvc?rev=1441414&view=rev
Log:
HTTPCLIENT-1311: made sure the current thread is re-interrupted if InterruptedException is
caught and re-thrown as a different exception; tweaked connection manager API related to interruptable
operations

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Feb  1 12:06:33 2013
@@ -1,6 +1,9 @@
 Changes since 4.3 ALPHA1
 -------------------
 
+* [HTTPCLIENT-1311] Interrupt flag is not preserved where InterruptedException is caught.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [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 <olegk at apache.org>

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ConnectionRequest.java
Fri Feb  1 12:06:33 2013
@@ -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 exten
      *         if the calling thread is interrupted while waiting
      */
     HttpClientConnection get(long timeout, TimeUnit tunit)
-        throws InterruptedException, ConnectionPoolTimeoutException;
+        throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException;
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
Fri Feb  1 12:06:33 2013
@@ -162,7 +162,8 @@ public class AutoRetryHttpClient impleme
                         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;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Fri Feb  1 12:06:33 2013
@@ -420,9 +420,8 @@ public class DefaultRequestDirector impl
                     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)) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
Fri Feb  1 12:06:33 2013
@@ -223,7 +223,7 @@ public class PoolingHttpClientConnection
 
             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 PoolingHttpClientConnection
     protected HttpClientConnection leaseConnection(
             final Future<CPoolEntry> 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 PoolingHttpClientConnection
                 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");
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
Fri Feb  1 12:06:33 2013
@@ -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 C
             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);

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MinimalClientExec.java
Fri Feb  1 12:06:33 2013
@@ -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 implement
             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);

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
Fri Feb  1 12:06:33 2013
@@ -82,7 +82,8 @@ public class ServiceUnavailableRetryExec
                         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;

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java?rev=1441414&r1=1441413&r2=1441414&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
Fri Feb  1 12:06:33 2013
@@ -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 ex
             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);
     }



Mime
View raw message