Index: contrib/org/apache/commons/httpclient/contrib/utils/HttpMethodCloner.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/utils/HttpMethodCloner.java,v retrieving revision 1.6 diff -u -r1.6 HttpMethodCloner.java --- contrib/org/apache/commons/httpclient/contrib/utils/HttpMethodCloner.java 4 May 2004 21:24:51 -0000 1.6 +++ contrib/org/apache/commons/httpclient/contrib/utils/HttpMethodCloner.java 5 Oct 2004 08:50:07 -0000 @@ -28,7 +28,6 @@ package org.apache.commons.httpclient.contrib.utils; import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.methods.EntityEnclosingMethod; @@ -58,10 +57,6 @@ private static void copyHttpMethodBase( HttpMethodBase m, HttpMethodBase copy) { - if (m.getHostConfiguration() != null) { - copy.setHostConfiguration( - new HostConfiguration(m.getHostConfiguration())); - } try { copy.setParams((HttpMethodParams)m.getParams().clone()); } catch (CloneNotSupportedException e) { 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.19 diff -u -r1.19 HostConfiguration.java --- java/org/apache/commons/httpclient/HostConfiguration.java 17 Jul 2004 18:58:33 -0000 1.19 +++ java/org/apache/commons/httpclient/HostConfiguration.java 5 Oct 2004 08:50:07 -0000 @@ -55,51 +55,22 @@ public static final HostConfiguration ANY_HOST_CONFIGURATION = new HostConfiguration(); /** The host to use. */ - private String host; - - /** The virtual host to use. */ - private String virtualHost; - - /** The port to use. */ - private int port; - - /** The protocol */ - private Protocol protocol; - - /** True if a host has been set */ - private boolean hostSet; + private HttpHost host = null; /** The host name of the proxy server */ - private String proxyHost; - - /** The port number of the proxy server */ - private int proxyPort; + private ProxyHost proxyHost = null; - /** True if a proxy server has been set */ - private boolean proxySet; - /** The local address to use when creating the socket, or null to use the default */ - private InetAddress localAddress; + private InetAddress localAddress = null; /** Parameters specific to this host */ - private HostParams params; + private HostParams params = new HostParams(); /** * Constructor for HostConfiguration. */ public HostConfiguration() { - - this.host = null; - this.virtualHost = null; - this.port = -1; - this.protocol = null; - this.hostSet = false; - - this.proxyHost = null; - this.proxyPort = -1; - this.proxySet = false; - this.localAddress = null; - this.params = new HostParams(); + super(); } /** @@ -107,28 +78,27 @@ * * @param hostConfiguration the hostConfiguration to copy */ - public HostConfiguration (HostConfiguration hostConfiguration) { - + public HostConfiguration (final HostConfiguration hostConfiguration) { // wrap all of the assignments in a synchronized block to avoid // 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(); - - this.proxyHost = hostConfiguration.getProxyHost(); - this.proxyPort = hostConfiguration.getProxyPort(); - this.proxySet = hostConfiguration.isProxySet(); - this.localAddress = hostConfiguration.getLocalAddress(); + synchronized (hostConfiguration) { try { + if (hostConfiguration.host != null) { + this.host = (HttpHost) hostConfiguration.host.clone(); + } else { + this.host = null; + } + if (hostConfiguration.proxyHost != null) { + this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone(); + } else { + this.proxyHost = null; + } + this.localAddress = hostConfiguration.getLocalAddress(); this.params = (HostParams)hostConfiguration.getParams().clone(); } catch (CloneNotSupportedException e) { - this.params = new HostParams(); + throw new IllegalArgumentException("Host configuration could not be cloned"); } - } - + } } /** @@ -144,37 +114,35 @@ public synchronized String toString() { boolean appendComma = false; - StringBuffer b = new StringBuffer(50); b.append("HostConfiguration["); - if (isHostSet()) { + if (this.host != null) { appendComma = true; - b.append("host=").append(host); - b.append(", protocol=").append(protocol); - b.append(", port=").append(port); - if (virtualHost != null) { - b.append(", virtualHost=").append(virtualHost); - } + b.append("host=").append(this.host); } - if (isProxySet()) { + if (this.proxyHost != null) { if (appendComma) { b.append(", "); } else { appendComma = true; } - b.append("proxyHost=").append(proxyHost); - b.append(", proxyPort=").append(proxyPort); + b.append("proxyHost=").append(this.proxyHost); } - if (localAddress != null) { + if (this.localAddress != null) { if (appendComma) { b.append(", "); } else { appendComma = true; } - b.append("localAddress=").append(localAddress); + b.append("localAddress=").append(this.localAddress); + if (appendComma) { + b.append(", "); + } else { + appendComma = true; + } + b.append("params=").append(this.params); } - b.append("]"); return b.toString(); } @@ -189,27 +157,19 @@ * configuration * * @see #proxyEquals(HttpConnection) - * @see #isHostSet() */ - public synchronized boolean hostEquals(HttpConnection connection) { - - if (hostSet) { - if (!this.host.equalsIgnoreCase(connection.getHost())) { + public synchronized boolean hostEquals(final HttpConnection connection) { + if (connection == null) { + throw new IllegalArgumentException("Connection may not be null"); + } + if (this.host != null) { + if (!this.host.getHostName().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()) { + if (this.host.getPort() != connection.getPort()) { return false; } - if (!this.protocol.equals(connection.getProtocol())) { + if (!this.host.getProtocol().equals(connection.getProtocol())) { return false; } if (this.localAddress != null) { @@ -225,7 +185,6 @@ } else { return false; } - } /** @@ -238,15 +197,16 @@ * * @see #hostEquals(HttpConnection) */ - public synchronized boolean proxyEquals(HttpConnection connection) { - - if (proxyHost == null) { - return connection.getProxyHost() == null; + public synchronized boolean proxyEquals(final HttpConnection connection) { + if (connection == null) { + throw new IllegalArgumentException("Connection may not be null"); + } + if (this.proxyHost != null) { + return + this.proxyHost.getHostName().equalsIgnoreCase(connection.getProxyHost()) + && this.proxyHost.getPort() == connection.getProxyPort(); } else { - return ( - proxyHost.equalsIgnoreCase(connection.getProxyHost()) - && proxyPort == connection.getProxyPort() - ); + return connection.getProxyHost() == null; } } @@ -255,18 +215,27 @@ * @return true if the host is set. */ public synchronized boolean isHostSet() { - return hostSet; + return this.host != null; } /** + * Sets the given host + * + * @param host the host + */ + public synchronized void setHost(final HttpHost host) { + this.host = host; + } + + /** * Sets 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, null, port, Protocol.getProtocol(protocol)); + public synchronized void setHost(final String host, int port, final String protocol) { + this.host = new HttpHost(host, port, Protocol.getProtocol(protocol)); } /** @@ -276,23 +245,13 @@ * @param virtualHost the virtual host name or null * @param port the host port or -1 to use protocol default * @param protocol the protocol + * + * @deprecated #setHost(String, int, Protocol) */ - public synchronized void setHost(String host, String virtualHost, int port, - Protocol protocol) { - - if (host == null) { - throw new IllegalArgumentException("host must not be null"); - } - if (protocol == null) { - throw new IllegalArgumentException("protocol must not be null"); - } - - this.host = host; - this.virtualHost = virtualHost; - this.port = port == -1 ? protocol.getDefaultPort() : port; - this.protocol = protocol; - - this.hostSet = true; + public synchronized void setHost(final String host, final String virtualHost, int port, + final Protocol protocol) { + setHost(host, port, protocol); + this.params.setVirtualHost(virtualHost); } /** @@ -302,8 +261,14 @@ * @param port The port * @param protocol the protocol */ - public synchronized void setHost(String host, int port, Protocol protocol) { - setHost(host, null, port, protocol); + public synchronized void setHost(final String host, int port, final Protocol protocol) { + if (host == null) { + throw new IllegalArgumentException("host must not be null"); + } + if (protocol == null) { + throw new IllegalArgumentException("protocol must not be null"); + } + this.host = new HttpHost(host, port, protocol); } /** @@ -312,8 +277,8 @@ * @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")); + public synchronized void setHost(final String host, int port) { + setHost(host, port, Protocol.getProtocol("http")); } /** @@ -321,7 +286,7 @@ * * @param host The host(IP or DNS name). */ - public synchronized void setHost(String host) { + public synchronized void setHost(final String host) { Protocol defaultProtocol = Protocol.getProtocol("http"); setHost(host, null, defaultProtocol.getDefaultPort(), defaultProtocol); } @@ -330,7 +295,7 @@ * Sets the protocol, host and port from the given URI. * @param uri the URI. */ - public synchronized void setHost(URI uri) { + public synchronized void setHost(final URI uri) { try { setHost(uri.getHost(), uri.getPort(), uri.getScheme()); } catch (URIException e) { @@ -344,20 +309,11 @@ * @return The host url. */ public synchronized String getHostURL() { - - if (!hostSet) { - throw new IllegalStateException("a default host must be set to " - + "create a host URL" - ); - } - - String url = protocol.getScheme() + "://" + host; - - if (port != -1 && port != protocol.getDefaultPort()) { - url += ":" + port; + if (this.host == null) { + throw new IllegalStateException("Host must be set to create a host URL"); + } else { + return this.host.toURI(); } - - return url; } /** @@ -368,16 +324,22 @@ * @see #isHostSet() */ public synchronized String getHost() { - return host; + if (this.host != null) { + return this.host.getHostName(); + } else { + return null; + } } /** * Returns the virtual host. * * @return the virtual host name, or null if not set + * + * @deprecated use HostParams */ public synchronized String getVirtualHost() { - return virtualHost; + return this.params.getVirtualHost(); } /** @@ -388,7 +350,11 @@ * @see #isHostSet() */ public synchronized int getPort() { - return port; + if (this.host != null) { + return this.host.getPort(); + } else { + return -1; + } } /** @@ -396,7 +362,11 @@ * @return The protocol. */ public synchronized Protocol getProtocol() { - return protocol; + if (this.host != null) { + return this.host.getProtocol(); + } else { + return null; + } } /** @@ -407,20 +377,25 @@ * @see #setProxy(String, int) */ public synchronized boolean isProxySet() { - return proxySet; + return this.proxyHost != null; } /** + * Sets the given proxy host + * + * @param host the proxy host + */ + public synchronized void setProxyHost(final ProxyHost proxyHost) { + this.proxyHost = proxyHost; + } + + /** * Set the proxy settings. * @param proxyHost The proxy host * @param proxyPort The proxy port */ - public synchronized void setProxy(String proxyHost, int proxyPort) { - - this.proxyHost = proxyHost; - this.proxyPort = proxyPort; - - this.proxySet = true; + public synchronized void setProxy(final String proxyHost, int proxyPort) { + this.proxyHost = new ProxyHost(proxyHost, proxyPort); } /** @@ -431,7 +406,11 @@ * @see #isProxySet() */ public synchronized String getProxyHost() { - return proxyHost; + if (this.proxyHost != null) { + return this.proxyHost.getHostName(); + } else { + return null; + } } /** @@ -442,7 +421,11 @@ * @see #isProxySet() */ public synchronized int getProxyPort() { - return proxyPort; + if (this.proxyHost != null) { + return this.proxyHost.getPort(); + } else { + return -1; + } } /** @@ -494,7 +477,7 @@ /** * @see java.lang.Object#equals(java.lang.Object) */ - public synchronized boolean equals(Object o) { + public synchronized boolean equals(final Object o) { if (o instanceof HostConfiguration) { @@ -503,52 +486,37 @@ return true; } - HostConfiguration config = (HostConfiguration) o; + HostConfiguration that = (HostConfiguration) o; - if (hostSet) { - if (!host.equalsIgnoreCase(config.getHost())) { + if (this.host != null) { + if (!this.host.equals(that.host)) { return false; } - if (virtualHost != null) { - if (!virtualHost.equalsIgnoreCase(config.getVirtualHost())) { - return false; - } - } else { - if (config.getVirtualHost() != null) { - return false; - } - } - if (port != config.getPort()) { + } else { + if (that.host != null) { return false; } - if (!protocol.equals(config.getProtocol())) { + } + if (this.proxyHost != null) { + if (!this.proxyHost.equals(that.proxyHost)) { return false; } - } else if (config.isHostSet()) { - return false; - } - if (proxyHost != null) { - if (!proxyHost.equalsIgnoreCase (config.getProxyHost()) - || proxyPort != config.getProxyPort()) { - // either proxyHost or proxyPort don't match + } else { + if (that.proxyHost != null) { return false; } - } else if (config.getProxyHost() != null) { - return false; - } + } if (localAddress != null) { - if (!localAddress.equals(config.getLocalAddress())) { + if (!localAddress.equals(that.getLocalAddress())) { return false; } } else { - if (config.getLocalAddress() != null) { + if (that.getLocalAddress() != null) { return false; } } - // everything matches return true; - } else { return false; } @@ -559,7 +527,6 @@ * @see java.lang.Object#hashCode() */ public int hashCode() { - if (host != null) { return host.hashCode(); } else if (proxyHost != null) { 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.96 diff -u -r1.96 HttpClient.java --- java/org/apache/commons/httpclient/HttpClient.java 14 Jun 2004 21:25:38 -0000 1.96 +++ java/org/apache/commons/httpclient/HttpClient.java 5 Oct 2004 08:50:07 -0000 @@ -321,14 +321,7 @@ LOG.trace("enter HttpClient.executeMethod(HttpMethod)"); // execute this method and use its host configuration, if it has one - return executeMethod( - method.getHostConfiguration() != null - ? method.getHostConfiguration() - : getHostConfiguration(), - method, - null - ); - + return executeMethod(null, method, null); } /** @@ -345,11 +338,11 @@ * cannot be recovered from. * @since 2.0 */ - public int executeMethod(HostConfiguration hostConfiguration, HttpMethod method) + public int executeMethod(final HostConfiguration hostConfiguration, final HttpMethod method) throws IOException, HttpException { LOG.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod)"); - + return executeMethod(hostConfiguration, method, null); } @@ -374,7 +367,7 @@ * @since 2.0 */ public int executeMethod(HostConfiguration hostConfiguration, - HttpMethod method, HttpState state) + final HttpMethod method, final HttpState state) throws IOException, HttpException { LOG.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)"); @@ -382,58 +375,20 @@ if (method == null) { throw new IllegalArgumentException("HttpMethod parameter may not be null"); } - - if (hostConfiguration == null) { - hostConfiguration = ( - method.getHostConfiguration() != null - ? method.getHostConfiguration() - : getHostConfiguration() - ); - } - - HostConfiguration defaultHostConfiguration = null; - synchronized (this) { - defaultHostConfiguration = getHostConfiguration(); - } - HostConfiguration methodConfiguration = new HostConfiguration(hostConfiguration); - if (hostConfiguration != defaultHostConfiguration) { - // we may need to apply some defaults - if (!methodConfiguration.isHostSet()) { - methodConfiguration.setHost( - defaultHostConfiguration.getHost(), - defaultHostConfiguration.getVirtualHost(), - defaultHostConfiguration.getPort(), - defaultHostConfiguration.getProtocol() - ); - } - if (!methodConfiguration.isProxySet() - && defaultHostConfiguration.isProxySet()) { - - methodConfiguration.setProxy( - defaultHostConfiguration.getProxyHost(), - defaultHostConfiguration.getProxyPort() - ); - } - if (methodConfiguration.getLocalAddress() == null - && defaultHostConfiguration.getLocalAddress() != null) { - - methodConfiguration.setLocalAddress(defaultHostConfiguration.getLocalAddress()); + HostConfiguration defaulthostconfig = getHostConfiguration(); + if (hostConfiguration == null || hostConfiguration == defaulthostconfig) { + // make a deep copy of the host derfauls + hostConfiguration = new HostConfiguration(defaulthostconfig); + if (method.getHost() != null) { + hostConfiguration.setHost(method.getHost()); } } - /* access all synchronized data in a single block, this will keeps us - * from accessing data asynchronously as well having to regain the lock - * for each item. - */ - HttpMethodDirector methodDirector = null; - synchronized (this) { - methodDirector = new HttpMethodDirector( + HttpMethodDirector methodDirector = new HttpMethodDirector( this.httpConnectionManager, - methodConfiguration, + hostConfiguration, this.params, (state == null ? getState() : state)); - defaultHostConfiguration = getHostConfiguration(); - } methodDirector.executeMethod(method); return method.getStatusCode(); } 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.100 diff -u -r1.100 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 15 Sep 2004 20:32:21 -0000 1.100 +++ java/org/apache/commons/httpclient/HttpConnection.java 5 Oct 2004 08:50:08 -0000 @@ -154,7 +154,6 @@ this(hostConfiguration.getProxyHost(), hostConfiguration.getProxyPort(), hostConfiguration.getHost(), - hostConfiguration.getVirtualHost(), hostConfiguration.getPort(), hostConfiguration.getProtocol()); this.localAddress = hostConfiguration.getLocalAddress(); @@ -168,9 +167,11 @@ * @param proxyHost the host to proxy via * @param proxyPort the port to proxy via * @param host the host to connect to. Parameter value must be non-null. - * @param virtualHost the virtual host requests will be sent to + * @param virtualHost No longer applicable. * @param port the port to connect to * @param protocol The protocol to use. Parameter value must be non-null. + * + * @deprecated use #HttpConnection(String, int, String, int, Protocol) */ public HttpConnection( String proxyHost, @@ -179,6 +180,27 @@ String virtualHost, int port, Protocol protocol) { + this(proxyHost, proxyPort, host, port, protocol); + } + + /** + * Creates a new HTTP connection for the given host with the virtual + * alias and port via the given proxy host and port using the given + * protocol. + * + * @param proxyHost the host to proxy via + * @param proxyPort the port to proxy via + * @param host the host to connect to. Parameter value must be non-null. + * @param virtualHost the virtual host requests will be sent to + * @param port the port to connect to + * @param protocol The protocol to use. Parameter value must be non-null. + */ + public HttpConnection( + String proxyHost, + int proxyPort, + String host, + int port, + Protocol protocol) { if (host == null) { throw new IllegalArgumentException("host parameter is null"); @@ -190,7 +212,6 @@ proxyHostName = proxyHost; proxyPortNumber = proxyPort; hostName = host; - virtualName = virtualHost; portNumber = protocol.resolvePort(port); protocolInUse = protocol; } @@ -235,9 +256,12 @@ * Returns the target virtual host. * * @return the virtual host. + * + * @deprecated no longer applicable */ + public String getVirtualHost() { - return virtualName; + return this.hostName; } /** @@ -249,10 +273,12 @@ * to be used * * @throws IllegalStateException if the connection is already open + * + * @deprecated no longer applicable */ + public void setVirtualHost(String host) throws IllegalStateException { assertNotOpen(); - virtualName = host; } /** @@ -1268,9 +1294,6 @@ /** 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/HttpMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v retrieving revision 1.41 diff -u -r1.41 HttpMethod.java --- java/org/apache/commons/httpclient/HttpMethod.java 5 Jul 2004 22:46:58 -0000 1.41 +++ java/org/apache/commons/httpclient/HttpMethod.java 5 Oct 2004 08:50:08 -0000 @@ -65,11 +65,20 @@ /** * Gets the host configuration for this method. The configuration specifies * the server, port, protocol, and proxy server via which this method will - * send its HTTP request. + * send its HTTP request. + * + * @deprecated no longer applicable * * @return the HostConfiguration or null if none is set */ HostConfiguration getHostConfiguration(); + + /** + * Gets the target host for this method. + * + * @return the {@link HttpHost} or null if none is set + */ + HttpHost getHost(); /** * Sets the path of the HTTP method. 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.216 diff -u -r1.216 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 30 Sep 2004 18:15:22 -0000 1.216 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 5 Oct 2004 08:50:09 -0000 @@ -153,8 +153,8 @@ * a recoverable exception. */ private int recoverableExceptionCount = 0; - /** the host configuration for this HTTP method, can be null */ - private HostConfiguration hostConfiguration; + /** the host for this HTTP method, can be null */ + private HttpHost httphost = null; /** * Handles method retries @@ -242,7 +242,7 @@ */ public URI getURI() throws URIException { - if (hostConfiguration == null) { + if (this.httphost == null) { // just use a relative URI, the host hasn't been set URI tmpUri = new URI(null, null, path, null, null); tmpUri.setEscapedQuery(queryString); @@ -250,15 +250,14 @@ } else { // we only want to include the port if it's not the default - int port = hostConfiguration.getPort(); - if (port == hostConfiguration.getProtocol().getDefaultPort()) { + int port = this.httphost.getPort(); + if (port == this.httphost.getProtocol().getDefaultPort()) { port = -1; } - URI tmpUri = new URI( - hostConfiguration.getProtocol().getScheme(), + this.httphost.getProtocol().getScheme(), null, - hostConfiguration.getHost(), + this.httphost.getHostName(), port, path, null // to set an escaped form @@ -282,16 +281,8 @@ public void setURI(URI uri) throws URIException { // only set the host if specified by the URI if (uri.isAbsoluteURI()) { - if (this.hostConfiguration == null) { - this.hostConfiguration = new HostConfiguration(); - } - this.hostConfiguration.setHost( - uri.getHost(), - uri.getPort(), - uri.getScheme() - ); + this.httphost = new HttpHost(uri); } - // set the path, defaulting to root setPath( uri.getPath() == null @@ -1227,7 +1218,7 @@ // 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.getVirtualHost(); + String host = this.params.getVirtualHost(); if (host != null) { LOG.debug("Using virtual host name: " + host); } else { @@ -2286,22 +2277,38 @@ } } + public HttpHost getHost() { + return this.httphost; + } + /** * Returns the {@link HostConfiguration host configuration}. * * @return the host configuration + * + * @deprecated no longer applicable */ public HostConfiguration getHostConfiguration() { - return hostConfiguration; + HostConfiguration hostconfig = new HostConfiguration(); + hostconfig.setHost(this.httphost); + return hostconfig; } - /** * Sets the {@link HostConfiguration host configuration}. * * @param hostConfiguration The hostConfiguration to set + * + * @deprecated no longer applicable */ - public void setHostConfiguration(HostConfiguration hostConfiguration) { - this.hostConfiguration = hostConfiguration; + public void setHostConfiguration(final HostConfiguration hostconfig) { + if (hostconfig != null) { + this.httphost = new HttpHost( + hostconfig.getHost(), + hostconfig.getPort(), + hostconfig.getProtocol()); + } else { + this.httphost = null; + } } /** Index: java/org/apache/commons/httpclient/HttpMethodDirector.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v retrieving revision 1.30 diff -u -r1.30 HttpMethodDirector.java --- java/org/apache/commons/httpclient/HttpMethodDirector.java 15 Sep 2004 20:42:17 -0000 1.30 +++ java/org/apache/commons/httpclient/HttpMethodDirector.java 5 Oct 2004 08:50:09 -0000 @@ -270,7 +270,7 @@ return; } if ((this.authProcess == AUTH_WWW_REQUIRED) || (!authscheme.isConnectionBased())) { - String host = conn.getVirtualHost(); + String host = method.getParams().getVirtualHost(); if (host == null) { host = conn.getHost(); } @@ -672,7 +672,7 @@ if (authscheme == null) { return false; } - String host = conn.getVirtualHost(); + String host = method.getParams().getVirtualHost(); if (host == null) { host = conn.getHost(); } 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.44 diff -u -r1.44 MultiThreadedHttpConnectionManager.java --- java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 30 Sep 2004 18:15:22 -0000 1.44 +++ java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 5 Oct 2004 08:50:09 -0000 @@ -622,7 +622,6 @@ connectionConfiguration.setHost( conn.getHost(), - conn.getVirtualHost(), conn.getPort(), conn.getProtocol() ); @@ -1546,6 +1545,9 @@ } } + /** + * @deprecated + */ public String getVirtualHost() { if (hasConnection()) { return wrappedConnection.getVirtualHost(); @@ -1554,6 +1556,9 @@ } } + /** + * @deprecated + */ public void setVirtualHost(String host) throws IllegalStateException { if (hasConnection()) { wrappedConnection.setVirtualHost(host); 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.21 diff -u -r1.21 SimpleHttpConnectionManager.java --- java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 13 May 2004 04:03:25 -0000 1.21 +++ java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java 5 Oct 2004 08:50:10 -0000 @@ -144,7 +144,6 @@ } httpConnection.setHost(hostConfiguration.getHost()); - httpConnection.setVirtualHost(hostConfiguration.getVirtualHost()); httpConnection.setPort(hostConfiguration.getPort()); httpConnection.setProtocol(hostConfiguration.getProtocol()); httpConnection.setLocalAddress(hostConfiguration.getLocalAddress()); Index: java/org/apache/commons/httpclient/auth/HttpAuthenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/HttpAuthenticator.java,v retrieving revision 1.18 diff -u -r1.18 HttpAuthenticator.java --- java/org/apache/commons/httpclient/auth/HttpAuthenticator.java 18 Apr 2004 23:51:36 -0000 1.18 +++ java/org/apache/commons/httpclient/auth/HttpAuthenticator.java 5 Oct 2004 08:50:10 -0000 @@ -61,7 +61,7 @@ * @author Remy Maucherat * @author Rodney Waldhoff * @author Jeff Dever - * @author Ortwin Gl� + * @author Ortwin Gl�ck * @author Sean C. Sullivan * @author Adrian Sutton * @author Mike Bowler @@ -273,7 +273,7 @@ if (proxy) { host = conn.getProxyHost(); } else { - host = conn.getVirtualHost(); + host = method.getParams().getVirtualHost(); if (host == null) { host = conn.getHost(); } Index: java/org/apache/commons/httpclient/params/HostParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HostParams.java,v retrieving revision 1.4 diff -u -r1.4 HostParams.java --- java/org/apache/commons/httpclient/params/HostParams.java 19 Sep 2004 19:07:21 -0000 1.4 +++ java/org/apache/commons/httpclient/params/HostParams.java 5 Oct 2004 08:50:10 -0000 @@ -85,4 +85,23 @@ public HostParams(HttpParams defaults) { super(defaults); } + + /** + * Sets the virtual host name. + * + * @param hostname The host name + */ + public void setVirtualHost(final String hostname) { + setParameter(HttpMethodParams.VIRTUAL_HOST, hostname); + } + + /** + * Returns the virtual host name. + * + * @return The virtual host name + */ + public String getVirtualHost() { + return (String) getParameter(HttpMethodParams.VIRTUAL_HOST); + } + } Index: java/org/apache/commons/httpclient/params/HttpMethodParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v retrieving revision 1.15 diff -u -r1.15 HttpMethodParams.java --- java/org/apache/commons/httpclient/params/HttpMethodParams.java 17 Sep 2004 08:00:51 -0000 1.15 +++ java/org/apache/commons/httpclient/params/HttpMethodParams.java 5 Oct 2004 08:50:10 -0000 @@ -258,6 +258,14 @@ public static final String BUFFER_WARN_TRIGGER_LIMIT = "http.method.response.buffer.warnlimit"; /** + * Defines the virtual host name. + *

+ * This parameter expects a value of type {@link java.lang.String}. + *

+ */ + public static final String VIRTUAL_HOST = "http.virtual-host"; + + /** * Creates a new collection of parameters with the collection returned * by {@link #getDefaultParams()} as a parent. The collection will defer * to its parent for a default value if a particular parameter is not @@ -425,6 +433,24 @@ setIntParameter(SO_TIMEOUT, timeout); } + /** + * Sets the virtual host name. + * + * @param hostname The host name + */ + public void setVirtualHost(final String hostname) { + setParameter(VIRTUAL_HOST, hostname); + } + + /** + * Returns the virtual host name. + * + * @return The virtual host name + */ + public String getVirtualHost() { + return (String) getParameter(VIRTUAL_HOST); + } + private static final String[] PROTOCOL_STRICTNESS_PARAMETERS = { UNAMBIGUOUS_STATUS_LINE, SINGLE_COOKIE_HEADER, Index: test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v retrieving revision 1.7 diff -u -r1.7 NoHostHttpConnectionManager.java --- test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 5 Jul 2004 22:46:59 -0000 1.7 +++ test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java 5 Oct 2004 08:50:10 -0000 @@ -84,7 +84,6 @@ } connection.setHost(hostConfiguration.getHost()); - connection.setVirtualHost(hostConfiguration.getVirtualHost()); connection.setPort(hostConfiguration.getPort()); connection.setProtocol(hostConfiguration.getProtocol()); connection.setLocalAddress(hostConfiguration.getLocalAddress()); Index: test/org/apache/commons/httpclient/TestAuthenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v retrieving revision 1.43 diff -u -r1.43 TestAuthenticator.java --- test/org/apache/commons/httpclient/TestAuthenticator.java 13 Jun 2004 12:13:08 -0000 1.43 +++ test/org/apache/commons/httpclient/TestAuthenticator.java 5 Oct 2004 08:50:11 -0000 @@ -97,7 +97,7 @@ host = conn.getProxyHost(); port = conn.getProxyPort(); } else { - host = conn.getVirtualHost(); + host = method.getParams().getVirtualHost(); if (host == null) { host = conn.getHost(); } Index: test/org/apache/commons/httpclient/params/TestHttpParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v retrieving revision 1.2 diff -u -r1.2 TestHttpParams.java --- test/org/apache/commons/httpclient/params/TestHttpParams.java 15 Sep 2004 20:45:48 -0000 1.2 +++ test/org/apache/commons/httpclient/params/TestHttpParams.java 5 Oct 2004 08:50:11 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v 1.2 2004/09/15 20:45:48 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v 1.2 2004/09/15 20:45:48 olegk Exp $ * $Revision: 1.2 $ * $Date: 2004/09/15 20:45:48 $ * ==================================================================== @@ -129,5 +129,31 @@ Header[] thatheader = httpget.getRequestHeaders("that-header"); assertEquals(2, thatheader.length); assertEquals("test", httpget.getRequestHeader("User-Agent").getValue()); + } + + public void testDefaults() throws IOException { + this.server.setHttpService(new SimpleService()); + + this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test"); + HostConfiguration hostconfig = new HostConfiguration(); + hostconfig.setHost( + this.server.getLocalAddress(), + this.server.getLocalPort(), + Protocol.getProtocol("http")); + + GetMethod httpget = new GetMethod("/miss/"); + try { + this.client.executeMethod(hostconfig, httpget); + } finally { + httpget.releaseConnection(); + } + assertEquals(HttpStatus.SC_OK, httpget.getStatusCode()); + assertEquals("test", httpget.getRequestHeader("User-Agent").getValue()); + assertEquals("test", httpget.getParams(). + getParameter(HttpMethodParams.USER_AGENT)); + assertEquals("test", hostconfig.getParams(). + getParameter(HttpMethodParams.USER_AGENT)); + assertEquals("test", client.getParams(). + getParameter(HttpMethodParams.USER_AGENT)); } } Index: java/org/apache/commons/httpclient/HttpHost.java =================================================================== RCS file: java/org/apache/commons/httpclient/HttpHost.java diff -N java/org/apache/commons/httpclient/HttpHost.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/HttpHost.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,219 @@ +/* + * $Header$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2002-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.httpclient; + +import org.apache.commons.httpclient.protocol.Protocol; + +/** + * Holds all of the variables needed to describe an HTTP connection to a host. This includes + * remote host, port and protocol. + * + * @author Michael Becke + * @author Mike Bowler + * @author Oleg Kalnichevski + * @author Laura Werner + * + * @since 3.0 + */ +public class HttpHost implements Cloneable { + + /** The host to use. */ + private String hostname = null; + + /** The port to use. */ + private int port = -1; + + /** The protocol */ + private Protocol protocol = null; + + /** + * Constructor for HttpHost. + * + * @param hostname the hostname (IP or DNS name). Can be null. + * @param virtualHostname the virtual hostname. Can be null. + * @param port the port. Value -1 can be used to set default protocol port + * @param protocol the protocol. Value null can be used to set default protocol + */ + public HttpHost(final String hostname, int port, final Protocol protocol) { + super(); + if (hostname == null) { + throw new IllegalArgumentException("Host name may not be null"); + } + if (protocol == null) { + throw new IllegalArgumentException("Protocol may not be null"); + } + this.hostname = hostname; + this.protocol = protocol; + if (port >= 0) { + this.port = port; + } else { + this.port = this.protocol.getDefaultPort(); + } + } + + /** + * Constructor for HttpHost. + * + * @param hostname the hostname (IP or DNS name). Can be null. + * @param port the port. Value -1 can be used to set default protocol port + */ + public HttpHost(final String hostname, int port) { + this(hostname, port, Protocol.getProtocol("http")); + } + + /** + * Constructor for HttpHost. + * + * @param hostname the hostname (IP or DNS name). Can be null. + */ + public HttpHost(final String hostname) { + this(hostname, -1, Protocol.getProtocol("http")); + } + + /** + * URI constructor for HttpHost. + * + * @param uri the URI. + */ + public HttpHost(final URI uri) throws URIException { + this(uri.getHost(), uri.getPort(), Protocol.getProtocol(uri.getScheme())); + } + + /** + * Copy constructor for HttpHost + * + * @param httphost the HTTP host to copy details from + */ + public HttpHost (final HttpHost httphost) { + super(); + this.hostname = httphost.hostname; + this.port = httphost.port; + this.protocol = httphost.protocol; + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() { + return new HttpHost(this); + } + + /** + * Returns the host name (IP or DNS name). + * + * @return the host name (IP or DNS name), or null if not set + */ + public String getHostName() { + return this.hostname; + } + + /** + * Returns the port. + * + * @return the host port, or -1 if not set + */ + public synchronized int getPort() { + return this.port; + } + + /** + * Returns the protocol. + * @return The protocol. + */ + public synchronized Protocol getProtocol() { + return this.protocol; + } + + /** + * Return the host uri. + * + * @return The host uri. + */ + public String toURI() { + StringBuffer buffer = new StringBuffer(50); + if (this.protocol != null) { + buffer.append(this.protocol.getScheme()); + buffer.append("://"); + } + buffer.append(this.hostname); + if (this.port != this.protocol.getDefaultPort()) { + buffer.append(':'); + buffer.append(this.port); + } + return buffer.toString(); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer buffer = new StringBuffer(50); + buffer.append(toURI()); + return buffer.toString(); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(final Object o) { + + if (o instanceof HttpHost) { + // shortcut if we're comparing with ourselves + if (o == this) { + return true; + } + HttpHost that = (HttpHost) o; + if (!this.hostname.equalsIgnoreCase(that.hostname)) { + return false; + } + if (this.port != that.port) { + return false; + } + if (!this.protocol.equals(that.protocol)) { + return false; + } + // everything matches + return true; + } else { + return false; + } + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return + this.hostname.hashCode() + + this.port + + this.protocol.hashCode(); + } + +} Index: java/org/apache/commons/httpclient/ProxyHost.java =================================================================== RCS file: java/org/apache/commons/httpclient/ProxyHost.java diff -N java/org/apache/commons/httpclient/ProxyHost.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/ProxyHost.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,82 @@ +/* + * $Header$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 2002-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.commons.httpclient; + +import org.apache.commons.httpclient.protocol.Protocol; + +/** + * Holds all of the variables needed to describe an HTTP connection to a proxy. Proxy hosts + * always use plain HTTP connection when communicating with clients. + * + * @author Michael Becke + * @author Mike Bowler + * @author Oleg Kalnichevski + * @author Laura Werner + * + * @since 3.0 + */ +public class ProxyHost extends HttpHost { + + /** + * Copy constructor for HttpHost + * + * @param httphost the HTTP host to copy details from + */ + public ProxyHost (final ProxyHost httpproxy) { + super(httpproxy); + } + + /** + * Constructor for ProxyHost. + * + * @param hostname the hostname (IP or DNS name). Can be null. + * @param port the port. Value -1 can be used to set default protocol port + */ + public ProxyHost(final String hostname, int port) { + super(hostname, port, Protocol.getProtocol("http")); + } + + /** + * Constructor for HttpHost. + * + * @param hostname the hostname (IP or DNS name). Can be null. + */ + public ProxyHost(final String hostname) { + this(hostname, -1); + } + + /** + * @see java.lang.Object#clone() + */ + public Object clone() { + return new ProxyHost(this); + } + +}