Index: java/org/apache/commons/httpclient/HostConfiguration.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java,v retrieving revision 1.8 diff -u -r1.8 HostConfiguration.java --- java/org/apache/commons/httpclient/HostConfiguration.java 28 Jan 2003 04:40:20 -0000 1.8 +++ java/org/apache/commons/httpclient/HostConfiguration.java 6 Apr 2003 11:19:03 -0000 @@ -69,6 +69,7 @@ * * @author Michael Becke * @author Mike Bowler + * @author Oleg Kalnichevski * @since 2.0 */ public class HostConfiguration implements Cloneable { @@ -76,6 +77,9 @@ /** The host to use. */ private String host; + /** The virtual host to use. */ + private String virtualHost; + /** The port to use. */ private int port; @@ -100,6 +104,7 @@ public HostConfiguration() { this.host = null; + this.virtualHost = null; this.port = -1; this.protocol = null; this.hostSet = false; @@ -121,6 +126,7 @@ // having to negotiate the monitor for each method call synchronized (hostConfiguration) { this.host = hostConfiguration.getHost(); + this.virtualHost = hostConfiguration.getVirtualHost(); this.port = hostConfiguration.getPort(); this.protocol = hostConfiguration.getProtocol(); this.hostSet = hostConfiguration.isHostSet(); @@ -153,10 +159,25 @@ public synchronized boolean hostEquals(HttpConnection connection) { if (hostSet) { - return (host.equalsIgnoreCase(connection.getHost()) - && port == connection.getPort() - && protocol.equals(connection.getProtocol())); - + if (!this.host.equalsIgnoreCase(connection.getHost())) { + return false; + } + if (this.virtualHost != null) { + if (!this.virtualHost.equalsIgnoreCase(connection.getVirtualHost())) { + return false; + } + } else { + if (connection.getVirtualHost() != null) { + return false; + } + } + if (this.port != connection.getPort()) { + return false; + } + if (!this.protocol.equals(connection.getProtocol())) { + return false; + } + return true; } else { return false; } @@ -195,23 +216,25 @@ } /** - * Set the host - * @param host The host. + * Set the given host, port and protocol + * + * @param host the host, IP or DNS name * @param port The port * @param protocol The protocol. */ public synchronized void setHost(String host, int port, String protocol) { - setHost(host, port, Protocol.getProtocol(protocol)); + setHost(host, null, port, Protocol.getProtocol(protocol)); } /** - * Sets this configuration's host infomation. + * Set the given host, virtual host, port and protocol. * * @param host the host, IP or DNS name + * @param virtualHost the virtual host name * @param port the host port or -1 to use protocol default * @param protocol the protocol */ - public synchronized void setHost(String host, int port, + public synchronized void setHost(String host, String virtualHost, int port, Protocol protocol) { if (host == null) { @@ -222,6 +245,7 @@ } this.host = host; + this.virtualHost = virtualHost; this.port = port == -1 ? protocol.getDefaultPort() : port; this.protocol = protocol; @@ -230,6 +254,39 @@ } /** + * Set the given host, port and protocol. + * + * @param host the host, IP or DNS name + * @param port The port + * @param protocol the protocol + */ + public synchronized void setHost(String host, int port, Protocol protocol) { + setHost(host, null, port, protocol); + } + + + /** + * Set the given host and port. Select default protocol. + * @param host the host, IP or DNS name + * @param port The port + */ + public synchronized void setHost(String host, int port) { + setHost(host, null, port, Protocol.getProtocol("http")); + } + + + /** + * Set the given host. Select default protocol and port. + * @param host The host. + * @param port The port + */ + public synchronized void setHost(String host) { + Protocol defaultProtocol = Protocol.getProtocol("http"); + setHost(host, null, defaultProtocol.getDefaultPort(), defaultProtocol); + } + + + /** * Sets the protocol, host and port from the given URI. * @param uri the URI. */ @@ -273,6 +330,14 @@ } /** + * Returns the virtual host. + * @return String + */ + public synchronized String getVirtualHost() { + return virtualHost; + } + + /** * Returns the port. * @return int */ @@ -339,10 +404,22 @@ HostConfiguration config = (HostConfiguration) o; if (hostSet) { - if (!host.equalsIgnoreCase(config.getHost()) - || port != config.getPort() - || !protocol.equals(config.getProtocol())) { - // either host, port or protocol don't match + if (!host.equalsIgnoreCase(config.getHost())) { + return false; + } + if (virtualHost != null) { + if (!virtualHost.equalsIgnoreCase(config.getVirtualHost())) { + return false; + } + } else { + if (config.getVirtualHost() != null) { + return false; + } + } + if (port != config.getPort()) { + return false; + } + if (!protocol.equals(config.getProtocol())) { return false; } } else if (config.isHostSet()) { Index: java/org/apache/commons/httpclient/HttpClient.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v retrieving revision 1.71 diff -u -r1.71 HttpClient.java --- java/org/apache/commons/httpclient/HttpClient.java 25 Feb 2003 09:13:55 -0000 1.71 +++ java/org/apache/commons/httpclient/HttpClient.java 6 Apr 2003 11:19:06 -0000 @@ -366,7 +366,7 @@ throw new IllegalStateException ("HttpURL or HttpsURL instance required"); } - this.hostConfiguration.setHost(host, port, protocol); + this.hostConfiguration.setHost(host, null, port, protocol); } /** @@ -390,7 +390,7 @@ int port = url.getPort(); Protocol protocol = Protocol.getProtocol(url.getProtocol()); - hostConfiguration.setHost(url.getHost(), port, protocol); + hostConfiguration.setHost(url.getHost(), null, port, protocol); } /** @@ -532,6 +532,7 @@ if (!methodConfiguration.isHostSet()) { methodConfiguration.setHost( defaultHostConfiguration.getHost(), + defaultHostConfiguration.getVirtualHost(), defaultHostConfiguration.getPort(), defaultHostConfiguration.getProtocol() ); Index: 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.53 diff -u -r1.53 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 4 Apr 2003 02:37:02 -0000 1.53 +++ java/org/apache/commons/httpclient/HttpConnection.java 6 Apr 2003 11:19:13 -0000 @@ -147,7 +147,18 @@ * @param protocol the protocol to use */ public HttpConnection(String host, int port, Protocol protocol) { - this(null, -1, host, port, protocol); + this(null, -1, host, null, port, protocol); + } + + /** + * Constructor. + * + * @param host the host I should connect to + * @param port the port I should connect to + * @param protocol the protocol to use + */ + public HttpConnection(String host, String virtualHost, int port, Protocol protocol) { + this(null, -1, host, virtualHost, port, protocol); } /** @@ -186,7 +197,7 @@ String host, int port, boolean secure) { - this(proxyHost, proxyPort, host, port, + this(proxyHost, proxyPort, host, null, port, Protocol.getProtocol(secure ? "https" : "http")); } @@ -199,6 +210,7 @@ this(hostConfiguration.getProxyHost(), hostConfiguration.getProxyPort(), hostConfiguration.getHost(), + hostConfiguration.getVirtualHost(), hostConfiguration.getPort(), hostConfiguration.getProtocol()); } @@ -209,23 +221,18 @@ * @param proxyHost the host I should proxy via * @param proxyPort the port I should proxy via * @param host the host I should connect to. Parameter value must be non-null. + * @param virtualHost the virtual host I will be sending requests to * @param port the port I should connect to - * @param protocol The protocol to use. + * @param protocol The protocol to use. Parameter value must be non-null. */ public HttpConnection( String proxyHost, int proxyPort, String host, + String virtualHost, int port, Protocol protocol) { - if (LOG.isDebugEnabled()) { - LOG.debug( - "creating connection for " + host + ":" + port + " via " - + proxyHost + ":" + proxyPort + " using protocol: " + protocol - ); - } - if (host == null) { throw new IllegalArgumentException("host parameter is null"); } @@ -233,18 +240,44 @@ throw new IllegalArgumentException("protocol is null"); } + if (LOG.isDebugEnabled()) { + StringBuffer buffer = new StringBuffer(); + buffer.append("Creating connection for "); + buffer.append(host); + if (virtualHost != null) { + buffer.append("["); + buffer.append(virtualHost); + buffer.append("]"); + } + if (port < 0) { + buffer.append(":"); + buffer.append(port); + } + if (proxyHost != null) { + buffer.append(" via "); + buffer.append(proxyHost); + if (proxyPort < 0) { + buffer.append(":"); + buffer.append(proxyPort); + } + } + buffer.append(" using protocol "); + buffer.append(protocol.toString()); + LOG.debug(buffer.toString()); + } + proxyHostName = proxyHost; proxyPortNumber = proxyPort; hostName = host; + virtualName = virtualHost; portNumber = protocol.resolvePort(port); protocolInUse = protocol; - } // ------------------------------------------ Attribute Setters and Getters /** - * Return my host. + * Return my host name. * * @return my host. */ @@ -253,20 +286,43 @@ } /** - * Set my host. + * Set my host name. * * @param host the host I should connect to. Parameter value must be non-null. * @throws IllegalStateException if I am already connected */ public void setHost(String host) throws IllegalStateException { if (host == null) { - throw new NullPointerException("host parameter is null"); + throw new IllegalArgumentException("host parameter is null"); } assertNotOpen(); hostName = host; } /** + * Return my virtual host name. + * + * @return my virtual host. + */ + public String getVirtualHost() { + return virtualName; + } + + /** + * Set my virtual host name. + * + * @param host the virtual host name that should be used instead of + * physical host name when sending HTTP requests. Virtual host + * name can be set to null if virtual host name is not + * to be used + * @throws IllegalStateException if I am already connected + */ + public void setVirtualHost(String host) throws IllegalStateException { + assertNotOpen(); + virtualName = host; + } + + /** * Return my port. * * If the port is -1 (or less than 0) the default port for @@ -1094,6 +1150,9 @@ /** My host. */ private String hostName = null; + + /** My virtual host. */ + private String virtualName = null; /** My port. */ private int portNumber = -1; Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.129 diff -u -r1.129 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 4 Apr 2003 02:37:02 -0000 1.129 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 6 Apr 2003 11:19:38 -0000 @@ -1430,7 +1430,12 @@ // applications to send the Host request-header. // TODO: Add the ability to disable the sending of this header for // HTTP/1.0 requests. - String host = conn.getHost(); + String host = conn.getVirtualHost(); + if (host != null) { + LOG.debug("Using virtual host name: " + host); + } else { + host = conn.getHost(); + } int port = conn.getPort(); if (getRequestHeader("host") != null) { Index: java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v retrieving revision 1.12 diff -u -r1.12 MultiThreadedHttpConnectionManager.java --- java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 6 Mar 2003 07:49:03 -0000 1.12 +++ java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 6 Apr 2003 11:19:43 -0000 @@ -324,8 +324,11 @@ SimpleHttpConnectionManager.finishLastResponse(conn); HostConfiguration connectionConfiguration = new HostConfiguration(); - connectionConfiguration.setHost(conn.getHost(), - conn.getPort(), conn.getProtocol()); + connectionConfiguration.setHost( + conn.getHost(), + conn.getVirtualHost(), + conn.getPort(), + conn.getProtocol()); if (conn.getProxyHost() != null) { connectionConfiguration.setProxy(conn.getProxyHost(), conn.getProxyPort()); } Index: java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java,v retrieving revision 1.10 diff -u -r1.10 SimpleHttpConnectionManager.java --- java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 31 Jan 2003 00:33:36 -0000 1.10 +++ java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 6 Apr 2003 11:19:44 -0000 @@ -77,6 +77,7 @@ * @author Michael Becke * @author Eric Johnson * @author Mike Bowler + * @author Oleg Kalnichevski * * @since 2.0 */ @@ -107,6 +108,7 @@ Protocol protocol = hostConfiguration.getProtocol(); String host = hostConfiguration.getHost(); + String virtualHost = hostConfiguration.getVirtualHost(); int port = hostConfiguration.getPort(); if (httpConnection == null) { @@ -116,11 +118,16 @@ hostConfiguration.getProxyHost(), hostConfiguration.getProxyPort(), host, + virtualHost, port, protocol ); } else { - httpConnection = new HttpConnection(host, port, protocol); + httpConnection = new HttpConnection( + host, + virtualHost, + port, + protocol); } } else { @@ -135,6 +142,7 @@ } httpConnection.setHost(host); + httpConnection.setVirtualHost(virtualHost); httpConnection.setPort(port); httpConnection.setProtocol(protocol); Index: test/org/apache/commons/httpclient/SimpleHttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v retrieving revision 1.11 diff -u -r1.11 SimpleHttpConnection.java --- test/org/apache/commons/httpclient/SimpleHttpConnection.java 13 Mar 2003 17:51:28 -0000 1.11 +++ test/org/apache/commons/httpclient/SimpleHttpConnection.java 6 Apr 2003 11:19:46 -0000 @@ -111,16 +111,17 @@ } public SimpleHttpConnection() { - super(null, -1, "localhost", 80, Protocol.getProtocol("http")); + super(null, -1, "localhost", null, 80, Protocol.getProtocol("http")); } public SimpleHttpConnection( String proxyHost, int proxyPort, String host, + String virtualHost, int port, Protocol protocol) { - super(proxyHost, proxyPort, host, port, protocol); + super(proxyHost, proxyPort, host, virtualHost, port, protocol); } public SimpleHttpConnection(String host, int port){ Index: test/org/apache/commons/httpclient/TestRequestLine.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRequestLine.java,v retrieving revision 1.1 diff -u -r1.1 TestRequestLine.java --- test/org/apache/commons/httpclient/TestRequestLine.java 13 Mar 2003 17:51:28 -0000 1.1 +++ test/org/apache/commons/httpclient/TestRequestLine.java 6 Apr 2003 11:19:47 -0000 @@ -99,7 +99,7 @@ SimpleHttpConnection conn = null; SimpleHttpMethod method = null; - conn = new SimpleHttpConnection(null, -1, "localhost", 80, Protocol.getProtocol("http")); + conn = new SimpleHttpConnection(null, -1, "localhost", null, 80, Protocol.getProtocol("http")); method = new SimpleHttpMethod(); assertEquals("Simple / HTTP/1.1\r\n", method.getTestRequestLine(conn)); @@ -107,7 +107,7 @@ method = new SimpleHttpMethod("stuff"); assertEquals("Simple stuff HTTP/1.1\r\n", method.getTestRequestLine(conn)); - conn = new SimpleHttpConnection("proxy", 8080, "localhost", 80, Protocol.getProtocol("http")); + conn = new SimpleHttpConnection("proxy", 8080, "localhost", null, 80, Protocol.getProtocol("http")); method = new SimpleHttpMethod(); assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.getTestRequestLine(conn)); @@ -115,7 +115,7 @@ method = new SimpleHttpMethod("stuff"); assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn)); - conn = new SimpleHttpConnection("proxy", 8080, "localhost", -1, Protocol.getProtocol("http")); + conn = new SimpleHttpConnection("proxy", 8080, "localhost", null, -1, Protocol.getProtocol("http")); method = new SimpleHttpMethod(); assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.getTestRequestLine(conn)); @@ -123,7 +123,7 @@ method = new SimpleHttpMethod("stuff"); assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn)); - conn = new SimpleHttpConnection("proxy", 8080, "localhost", 666, Protocol.getProtocol("http")); + conn = new SimpleHttpConnection("proxy", 8080, "localhost", null, 666, Protocol.getProtocol("http")); method = new SimpleHttpMethod(); assertEquals("Simple http://localhost:666/ HTTP/1.1\r\n", method.getTestRequestLine(conn)); @@ -136,7 +136,7 @@ SimpleHttpConnection conn = null; SimpleHttpMethod method = null; - conn = new SimpleHttpConnection(null, -1, "localhost", 80, Protocol.getProtocol("http")); + conn = new SimpleHttpConnection(null, -1, "localhost", null, 80, Protocol.getProtocol("http")); method = new SimpleHttpMethod(); method.setQueryString( new NameValuePair[] { @@ -151,7 +151,7 @@ SimpleHttpConnection conn = null; SimpleHttpMethod method = null; - conn = new SimpleHttpConnection(null, -1, "localhost", 80, Protocol.getProtocol("http")); + conn = new SimpleHttpConnection(null, -1, "localhost", null, 80, Protocol.getProtocol("http")); method = new SimpleHttpMethod(); method.setPath("/some%20stuff/");