You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2004/10/06 19:32:05 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params TestHttpParams.java

olegk       2004/10/06 10:32:04

  Modified:    httpclient/src/contrib/org/apache/commons/httpclient/contrib/utils
                        HttpMethodCloner.java
               httpclient/src/java/org/apache/commons/httpclient
                        HostConfiguration.java HttpClient.java
                        HttpConnection.java HttpMethod.java
                        HttpMethodBase.java HttpMethodDirector.java
                        MultiThreadedHttpConnectionManager.java
                        SimpleHttpConnectionManager.java
               httpclient/src/java/org/apache/commons/httpclient/auth
                        HttpAuthenticator.java
               httpclient/src/java/org/apache/commons/httpclient/params
                        HostParams.java HttpMethodParams.java
               httpclient/src/test/org/apache/commons/httpclient
                        NoHostHttpConnectionManager.java
                        TestAuthenticator.java TestNoHost.java
               httpclient/src/test/org/apache/commons/httpclient/params
                        TestHttpParams.java
  Added:       httpclient/src/java/org/apache/commons/httpclient
                        HttpHost.java ProxyHost.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestVirtualHost.java
  Log:
  PR #31471 (HostConfiguration handling requires cleanup)
  
  Changelog:
  
  * HttpMethods no longer contain a HostConfiguration instance.
  * HostConfiguration heavily refactored
  * The virtual host logic out of HttpConnection and HostConfiguration classes and moved it to the HttpMethodParams & HostParams
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.7       +0 -5      jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/utils/HttpMethodCloner.java
  
  Index: HttpMethodCloner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/contrib/org/apache/commons/httpclient/contrib/utils/HttpMethodCloner.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HttpMethodCloner.java	4 May 2004 21:24:51 -0000	1.6
  +++ HttpMethodCloner.java	6 Oct 2004 17:32:03 -0000	1.7
  @@ -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) {
  
  
  
  1.20      +142 -173  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java
  
  Index: HostConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- HostConfiguration.java	17 Jul 2004 18:58:33 -0000	1.19
  +++ HostConfiguration.java	6 Oct 2004 17:32:03 -0000	1.20
  @@ -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;
  +    private ProxyHost proxyHost = null;
   
  -    /** The port number of the proxy server */
  -    private int proxyPort;
  -
  -    /** 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(this.localAddress);
               if (appendComma) {
                   b.append(", ");
               } else {
                   appendComma = true;
               }
  -            b.append("localAddress=").append(localAddress);
  +            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 <code>true</code> 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 <code>null</code>
        * @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 <code>null</code> 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;
  +        }
       }
   
       /**
  @@ -452,6 +435,7 @@
        * 
        * @param localAddress the local address to use
        */
  +    
       public synchronized void setLocalAddress(InetAddress localAddress) {
           this.localAddress = localAddress;
       }
  @@ -462,6 +446,7 @@
        * 
        * @return the local address to be used when creating Sockets, or <code>null</code>
        */
  +    
       public synchronized InetAddress getLocalAddress() {
           return this.localAddress;
       }
  @@ -494,7 +479,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 +488,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 +529,6 @@
        * @see java.lang.Object#hashCode()
        */
       public int hashCode() {
  -        
           if (host != null) {
               return host.hashCode();
           } else if (proxyHost != null) {
  
  
  
  1.97      +16 -61    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
  
  Index: HttpClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- HttpClient.java	14 Jun 2004 21:25:38 -0000	1.96
  +++ HttpClient.java	6 Oct 2004 17:32:03 -0000	1.97
  @@ -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 defaults
  +            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();
       }
  
  
  
  1.101     +35 -12    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- HttpConnection.java	15 Sep 2004 20:32:21 -0000	1.100
  +++ HttpConnection.java	6 Oct 2004 17:32:03 -0000	1.101
  @@ -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;
  
  
  
  1.42      +14 -5     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java
  
  Index: HttpMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- HttpMethod.java	5 Jul 2004 22:46:58 -0000	1.41
  +++ HttpMethod.java	6 Oct 2004 17:32:03 -0000	1.42
  @@ -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 <code>null</code> if none is set
        */
       HostConfiguration getHostConfiguration();
  +
  +    /**
  +     * Gets the target host for this method. 
  +     * 
  +     * @return the {@link HttpHost} or <code>null</code> if none is set
  +     */
  +    HttpHost getHost();
   
       /**
        * Sets the path of the HTTP method.
  
  
  
  1.217     +33 -26    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.216
  retrieving revision 1.217
  diff -u -r1.216 -r1.217
  --- HttpMethodBase.java	30 Sep 2004 18:15:22 -0000	1.216
  +++ HttpMethodBase.java	6 Oct 2004 17:32:03 -0000	1.217
  @@ -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;
  +        }
       }
   
       /**
  
  
  
  1.31      +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
  
  Index: HttpMethodDirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- HttpMethodDirector.java	15 Sep 2004 20:42:17 -0000	1.30
  +++ HttpMethodDirector.java	6 Oct 2004 17:32:04 -0000	1.31
  @@ -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();
           }
  
  
  
  1.45      +9 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java
  
  Index: MultiThreadedHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- MultiThreadedHttpConnectionManager.java	30 Sep 2004 18:15:22 -0000	1.44
  +++ MultiThreadedHttpConnectionManager.java	6 Oct 2004 17:32:04 -0000	1.45
  @@ -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);
  
  
  
  1.22      +3 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java
  
  Index: SimpleHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SimpleHttpConnectionManager.java	13 May 2004 04:03:25 -0000	1.21
  +++ SimpleHttpConnectionManager.java	6 Oct 2004 17:32:04 -0000	1.22
  @@ -144,7 +144,6 @@
                   }
   
                   httpConnection.setHost(hostConfiguration.getHost());
  -                httpConnection.setVirtualHost(hostConfiguration.getVirtualHost());
                   httpConnection.setPort(hostConfiguration.getPort());
                   httpConnection.setProtocol(hostConfiguration.getProtocol());
                   httpConnection.setLocalAddress(hostConfiguration.getLocalAddress());
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpHost.java
  
  Index: HttpHost.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpHost.java,v 1.1 2004/10/06 17:32:03 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/10/06 17:32:03 $
   *
   * ====================================================================
   *
   *  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
   * <http://www.apache.org/>.
   *
   */
  
  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 <a href="mailto:becke@u.washington.edu">Michael Becke</a>
   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
   * @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 <code>null</code>.
       * @param virtualHostname the virtual hostname. Can be <code>null</code>.
       * @param port the port. Value <code>-1</code> can be used to set default protocol port
       * @param protocol the protocol. Value <code>null</code> 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 <code>null</code>.
       * @param port the port. Value <code>-1</code> 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 <code>null</code>.
       */
      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 <code>null</code> if not set
       */
      public String getHostName() {
          return this.hostname;
      }
  
      /**
       * Returns the port.
       * 
       * @return the host port, or <code>-1</code> 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();
      }
  
  }
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ProxyHost.java
  
  Index: ProxyHost.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ProxyHost.java,v 1.1 2004/10/06 17:32:04 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/10/06 17:32:04 $
   *
   * ====================================================================
   *
   *  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
   * <http://www.apache.org/>.
   *
   */
  
  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 <a href="mailto:becke@u.washington.edu">Michael Becke</a>
   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
   * @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 <code>null</code>.
       * @param port the port. Value <code>-1</code> 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 <code>null</code>.
       */
      public ProxyHost(final String hostname) {
          this(hostname, -1);
      }
      
      /**
       * @see java.lang.Object#clone()
       */
      public Object clone() {
          return new ProxyHost(this);
      }    
      
  }
  
  
  
  1.19      +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/HttpAuthenticator.java
  
  Index: HttpAuthenticator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/HttpAuthenticator.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- HttpAuthenticator.java	18 Apr 2004 23:51:36 -0000	1.18
  +++ HttpAuthenticator.java	6 Oct 2004 17:32:04 -0000	1.19
  @@ -61,7 +61,7 @@
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Rodney Waldhoff
    * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
  - * @author Ortwin Gl�ck
  + * @author Ortwin Gl�ck
    * @author Sean C. Sullivan
    * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
    * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  @@ -273,7 +273,7 @@
               if (proxy) {
                   host = conn.getProxyHost();
               } else {
  -                host = conn.getVirtualHost();
  +                host = method.getParams().getVirtualHost();
                   if (host == null) {
                       host = conn.getHost();
                   }
  
  
  
  1.5       +23 -4     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HostParams.java
  
  Index: HostParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HostParams.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HostParams.java	19 Sep 2004 19:07:21 -0000	1.4
  +++ HostParams.java	6 Oct 2004 17:32:04 -0000	1.5
  @@ -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);
  +    }
  +        
   }
  
  
  
  1.17      +30 -4     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java
  
  Index: HttpMethodParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- HttpMethodParams.java	6 Oct 2004 03:39:59 -0000	1.16
  +++ HttpMethodParams.java	6 Oct 2004 17:32:04 -0000	1.17
  @@ -258,6 +258,14 @@
       public static final String BUFFER_WARN_TRIGGER_LIMIT = "http.method.response.buffer.warnlimit";
       
       /**
  +     * Defines the virtual host name.
  +     * <p>
  +     * This parameter expects a value of type {@link java.lang.String}. 
  +     * </p>
  +     */
  +    public static final String VIRTUAL_HOST = "http.virtual-host"; 
  +
  +    /**
        * Sets the value to use as the multipart boundary.
        * <p>
        * This parameter expects a value if type {@link String}.
  @@ -434,6 +442,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,
  
  
  
  1.8       +3 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java
  
  Index: NoHostHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NoHostHttpConnectionManager.java	5 Jul 2004 22:46:59 -0000	1.7
  +++ NoHostHttpConnectionManager.java	6 Oct 2004 17:32:04 -0000	1.8
  @@ -84,7 +84,6 @@
               }
   
               connection.setHost(hostConfiguration.getHost());
  -            connection.setVirtualHost(hostConfiguration.getVirtualHost());
               connection.setPort(hostConfiguration.getPort());
               connection.setProtocol(hostConfiguration.getProtocol());
               connection.setLocalAddress(hostConfiguration.getLocalAddress());
  
  
  
  1.44      +5 -5      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java
  
  Index: TestAuthenticator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- TestAuthenticator.java	13 Jun 2004 12:13:08 -0000	1.43
  +++ TestAuthenticator.java	6 Oct 2004 17:32:04 -0000	1.44
  @@ -97,7 +97,7 @@
                   host = conn.getProxyHost();
                   port = conn.getProxyPort();
               } else {
  -                host = conn.getVirtualHost();
  +                host = method.getParams().getVirtualHost();
                   if (host == null) {
                       host = conn.getHost();
                   }
  
  
  
  1.42      +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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- TestNoHost.java	6 Oct 2004 03:39:58 -0000	1.41
  +++ TestNoHost.java	6 Oct 2004 17:32:04 -0000	1.42
  @@ -91,6 +91,7 @@
           suite.addTestSuite(TestIdleConnectionTimeout.class);
           suite.addTest(TestMethodAbort.suite());
           suite.addTest(TestHttpParams.suite());
  +        suite.addTest(TestVirtualHost.suite());
           suite.addTest(TestMultipartPost.suite());
           return suite;
       }
  
  
  
  1.1                  jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestVirtualHost.java
  
  Index: TestVirtualHost.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestVirtualHost.java,v 1.1 2004/10/06 17:32:04 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/10/06 17:32:04 $
   * ====================================================================
   *
   *  Copyright 1999-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
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.commons.httpclient;
  
  import java.io.IOException;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.httpclient.methods.GetMethod;
  import org.apache.commons.httpclient.server.HttpService;
  import org.apache.commons.httpclient.server.SimpleRequest;
  import org.apache.commons.httpclient.server.SimpleResponse;
  
  /**
   * HTTP protocol versioning tests.
   *
   * @author Oleg Kalnichevski
   * 
   * @version $Revision: 1.1 $
   */
  public class TestVirtualHost extends HttpClientTestBase {
  
      // ------------------------------------------------------------ Constructor
      public TestVirtualHost(String testName) {
          super(testName);
      }
  
      // ------------------------------------------------------------------- Main
      public static void main(String args[]) {
          String[] testCaseName = { TestVirtualHost.class.getName() };
          junit.textui.TestRunner.main(testCaseName);
      }
  
      // ------------------------------------------------------- TestCase Methods
  
      public static Test suite() {
          return new TestSuite(TestVirtualHost.class);
      }
  
      private class VirtualService implements HttpService {
  
          public VirtualService() {
              super();
          }
  
          public boolean process(final SimpleRequest request, final SimpleResponse response)
              throws IOException
          {
              HttpVersion httpversion = request.getRequestLine().getHttpVersion();
              Header hostheader = request.getFirstHeader("Host");
              if (hostheader == null) {
                  response.setStatusLine(httpversion, HttpStatus.SC_BAD_REQUEST);
                  response.setBodyString("Host header missing");
              } else {
                  response.setStatusLine(httpversion, HttpStatus.SC_OK);
                  response.setBodyString(hostheader.getValue());
              }
              return true;
          }
      }
  
      public void testVirtualHostHeader() throws IOException {
          this.server.setHttpService(new VirtualService());
  
          GetMethod httpget = new GetMethod("/test/");
          
          HostConfiguration hostconf = new HostConfiguration();
          hostconf.setHost(this.server.getLocalAddress(), this.server.getLocalPort(), "http");
          hostconf.getParams().setVirtualHost("somehost");
          try {
              this.client.executeMethod(hostconf, httpget);
              String hostheader = "somehost:" + this.server.getLocalPort();
              assertEquals(hostheader, httpget.getResponseBodyAsString());
          } finally {
              httpget.releaseConnection();
          }
      }
  
      public void testNoVirtualHostHeader() throws IOException {
          this.server.setHttpService(new VirtualService());
  
          GetMethod httpget = new GetMethod("/test/");
          
          HostConfiguration hostconf = new HostConfiguration();
          hostconf.setHost(this.server.getLocalAddress(), this.server.getLocalPort(), "http");
          hostconf.getParams().setVirtualHost(null);
          try {
              this.client.executeMethod(hostconf, httpget);
              String hostheader = this.server.getLocalAddress() + ":" + this.server.getLocalPort();
              assertEquals(hostheader, httpget.getResponseBodyAsString());
          } finally {
              httpget.releaseConnection();
          }
      }
  }
  
  
  
  1.3       +30 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java
  
  Index: TestHttpParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/params/TestHttpParams.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestHttpParams.java	15 Sep 2004 20:45:48 -0000	1.2
  +++ TestHttpParams.java	6 Oct 2004 17:32:04 -0000	1.3
  @@ -130,4 +130,30 @@
           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));
  +    }
   }
  
  
  

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