commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbe...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol Protocol.java SSLProtocolSocketFactory.java ProtocolSocketFactory.java DefaultProtocolSocketFactory.java
Date Fri, 30 Jan 2004 19:23:15 GMT
mbecke      2004/01/30 11:23:15

  Modified:    httpclient/src/test/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH TestNoHost.java
               httpclient/src/java/org/apache/commons/httpclient/protocol
                        Tag: HTTPCLIENT_2_0_BRANCH Protocol.java
                        SSLProtocolSocketFactory.java
                        ProtocolSocketFactory.java
                        DefaultProtocolSocketFactory.java
  Added:       httpclient/src/test/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH TestEquals.java
  Log:
  Fixed possible connection leak caused by lack of equals() and hashCode() on protocol
  socket factories.
  
  PR: 26139
  Submitted by: Michael Becke
  Reviewed by: Oleg Kalnichevski and Roland Weber
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.22.2.1  +5 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java
  
  Index: TestNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v
  retrieving revision 1.22
  retrieving revision 1.22.2.1
  diff -u -r1.22 -r1.22.2.1
  --- TestNoHost.java	17 Apr 2003 11:34:19 -0000	1.22
  +++ TestNoHost.java	30 Jan 2004 19:23:15 -0000	1.22.2.1
  @@ -104,6 +104,7 @@
           suite.addTest(TestRequestLine.suite());
           suite.addTest(TestPartsNoHost.suite());
           suite.addTest(TestMethodCharEncoding.suite());
  +        suite.addTest(TestEquals.suite());
           return suite;
       }
   
  
  
  
  No                   revision
  
  Index: TestNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v
  retrieving revision 1.22
  retrieving revision 1.22.2.1
  diff -u -r1.22 -r1.22.2.1
  --- TestNoHost.java	17 Apr 2003 11:34:19 -0000	1.22
  +++ TestNoHost.java	30 Jan 2004 19:23:15 -0000	1.22.2.1
  @@ -104,6 +104,7 @@
           suite.addTest(TestRequestLine.suite());
           suite.addTest(TestPartsNoHost.suite());
           suite.addTest(TestMethodCharEncoding.suite());
  +        suite.addTest(TestEquals.suite());
           return suite;
       }
   
  
  
  
  No                   revision
  
  Index: TestNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v
  retrieving revision 1.22
  retrieving revision 1.22.2.1
  diff -u -r1.22 -r1.22.2.1
  --- TestNoHost.java	17 Apr 2003 11:34:19 -0000	1.22
  +++ TestNoHost.java	30 Jan 2004 19:23:15 -0000	1.22.2.1
  @@ -104,6 +104,7 @@
           suite.addTest(TestRequestLine.suite());
           suite.addTest(TestPartsNoHost.suite());
           suite.addTest(TestMethodCharEncoding.suite());
  +        suite.addTest(TestEquals.suite());
           return suite;
       }
   
  
  
  
  1.1.2.1   +4 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestEquals.java
  
  Index: TestEquals.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestEquals.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- TestEquals.java	27 Jan 2004 22:18:49 -0000	1.1
  +++ TestEquals.java	30 Jan 2004 19:23:15 -0000	1.1.2.1
  @@ -1,13 +1,13 @@
   package org.apache.commons.httpclient;
   
  +import junit.framework.Test;
  +import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +
   import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
   import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
   import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory;
  -
  -import junit.framework.Test;
  -import junit.framework.TestCase;
  -import junit.framework.TestSuite;
   
   /**
    */
  
  
  
  No                   revision
  No                   revision
  1.5.2.1   +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java
  
  Index: Protocol.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- Protocol.java	31 Jan 2003 00:33:36 -0000	1.5
  +++ Protocol.java	30 Jan 2004 19:23:15 -0000	1.5.2.1
  @@ -165,14 +165,14 @@
   
           if ("http".equals(id)) {
               final Protocol http 
  -                = new Protocol("http", new DefaultProtocolSocketFactory(), 80);
  +                = new Protocol("http", DefaultProtocolSocketFactory.getSocketFactory(),
80);
               Protocol.registerProtocol("http", http);
               return http;
           }
   
           if ("https".equals(id)) {
               final Protocol https 
  -                = new Protocol("https", new SSLProtocolSocketFactory(), 443);
  +                = new Protocol("https", SSLProtocolSocketFactory.getSocketFactory(), 443);
               Protocol.registerProtocol("https", https);
               return https;
           }
  
  
  
  1.5.2.1   +30 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java
  
  Index: SSLProtocolSocketFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- SSLProtocolSocketFactory.java	31 Jan 2003 00:33:36 -0000	1.5
  +++ SSLProtocolSocketFactory.java	30 Jan 2004 19:23:15 -0000	1.5.2.1
  @@ -81,6 +81,19 @@
   public class SSLProtocolSocketFactory implements SecureProtocolSocketFactory {
   
       /**
  +     * The factory singleton.
  +     */
  +    private static final SSLProtocolSocketFactory factory = new SSLProtocolSocketFactory();
  +    
  +    /**
  +     * Gets an singleton instance of the SSLProtocolSocketFactory.
  +     * @return a SSLProtocolSocketFactory
  +     */
  +    static SSLProtocolSocketFactory getSocketFactory() {
  +        return factory;
  +    }    
  +    
  +    /**
        * Constructor for SSLProtocolSocketFactory.
        */
       public SSLProtocolSocketFactory() {
  @@ -132,4 +145,18 @@
           );
       }
   
  +    /**
  +     * All instances of SSLProtocolSocketFactory are the same.
  +     */
  +    public boolean equals(Object obj) {
  +        return ((obj != null) && obj.getClass().equals(SSLProtocolSocketFactory.class));
  +    }
  +
  +    /**
  +     * All instances of SSLProtocolSocketFactory have the same hash code.
  +     */
  +    public int hashCode() {
  +        return SSLProtocolSocketFactory.class.hashCode();
  +    }    
  +    
   }
  
  
  
  1.5.2.1   +9 -3      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java
  
  Index: ProtocolSocketFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- ProtocolSocketFactory.java	31 Jan 2003 00:33:36 -0000	1.5
  +++ ProtocolSocketFactory.java	30 Jan 2004 19:23:15 -0000	1.5.2.1
  @@ -71,6 +71,12 @@
   /**
    * A factory for creating Sockets.
    * 
  + * <p>Both {@link java.lang.Object#equals(java.lang.Object) Object.equals()} and

  + * {@link java.lang.Object#hashCode() Object.hashCode()} should be overridden appropriately.
 
  + * Protocol socket factories are used to uniquely identify <code>Protocol</code>s
and 
  + * <code>HostConfiguration</code>s, and <code>equals()</code> and
<code>hashCode()</code> are 
  + * required for the correct operation of some connection managers.</p>
  + * 
    * @see Protocol
    * 
    * @author Michael Becke
  
  
  
  1.5.2.1   +31 -4     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java
  
  Index: DefaultProtocolSocketFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- DefaultProtocolSocketFactory.java	31 Jan 2003 00:33:36 -0000	1.5
  +++ DefaultProtocolSocketFactory.java	30 Jan 2004 19:23:15 -0000	1.5.2.1
  @@ -70,7 +70,7 @@
   
   /**
    * The default class for creating protocol sockets.  This class just uses the
  - * Protocol constructors.
  + * {@link java.net.Socket socket} constructors.
    * 
    * @author Michael Becke
    * 
  @@ -79,6 +79,19 @@
   public class DefaultProtocolSocketFactory implements ProtocolSocketFactory {
   
       /**
  +     * The factory singleton.
  +     */
  +    private static final DefaultProtocolSocketFactory factory = new DefaultProtocolSocketFactory();
  +    
  +    /**
  +     * Gets an singleton instance of the DefaultProtocolSocketFactory.
  +     * @return a DefaultProtocolSocketFactory
  +     */
  +    static DefaultProtocolSocketFactory getSocketFactory() {
  +        return factory;
  +    }
  +    
  +    /**
        * Constructor for DefaultProtocolSocketFactory.
        */
       public DefaultProtocolSocketFactory() {
  @@ -103,6 +116,20 @@
       public Socket createSocket(String host, int port)
           throws IOException, UnknownHostException {
           return new Socket(host, port);
  +    }
  +
  +    /**
  +     * All instances of DefaultProtocolSocketFactory are the same.
  +     */
  +    public boolean equals(Object obj) {
  +        return ((obj != null) && obj.getClass().equals(DefaultProtocolSocketFactory.class));
  +    }
  +
  +    /**
  +     * All instances of DefaultProtocolSocketFactory have the same hash code.
  +     */
  +    public int hashCode() {
  +        return DefaultProtocolSocketFactory.class.hashCode();
       }
   
   }
  
  
  

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


Mime
View raw message