? src/java/org/apache/commons/httpclient/methods/NullMethod.java Index: src/java/org/apache/commons/httpclient/HttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v retrieving revision 1.85 diff -u -r1.85 HttpConnection.java --- src/java/org/apache/commons/httpclient/HttpConnection.java 22 Feb 2004 18:08:45 -0000 1.85 +++ src/java/org/apache/commons/httpclient/HttpConnection.java 2 Apr 2004 22:50:28 -0000 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v 1.85 2004/02/22 18:08:45 olegk Exp $ - * $Revision: 1.85 $ - * $Date: 2004/02/22 18:08:45 $ + * $Header: /usr/local/cvsroot/httpclient-2.1m1-ecm-branch/httpclient-2.1m1-ecm-branch/src/java/org/apache/commons/httpclient/HttpConnection.java,v 1.5 2004/04/02 22:21:01 msample Exp $ + * $Revision: 1.5 $ + * $Date: 2004/04/02 22:21:01 $ * * ==================================================================== * @@ -29,6 +29,14 @@ * */ +/* + * as per the Apache License: + * + * THIS FILE HAS BEEN MODIFIED BY ECMARKET FROM THE VERSION RELEASED + * IN THE JAKARTA COMMONS HTTPUTILS PACKAGE + */ + + package org.apache.commons.httpclient; import java.io.BufferedOutputStream; @@ -90,7 +98,7 @@ * @author Eric E Johnson * @author Laura Werner * - * @version $Revision: 1.85 $ $Date: 2004/02/22 18:08:45 $ + * @version $Revision: 1.5 $ $Date: 2004/04/02 22:21:01 $ */ public class HttpConnection { @@ -449,7 +457,7 @@ // assume the connection is not stale. isStale = false; try { - if (inputStream.available() == 0) { + if ( ( inputStream != null ) && (inputStream.available() == 0) ) { try { socket.setSoTimeout(1); int byteRead = inputStream.read(); @@ -641,7 +649,7 @@ // proxied connection final ProtocolSocketFactory socketFactory = (isSecure() && isProxied() - ? new DefaultProtocolSocketFactory() + ? protocolInUse.getProxyFactory() : protocolInUse.getSocketFactory()); if (this.params.getConnectionTimeout() == 0) { @@ -829,7 +837,7 @@ throws IOException { LOG.trace("enter HttpConnection.isResponseAvailable()"); assertOpen(); - return this.inputStream.available() > 0; + return ( this.inputStream != null ) && ( this.inputStream.available() > 0 ); } /** @@ -847,7 +855,10 @@ LOG.trace("enter HttpConnection.isResponseAvailable(int)"); assertOpen(); boolean result = false; - if (this.inputStream.available() > 0) { + if ( this.inputStream == null ) { + return false; + } + else if ( this.inputStream.available() > 0 ) { result = true; } else { try { @@ -1135,6 +1146,41 @@ this.locked = locked; } + + /** + * Removes and returns the java.net.Socket associated with this + * connection to enable tunneling other protocols through web + * proxies. + * + *

Once you have called this method, this HttpConnection will + * be disconnected.

+ * + *

@see java.org.apache.commons.httpclient.NullMethod for how + * to use HttpClient to tunnel non-HTTP protocols through a web + * proxy.

+ * + * @return Socket underlying HTTP Connection. + */ + public Socket detachSocket() { + Socket retVal = this.socket; + + // set socket to null so subsequent release on this connection + // doesn't close the socket. + + this.socket = null; + inputStream = null; + outputStream = null; + setLastResponseInputStream( null ); + isOpen = true; + used = false; + tunnelEstablished = false; + usingSecureSocket = false; + setLocked( false ); + //getHttpConnectionManager().releaseConnection( this ); + return retVal; + } + + // ------------------------------------------------------ Protected Methods /** @@ -1172,6 +1218,7 @@ Socket temp = socket; socket = null; try { + LOG.debug("Closing Socket"); temp.close(); } catch (Exception ex) { LOG.debug("Exception caught when closing socket", ex); Index: src/java/org/apache/commons/httpclient/protocol/Protocol.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java,v retrieving revision 1.9 diff -u -r1.9 Protocol.java --- src/java/org/apache/commons/httpclient/protocol/Protocol.java 22 Feb 2004 18:08:49 -0000 1.9 +++ src/java/org/apache/commons/httpclient/protocol/Protocol.java 2 Apr 2004 22:50:33 -0000 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/Protocol.java,v 1.9 2004/02/22 18:08:49 olegk Exp $ - * $Revision: 1.9 $ - * $Date: 2004/02/22 18:08:49 $ + * $Header: /usr/local/cvsroot/httpclient-2.1m1-ecm-branch/httpclient-2.1m1-ecm-branch/src/java/org/apache/commons/httpclient/protocol/Protocol.java,v 1.4 2004/04/02 22:16:30 msample Exp $ + * $Revision: 1.4 $ + * $Date: 2004/04/02 22:16:30 $ * * ==================================================================== * @@ -28,6 +28,15 @@ * [Additional notices, if required by prior licensing conditions] * */ + +/* + * as per the Apache License: + * + * THIS FILE HAS BEEN MODIFIED BY ECMARKET FROM THE VERSION RELEASED + * IN THE JAKARTA COMMONS HTTPUTILS PACKAGE + */ + + package org.apache.commons.httpclient.protocol; import java.util.Collections; @@ -160,6 +169,16 @@ /** True if this protocol is secure */ private boolean secure; + + /** + * Used when using a proxy to the to establish initial connection + * before wrapping with an SSL Socket or other provided by the + * SecureProtoclSocketFactory. Defaults to + * DefaultProtocolSocketFactory + */ + private ProtocolSocketFactory proxyFactory + = DefaultProtocolSocketFactory.getSocketFactory(); + /** * Constructs a new Protocol. Whether the created protocol is secure depends on @@ -203,6 +222,38 @@ SecureProtocolSocketFactory factory, int defaultPort) { this(scheme, (ProtocolSocketFactory) factory, defaultPort); } + + + /** + * Constructs a new, secure Protocol that uses the provided + * proxySocket Factory to initially establish the conection when a + * proxy is used instead of the DefaultProtocolSocketFactory. + * + * @param scheme the scheme (e.g. http, https) + * @param factory the factory for creating sockets for communication using + * this protocol + * @param defaultPort the port this protocol defaults to + * + * @param proxyFactory used only when going through a web proxy to + * establish the connection to the proxy. The secure factory is + * then used to take the socket from this factory and present + * another that hides the details of any inserted protocol such as + * SSL. The secure factory may simply return the same Socket if no + * protocol needs to be inserted, for example when tunnelling + * another protocl through a web proxy. + */ + public Protocol(String scheme, + SecureProtocolSocketFactory factory, + int defaultPort, + ProtocolSocketFactory proxyFactory ) { + this(scheme, (ProtocolSocketFactory) factory, defaultPort); + + if ( proxyFactory == null ) { + throw new IllegalArgumentException("proxyFactory is null"); + } + this.proxyFactory = proxyFactory; + } + /** * Returns the defaultPort. @@ -236,6 +287,15 @@ public boolean isSecure() { return secure; } + + /** + * Returns the proxyFactory + * @return The proxyFactory + */ + public ProtocolSocketFactory getProxyFactory() { + return proxyFactory; + } + /** * Resolves the correct port for this protocol. Returns the given port if