hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1231237 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src: main/java/org/apache/http/impl/nio/client/ main/java/org/apache/http/impl/nio/conn/ test/java/org/apache/http/impl/nio/client/
Date Fri, 13 Jan 2012 18:47:22 GMT
Author: olegk
Date: Fri Jan 13 18:47:22 2012
New Revision: 1231237

URL: http://svn.apache.org/viewvc?rev=1231237&view=rev
Log:
HTTPASYNC-11: Protocol handler must not invalidate the execution handler upon connection close
(message exchange may span accross multiple non-persistent connections)

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingClientProtocolHandler.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingAsyncClientConnectionManager.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1231237&r1=1231236&r2=1231237&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
Fri Jan 13 18:47:22 2012
@@ -396,6 +396,8 @@ class DefaultAsyncRequestDirector<T> imp
                 }
                 this.managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS);
             } else {
+                this.log.debug("Connection cannot be kept alive");
+                this.managedConn.unmarkReusable();
                 invalidateAuthIfSuccessful(this.proxyAuthState);
                 invalidateAuthIfSuccessful(this.targetAuthState);
             }

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingClientProtocolHandler.java?rev=1231237&r1=1231236&r2=1231237&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingClientProtocolHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingClientProtocolHandler.java
Fri Jan 13 18:47:22 2012
@@ -63,7 +63,6 @@ class LoggingClientProtocolHandler exten
         if (this.log.isDebugEnabled()) {
             this.log.debug(conn + ": Disconnected");
         }
-        super.closed(conn);
     }
 
     @Override

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingAsyncClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingAsyncClientConnectionManager.java?rev=1231237&r1=1231236&r2=1231237&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingAsyncClientConnectionManager.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingAsyncClientConnectionManager.java
Fri Jan 13 18:47:22 2012
@@ -208,15 +208,17 @@ public class PoolingAsyncClientConnectio
                         }
                     }
                 }
-                entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
-                if (this.log.isDebugEnabled()) {
-                    String s;
-                    if (keepalive > 0) {
-                        s = "for " + keepalive + " " + tunit;
-                    } else {
-                        s = "indefinitely";
+                if (managedConn.isOpen()) {
+                    entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
+                    if (this.log.isDebugEnabled()) {
+                        String s;
+                        if (keepalive > 0) {
+                            s = "for " + keepalive + " " + tunit;
+                        } else {
+                            s = "indefinitely";
+                        }
+                        this.log.debug("Connection " + format(entry) + " can be kept alive
" + s);
                     }
-                    this.log.debug("Connection " + format(entry) + " can be kept alive "
+ s);
                 }
             } finally {
                 this.pool.release(entry, managedConn.isMarkedReusable());

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java?rev=1231237&r1=1231236&r2=1231237&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
Fri Jan 13 18:47:22 2012
@@ -150,6 +150,17 @@ public class TestClientAuthentication ex
 
     static class AuthHandler implements HttpRequestHandler {
 
+        private final boolean keepAlive;
+        
+        AuthHandler(boolean keepAlive) {
+            super();
+            this.keepAlive = keepAlive;
+        }
+        
+        AuthHandler() {
+            this(true);
+        }
+        
         public void handle(
                 final HttpRequest request,
                 final HttpResponse response,
@@ -162,6 +173,8 @@ public class TestClientAuthentication ex
                 NStringEntity entity = new NStringEntity("success", HTTP.ASCII);
                 response.setEntity(entity);
             }
+            response.setHeader(HTTP.CONN_DIRECTIVE, 
+                    this.keepAlive ? HTTP.CONN_KEEP_ALIVE : HTTP.CONN_CLOSE);
         }
 
     }
@@ -312,6 +325,27 @@ public class TestClientAuthentication ex
     }
 
     @Test
+    public void testBasicAuthenticationSuccessNonPersistentConnection() throws Exception
{
+        HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+        registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler(false)));
+        HttpHost target = start(registry, null);
+
+        TestCredentialsProvider credsProvider = new TestCredentialsProvider(
+                new UsernamePasswordCredentials("test", "test"));
+        this.httpclient.setCredentialsProvider(credsProvider);
+
+        HttpGet httpget = new HttpGet("/");
+        httpget.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
+        Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
+        HttpResponse response = future.get();
+        Assert.assertNotNull(response);
+        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+        AuthScope authscope = credsProvider.getAuthScope();
+        Assert.assertNotNull(authscope);
+        Assert.assertEquals("test realm", authscope.getRealm());
+    }
+
+    @Test
     public void testBasicAuthenticationSuccessWithNonRepeatableExpectContinue() throws Exception
{
         HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
         registry.register("*", new BufferingAsyncRequestHandler(new AuthHandler()));



Mime
View raw message