Index: src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java =================================================================== retrieving revision 1.5 diff -u -r1.5 DefaultProtocolSocketFactory.java --- src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java 31 Jan 2003 00:33:36 -0000 1.5 +++ src/java/org/apache/commons/httpclient/protocol/DefaultProtocolSocketFactory.java 24 Jan 2004 15:44:38 -0000 @@ -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(); } } Index: src/java/org/apache/commons/httpclient/protocol/Protocol.java =================================================================== retrieving revision 1.7 diff -u -r1.7 Protocol.java --- src/java/org/apache/commons/httpclient/protocol/Protocol.java 10 Nov 2003 14:33:13 -0000 1.7 +++ src/java/org/apache/commons/httpclient/protocol/Protocol.java 24 Jan 2004 15:44:39 -0000 @@ -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; } Index: src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java =================================================================== retrieving revision 1.5 diff -u -r1.5 ProtocolSocketFactory.java --- src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java 31 Jan 2003 00:33:36 -0000 1.5 +++ src/java/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.java 24 Jan 2004 15:44:39 -0000 @@ -71,6 +71,12 @@ /** * A factory for creating Sockets. * + *
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 Protocols and
+ * HostConfigurations, and equals() and hashCode() are
+ * required for the correct operation of some connection managers.