You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mb...@apache.org on 2005/07/31 20:10:43 UTC

svn commit: r226671 - in /jakarta/commons/proper/httpclient/trunk: release_notes.txt src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java

Author: mbecke
Date: Sun Jul 31 11:10:38 2005
New Revision: 226671

URL: http://svn.apache.org/viewcvs?rev=226671&view=rev
Log:
SimpleHttpConnectionManager now logs warnings when it detects it is being used incorrectly. 

PR: 35815
Contributed by Michael Becke
Reviewed by Ortwin Glueck and Oleg Kalnichevski

Modified:
    jakarta/commons/proper/httpclient/trunk/release_notes.txt
    jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java
    jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java

Modified: jakarta/commons/proper/httpclient/trunk/release_notes.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/release_notes.txt?rev=226671&r1=226670&r2=226671&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/release_notes.txt (original)
+++ jakarta/commons/proper/httpclient/trunk/release_notes.txt Sun Jul 31 11:10:38 2005
@@ -2,8 +2,11 @@
 Changes since Release Candidate 3:
 
  * 35642 - Do not retry if host is unreachable. This ensures a connection timeout
-           will be obeied.
+           will be obeyed.
            Contributed by Ortwin Glück <oglueck at apache.org>
+           
+ * 35815 - SimpleHttpConnectionManager now logs warnings when it detects it is
+           being used incorrectly. 
 
 Release 3.0 Release Candidate 3
 -------------------

Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java?rev=226671&r1=226670&r2=226671&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java Sun Jul 31 11:10:38 2005
@@ -33,6 +33,8 @@
 import java.io.InputStream;
 
 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * A connection manager that provides access to a single HttpConnection.  This
@@ -49,6 +51,13 @@
  */
 public class SimpleHttpConnectionManager implements HttpConnectionManager {
 
+    private static final Log LOG = LogFactory.getLog(SimpleHttpConnectionManager.class);
+
+    private static final String MISUSE_MESSAGE = 
+        "SimpleHttpConnectionManager being used incorrectly.  Be sure that"
+        + " HttpMethod.releaseConnection() is always called and that only one thread"
+        + " and/or method is using this connection manager at a time.";
+    
     /**
      * Since the same connection is about to be reused, make sure the
      * previous request was completely processed, and if not
@@ -81,6 +90,14 @@
      */
     private long idleStartTime = Long.MAX_VALUE;
     
+    /**
+     * Used to test if {@link #httpConnection} is currently in use 
+     * (i.e. checked out).  This is only used as a sanity check to help
+     * debug cases where this connection manager is being used incorrectly.
+     * It will not be used to enforce thread safety.
+     */
+    private volatile boolean inUse = false;
+    
     public SimpleHttpConnectionManager() {
     }
     
@@ -157,6 +174,9 @@
 
         // remove the connection from the timeout handler
         idleStartTime = Long.MAX_VALUE;
+
+        if (inUse) LOG.warn(MISUSE_MESSAGE);
+        inUse = true;
         
         return httpConnection;
     }
@@ -181,6 +201,9 @@
 
         finishLastResponse(httpConnection);
         
+        if (!inUse) LOG.warn(MISUSE_MESSAGE);
+        inUse = false;
+
         // track the time the connection was made idle
         idleStartTime = System.currentTimeMillis();
     }

Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java?rev=226671&r1=226670&r2=226671&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/auth/TestBasicAuth.java Sun Jul 31 11:10:38 2005
@@ -61,6 +61,14 @@
  */
 public class TestBasicAuth extends HttpClientTestBase {
 
+    static {
+        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
+        System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
+        System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
+        System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
+
+    }
+    
     // ------------------------------------------------------------ Constructor
     public TestBasicAuth(final String testName) throws IOException {
         super(testName);
@@ -75,8 +83,10 @@
     // ------------------------------------------------------- TestCase Methods
 
     public static Test suite() {
+
+        
         TestSuite suite = new TestSuite(TestBasicAuth.class);
-        ProxyTestDecorator.addTests(suite);
+//        ProxyTestDecorator.addTests(suite);
         return suite;
     }
 
@@ -306,6 +316,7 @@
     }
 
     public void testBasicAuthenticationWithMutlipleRealms2() throws Exception {
+        System.out.println("NOW");
         UsernamePasswordCredentials creds = 
             new UsernamePasswordCredentials("testuser2", "testpass2");
         



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org