hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r538889 - in /jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl: client/DefaultClientRequestDirector.java conn/DefaultClientConnection.java
Date Thu, 17 May 2007 12:36:29 GMT
Author: olegk
Date: Thu May 17 05:36:28 2007
New Revision: 538889

URL: http://svn.apache.org/viewvc?view=rev&rev=538889
Log:
Fixed bug in connection management code. Connection keep-alive strategy now gets correctly
applied prior to executing a follow-up request 

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?view=diff&rev=538889&r1=538888&r2=538889
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
Thu May 17 05:36:28 2007
@@ -277,9 +277,15 @@
 
                 HttpRoute route = roureq.getRoute();
 
-                if (managedConn == null || !managedConn.isOpen()) {
+                // Allocate connection if needed
+                if (managedConn == null) {
                     managedConn = allocateConnection(route);
                 }
+                // Reopen connection if needed
+                if (!managedConn.isOpen()) {
+                    managedConn.open(route, context, params);
+                }
+                
                 try {
                     establishRoute(route, context);
                 } catch (TunnelRefusedException ex) {
@@ -369,10 +375,15 @@
                 if (followup == null) {
                     done = true;
                 } else {
-                    // Make sure the response body is fully consumed, if present
-                    HttpEntity entity = response.getEntity();
-                    if (entity != null) {
-                        entity.consumeContent();
+                    if (this.reuseStrategy.keepAlive(response, context)) {
+                        LOG.debug("Connection kept alive");
+                        // Make sure the response body is fully consumed, if present
+                        HttpEntity entity = response.getEntity();
+                        if (entity != null) {
+                            entity.consumeContent();
+                        }
+                    } else {
+                        managedConn.close();
                     }
                     // check if we can use the same connection for the followup
                     if ((managedConn != null) &&
@@ -381,6 +392,7 @@
                         //@@@ need to consume response body first?
                         //@@@ or let that be done in handleResponse(...)?
                         connManager.releaseConnection(managedConn);
+                        managedConn = null;
                     }
                     roureq = followup;
                 }
@@ -799,10 +811,18 @@
             final AuthState authState, 
             final HttpHost host,
             final HttpState state) {
+        
+        String hostname = host.getHostName();
+        int port = host.getPort();
+        if (port < 0) {
+            Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
+            port = scheme.getDefaultPort();
+        }
+        
         AuthScheme authScheme = authState.getAuthScheme();
         AuthScope authScope = new AuthScope(
-                host.getHostName(),
-                host.getPort(),
+                hostname,
+                port,
                 authScheme.getRealm(), 
                 authScheme.getSchemeName());  
         

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java?view=diff&rev=538889&r1=538888&r2=538889
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/DefaultClientConnection.java
Thu May 17 05:36:28 2007
@@ -67,6 +67,8 @@
     private static final Log HEADERS_LOG = LogFactory.getLog("org.apache.http.conn.headers");
     private static final Log WIRE_LOG = LogFactory.getLog("org.apache.http.conn.wire");
     
+    private static final Log LOG = LogFactory.getLog(DefaultClientConnection.class);
+    
     /** The unconnected socket between announce and open. */
     private volatile Socket announcedSocket;
 
@@ -116,9 +118,9 @@
      *
      * @throws IOException      in case of a problem
      */
-    public void shutdown()
-        throws IOException {
-
+    public void shutdown() throws IOException {
+        LOG.debug("Connection shut down");
+        
         Socket sock = announcedSocket; // copy volatile attribute
         if (sock != null)
             sock.close();
@@ -126,6 +128,12 @@
         super.shutdown();
 
     } // shutdown
+
+    
+    public void close() throws IOException {
+        LOG.debug("Connection closed");
+        super.close();
+    }
 
 
     protected HttpDataReceiver createHttpDataReceiver(



Mime
View raw message