commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient NoHostHttpConnectionManager.java TestHttpConnection.java
Date Wed, 22 Oct 2003 19:31:01 GMT
olegk       2003/10/22 12:31:01

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpClient.java HttpConnection.java
                        HttpConnectionManager.java HttpMethodBase.java
                        HttpMethodDirector.java
                        MultiThreadedHttpConnectionManager.java
                        SimpleHttpConnectionManager.java
               httpclient/src/java/org/apache/commons/httpclient/methods/multipart
                        PartBase.java
               httpclient/src/java/org/apache/commons/httpclient/params
                        HttpMethodParams.java
               httpclient/src/test/org/apache/commons/httpclient
                        NoHostHttpConnectionManager.java
                        TestHttpConnection.java
  Log:
  PR #15435 (New Preferences Architecture)
  
  - HttpConnection & HttpConnectionManager classes updated to take advantage of
  the new preference architecute.
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.87      +16 -4     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.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- HttpClient.java	11 Oct 2003 19:46:51 -0000	1.86
  +++ HttpClient.java	22 Oct 2003 19:31:00 -0000	1.87
  @@ -161,6 +161,9 @@
           if (this.httpConnectionManager == null) {
               this.httpConnectionManager = new SimpleHttpConnectionManager();
           }
  +        if (this.httpConnectionManager != null) {
  +            this.httpConnectionManager.getParams().setDefaults(this.params);
  +        }
       }
   
       /**
  @@ -184,6 +187,9 @@
           }
           this.params = params; 
           this.httpConnectionManager = httpConnectionManager;
  +        if (this.httpConnectionManager != null) {
  +            this.httpConnectionManager.getParams().setDefaults(this.params);
  +        }
       }
       
       /**
  @@ -534,6 +540,9 @@
           HttpConnectionManager httpConnectionManager
       ) {
           this.httpConnectionManager = httpConnectionManager;
  +        if (this.httpConnectionManager != null) {
  +            this.httpConnectionManager.getParams().setDefaults(this.params);
  +        }
       }
   
       /**
  @@ -555,6 +564,9 @@
        * @see HttpClientParams
        */
       public void setParams(final HttpClientParams params) {
  +        if (params == null) {
  +            throw new IllegalArgumentException("Parameters may not be null");
  +        }
           this.params = params;
       }
   
  
  
  
  1.76      +121 -53   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.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- HttpConnection.java	10 Sep 2003 21:37:48 -0000	1.75
  +++ HttpConnection.java	22 Oct 2003 19:31:00 -0000	1.76
  @@ -74,6 +74,7 @@
   import java.net.Socket;
   import java.net.SocketException;
   
  +import org.apache.commons.httpclient.params.HttpConnectionParams;
   import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory;
   import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
  @@ -95,11 +96,19 @@
    * </tr><tr>
    *    <td>{@link java.net.Socket#setTcpNoDelay(boolean)}
    *    <td>SO_NODELAY
  - *    <td>None
  + *    <td>{@link HttpConnectionParams#setTcpNoDelay(boolean)}
    * </tr><tr>
    *    <td>{@link java.net.Socket#setSoTimeout(int)}
    *    <td>SO_TIMEOUT
  - *    <td>{@link #setConnectionTimeout(int)}
  + *    <td>{@link HttpConnectionParams#setSoTimeout(int)}
  + * </tr><tr>
  + *    <td>{@link java.net.Socket#setSendBufferSize(int)}
  + *    <td>SO_SNDBUF
  + *    <td>{@link HttpConnectionParams#setSendBufferSize(int)}
  + * </tr><tr>
  + *    <td>{@link java.net.Socket#setReceiveBufferSize(int)}
  + *    <td>SO_RCVBUF
  + *    <td>{@link HttpConnectionParams#setReceiveBufferSize(int)}
    * </tr></table>
    *
    * @author Rod Waldhoff
  @@ -393,7 +402,7 @@
        * @return <tt>true</tt> if I am connected
        */
       public boolean isOpen() {
  -        if (used && isStaleCheckingEnabled() && isStale()) {
  +        if (used && this.params.isStaleCheckingEnabled() && isStale())
{
               LOG.debug("Connection is stale, closing...");
               close();
           }
  @@ -406,9 +415,12 @@
        * @return <code>true</code> if enabled
        * 
        * @see #isStale()
  +     * 
  +     * @deprecated Use {@link HttpConnectionParams#isStaleCheckingEnabled()},
  +     * {@link HttpConnection#getParams()}.
        */
       public boolean isStaleCheckingEnabled() {
  -        return staleCheckingEnabled;
  +        return this.params.isStaleCheckingEnabled();
       }
   
       /**
  @@ -418,9 +430,12 @@
        * 
        * @see #isStale()
        * @see #isOpen()
  +     * 
  +     * @deprecated Use {@link HttpConnectionParams#setStaleCheckingEnabled(boolean)},
  +     * {@link HttpConnection#getParams()}.
        */
       public void setStaleCheckingEnabled(boolean staleCheckEnabled) {
  -        this.staleCheckingEnabled = staleCheckEnabled;
  +        this.params.setStaleCheckingEnabled(staleCheckEnabled);
       }
   
       /**
  @@ -462,7 +477,7 @@
                               inputStream.unread(byteRead);
                           }
                       } finally {
  -                        socket.setSoTimeout(soTimeout);
  +                        socket.setSoTimeout(this.params.getSoTimeout());
                       }
                   }
               } catch (InterruptedIOException e) {
  @@ -525,6 +540,31 @@
       // --------------------------------------------------- Other Public Methods
   
       /**
  +     * Returns {@link HttpConnectionParams HTTP protocol parameters} associated with this
method.
  +     *
  +     * @return HTTP parameters.
  +     *
  +     * @since 2.1
  +     */
  +    public HttpConnectionParams getParams() {
  +        return this.params;
  +    }
  +
  +    /**
  +     * Assigns {@link HttpConnectionParams HTTP protocol parameters} for this method.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionParams
  +     */
  +    public void setParams(final HttpConnectionParams params) {
  +        if (params == null) {
  +            throw new IllegalArgumentException("Parameters may not be null");
  +        }
  +        this.params = params;
  +    }
  +
  +    /**
        * Set my {@link Socket}'s timeout, via {@link Socket#setSoTimeout}.  If the
        * connection is already open, the SO_TIMEOUT is changed.  If no connection
        * is open, then subsequent connections will use the timeout value.
  @@ -535,13 +575,33 @@
        * @throws SocketException - if there is an error in the underlying
        * protocol, such as a TCP error.
        * @throws IllegalStateException if I am not connected
  +     * 
  +     * @deprecated Use {@link HttpConnectionParams#setSoTimeout(int)},
  +     * {@link HttpConnection#getParams()}.
        */
       public void setSoTimeout(int timeout)
           throws SocketException, IllegalStateException {
  -        LOG.debug("HttpConnection.setSoTimeout(" + timeout + ")");
  -        soTimeout = timeout;
  -        if (socket != null) {
  -            socket.setSoTimeout(timeout);
  +        this.params.setSoTimeout(timeout);
  +        if (this.socket != null) {
  +            this.socket.setSoTimeout(timeout);
  +        }
  +    }
  +
  +    /**
  +     * Sets <code>SO_TIMEOUT</code> value directly on the underlying {@link
Socket socket}. 
  +     * This method does not change the default read timeout value set via 
  +     * {@link HttpConnectionParams}.
  +     *
  +     * @param timeout the timeout value
  +     * @throws SocketException - if there is an error in the underlying
  +     * protocol, such as a TCP error.
  +     * @throws IllegalStateException if I am not connected
  +     */
  +    public void setSocketTimeout(int timeout)
  +        throws SocketException, IllegalStateException {
  +        assertOpen();
  +        if (this.socket != null) {
  +            this.socket.setSoTimeout(timeout);
           }
       }
   
  @@ -553,14 +613,12 @@
        * Note: This is not a connection timeout but a timeout on network traffic!
        *
        * @return the timeout value
  +     * 
  +     * @deprecated Use {@link HttpConnectionParams#getSoTimeout()},
  +     * {@link HttpConnection#getParams()}.
        */
       public int getSoTimeout() throws SocketException {
  -        LOG.debug("HttpConnection.getSoTimeout()");
  -        if (this.socket != null) {
  -            return this.socket.getSoTimeout();
  -        } else {
  -            return this.soTimeout;
  -        }
  +        return this.params.getSoTimeout();
       }
   
       /**
  @@ -568,9 +626,12 @@
        * until a connection is established. The connection will fail after this
        * amount of time.
        * @param timeout The timeout in milliseconds. 0 means timeout is not used.
  +     * 
  +     * @deprecated Use {@link HttpConnectionParams#setConnectionTimeout(int)},
  +     * {@link HttpConnection#getParams()}.
        */
       public void setConnectionTimeout(int timeout) {
  -        this.connectTimeout = timeout;
  +        this.params.setConnectionTimeout(timeout);
       }
   
       /**
  @@ -599,7 +660,7 @@
                               ? new DefaultProtocolSocketFactory()
                               : protocolInUse.getSocketFactory());
   
  -                if (connectTimeout == 0) {
  +                if (this.params.getConnectionTimeout() == 0) {
                       if (localAddress != null) {
                           socket = socketFactory.createSocket(host, port, localAddress, 0);
                       } else {
  @@ -615,7 +676,7 @@
                               }
                           }
                       };
  -                    TimeoutController.execute(task, connectTimeout);
  +                    TimeoutController.execute(task, this.params.getConnectionTimeout());
                       socket = task.getSocket();
                       if (task.exception != null) {
                           throw task.exception;
  @@ -632,11 +693,16 @@
               situations. In such cases, nagling may be turned off through 
               use of the TCP_NODELAY sockets option." */
   
  -            socket.setTcpNoDelay(soNodelay);
  -            socket.setSoTimeout(soTimeout);
  -            if (sendBufferSize != -1) {
  -                socket.setSendBufferSize(sendBufferSize);
  -            }
  +            socket.setTcpNoDelay(this.params.getTcpNoDelay());
  +            socket.setSoTimeout(this.params.getSoTimeout());
  +            int sndBufSize = this.params.getSendBufferSize();
  +            if (sndBufSize >= 0) {
  +                socket.setSendBufferSize(sndBufSize);
  +            }        
  +            int rcvBufSize = this.params.getReceiveBufferSize();
  +            if (rcvBufSize >= 0) {
  +                socket.setReceiveBufferSize(rcvBufSize);
  +            }        
               inputStream = new PushbackInputStream(socket.getInputStream());
               outputStream = new BufferedOutputStream(
                   new WrappedOutputStream(socket.getOutputStream()),
  @@ -651,10 +717,19 @@
               throw e;
           } catch (TimeoutController.TimeoutException e) {
               if (LOG.isWarnEnabled()) {
  -                LOG.warn("The host " + hostName + ":" + portNumber
  -                        + " (or proxy " + proxyHostName + ":" + proxyPortNumber
  -                        + ") did not accept the connection within timeout of "
  -                        + connectTimeout + " milliseconds");
  +                StringBuffer buffer = new StringBuffer();
  +                buffer.append("The host "); 
  +                buffer.append(hostName); 
  +                buffer.append(":"); 
  +                buffer.append(portNumber); 
  +                buffer.append(" (or proxy "); 
  +                buffer.append(proxyHostName); 
  +                buffer.append(":"); 
  +                buffer.append(proxyPortNumber); 
  +                buffer.append(") did not accept the connection within timeout of "); 
  +                buffer.append(this.params.getConnectionTimeout()); 
  +                buffer.append(" milliseconds"); 
  +                LOG.warn(buffer.toString()); 
               }
               throw new ConnectionTimeoutException();
           }
  @@ -687,8 +762,13 @@
               (SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
   
           socket = socketFactory.createSocket(socket, hostName, portNumber, true);
  -        if (sendBufferSize != -1) {
  -            socket.setSendBufferSize(sendBufferSize);
  +        int sndBufSize = this.params.getSendBufferSize();
  +        if (sndBufSize >= 0) {
  +            socket.setSendBufferSize(sndBufSize);
  +        }        
  +        int rcvBufSize = this.params.getReceiveBufferSize();
  +        if (rcvBufSize >= 0) {
  +            socket.setReceiveBufferSize(rcvBufSize);
           }        
           inputStream = new PushbackInputStream(socket.getInputStream());
           outputStream = new BufferedOutputStream(
  @@ -805,7 +885,7 @@
                   }
               } finally {
                   try {
  -                    socket.setSoTimeout(soTimeout);
  +                    socket.setSoTimeout(this.params.getSoTimeout());
                   } catch (IOException ioe) {
                       LOG.debug("An error ocurred while resetting soTimeout, we will assume
that"
                           + " no response is available.",
  @@ -1146,12 +1226,12 @@
        * @throws SocketException if an error occurs while setting the socket value
        * 
        * @see Socket#setSendBufferSize(int)
  +     * 
  +     * @deprecated Use {@link HttpConnectionParams#setSendBufferSize(int)},
  +     * {@link HttpConnection#getParams()}.
        */
       public void setSendBufferSize(int sendBufferSize) throws SocketException {
  -        this.sendBufferSize = sendBufferSize;
  -        if (socket != null) {
  -            socket.setSendBufferSize(sendBufferSize);
  -        }
  +        this.params.setSendBufferSize(sendBufferSize);
       }
   
       // -- Timeout Exception
  @@ -1323,9 +1403,6 @@
       /** My OutputStream. */
       private OutputStream outputStream = null;
       
  -    /** the size of the buffer to use for the socket OutputStream */
  -    private int sendBufferSize = -1;
  -    
       /** An {@link InputStream} for the response to an individual request. */
       private InputStream lastResponseInputStream = null;
       
  @@ -1335,11 +1412,8 @@
       /** the protocol being used */
       private Protocol protocolInUse;
       
  -    /** SO_TIMEOUT socket value */
  -    private int soTimeout = 0;
  -    
  -    /** TCP_NODELAY socket value */
  -    private boolean soNodelay = true;
  +    /** Collection of HTTP parameters associated with this HTTP connection*/
  +    private HttpConnectionParams params = new HttpConnectionParams();
       
       /** flag to indicate if this connection can be released, if locked the connection cannot
be 
        * released */
  @@ -1350,12 +1424,6 @@
       
       /** Whether I am tunneling a proxy or not */
       private boolean tunnelEstablished = false;
  -    
  -    /** Whether or not isStale() is used by isOpen() */
  -    private boolean staleCheckingEnabled = true;    
  -
  -    /** Timeout until connection established (Socket created). 0 means no timeout. */
  -    private int connectTimeout = 0;
       
       /** the connection manager that created this connection or null */
       private HttpConnectionManager httpConnectionManager;
  
  
  
  1.17      +25 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java
  
  Index: HttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- HttpConnectionManager.java	16 Jul 2003 20:48:27 -0000	1.16
  +++ HttpConnectionManager.java	22 Oct 2003 19:31:00 -0000	1.17
  @@ -63,6 +63,8 @@
   
   package org.apache.commons.httpclient;
   
  +import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
  +
   /**
    * An interface for classes that manage HttpConnections.
    * 
  @@ -147,4 +149,24 @@
        * @param conn - The HttpConnection to make available.
        */
       void releaseConnection(HttpConnection conn);
  +
  +    /**
  +     * Returns {@link HttpConnectionManagerParams parameters} associated 
  +     * with this connection manager.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionManagerParams
  +     */
  +    public HttpConnectionManagerParams getParams();
  +
  +    /**
  +     * Assigns {@link HttpConnectionManagerParams parameters} for this 
  +     * connection manager.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionManagerParams
  +     */
  +    public void setParams(final HttpConnectionManagerParams params);
   }
  
  
  
  1.186     +11 -8     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.185
  retrieving revision 1.186
  diff -u -r1.185 -r1.186
  --- HttpMethodBase.java	21 Oct 2003 20:13:28 -0000	1.185
  +++ HttpMethodBase.java	22 Oct 2003 19:31:00 -0000	1.186
  @@ -1708,7 +1708,7 @@
               int len = encodings.length;            
               if ((len > 0) && ("chunked".equalsIgnoreCase(encodings[len - 1].getName())))
{ 
                   // if response body is empty
  -                if (conn.isResponseAvailable(conn.getSoTimeout())) {
  +                if (conn.isResponseAvailable(conn.getParams().getSoTimeout())) {
                       result = new ChunkedInputStream(is, this);
                   } else {
                       if (getParams().isParameterTrue(HttpMethodParams.STRICT_TRANSFER_ENCODING))
{
  @@ -1926,9 +1926,9 @@
           if ((expectvalue != null) 
            && (expectvalue.compareToIgnoreCase("100-continue") == 0)) {
               if (ver.greaterEquals(HttpVersion.HTTP_1_1)) {
  -                int readTimeout = conn.getSoTimeout();
  +                int readTimeout = conn.getParams().getSoTimeout();
                   try {
  -                    conn.setSoTimeout(RESPONSE_WAIT_TIME_MS);
  +                    conn.setSocketTimeout(RESPONSE_WAIT_TIME_MS);
                       readStatusLine(state, conn);
                       processStatusLine(state, conn);
                       readResponseHeaders(state, conn);
  @@ -1948,7 +1948,7 @@
                       removeRequestHeader("Expect");
                       LOG.info("100 (continue) read timeout. Resume sending the request");
                   } finally {
  -                    conn.setSoTimeout(readTimeout);
  +                    conn.setSocketTimeout(readTimeout);
                   }
                   
               } else {
  @@ -2095,6 +2095,9 @@
        * @see HttpMethodParams
        */
       public void setParams(final HttpMethodParams params) {
  +        if (params == null) {
  +            throw new IllegalArgumentException("Parameters may not be null");
  +        }
           this.params = params;
       }
   
  
  
  
  1.7       +3 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- HttpMethodDirector.java	15 Oct 2003 02:12:18 -0000	1.6
  +++ HttpMethodDirector.java	22 Oct 2003 19:31:00 -0000	1.7
  @@ -244,8 +244,6 @@
               
               if (!connection.isOpen()) {
                   // this connection must be opened before it can be used
  -                connection.setSoTimeout(this.params.getSoTimeout());
  -                connection.setConnectionTimeout(this.params.getConnectionTimeout());
                   connection.open();
                   if (connection.isProxied() && connection.isSecure()) {
                       // we need to create a secure tunnel before we can execute the real
method
  
  
  
  1.26      +81 -11    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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- MultiThreadedHttpConnectionManager.java	26 Sep 2003 02:44:18 -0000	1.25
  +++ MultiThreadedHttpConnectionManager.java	22 Oct 2003 19:31:00 -0000	1.26
  @@ -77,6 +77,8 @@
   import java.util.LinkedList;
   import java.util.Map;
   
  +import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
  +import org.apache.commons.httpclient.params.HttpConnectionParams;
   import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -104,15 +106,17 @@
       public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
   
       // ----------------------------------------------------- Instance Variables
  +    /**
  +     * Collection of parameters associated with this connection manager.
  +     */
  +    private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); 
  +
       /** Maximum number of connections allowed per host */
       private int maxHostConnections = DEFAULT_MAX_HOST_CONNECTIONS;
   
       /** Maximum number of connections allowed overall */
       private int maxTotalConnections = DEFAULT_MAX_TOTAL_CONNECTIONS;
   
  -    /** The value to set when calling setStaleCheckingEnabled() on each connection */
  -    private boolean connectionStaleCheckingEnabled = true;
  -
       /** Connection Pool */
       private ConnectionPool connectionPool;
   
  @@ -144,9 +148,12 @@
        * @return <code>true</code> if stale checking will be enabled on HttpConections
        * 
        * @see HttpConnection#isStaleCheckingEnabled()
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#isStaleCheckingEnabled()},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public boolean isConnectionStaleCheckingEnabled() {
  -        return connectionStaleCheckingEnabled;
  +        return this.params.isStaleCheckingEnabled();
       }
   
       /**
  @@ -156,9 +163,12 @@
        * on HttpConections
        * 
        * @see HttpConnection#setStaleCheckingEnabled(boolean)
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#setStaleCheckingEnabled(boolean)},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled)
{
  -        this.connectionStaleCheckingEnabled = connectionStaleCheckingEnabled;
  +        this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
       }
   
       /**
  @@ -438,9 +448,35 @@
   
           return connectionConfiguration;
       }
  -    
   
       /**
  +     * Returns {@link HttpConnectionManagerParams parameters} associated 
  +     * with this connection manager.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionManagerParams
  +     */
  +    public HttpConnectionManagerParams getParams() {
  +        return this.params;
  +    }
  +
  +    /**
  +     * Assigns {@link HttpConnectionManagerParams parameters} for this 
  +     * connection manager.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionManagerParams
  +     */
  +    public void setParams(final HttpConnectionManagerParams params) {
  +        if (params == null) {
  +            throw new IllegalArgumentException("Parameters may not be null");
  +        }
  +        this.params = params;
  +    }
  +    
  +    /**
        * Global Connection Pool, including per-host pools
        */
       private class ConnectionPool {
  @@ -478,7 +514,7 @@
                       LOG.debug("Allocating new connection, hostConfig=" + hostConfiguration);
                   }
                   connection = new HttpConnection(hostConfiguration);
  -                connection.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
  +                connection.getParams().setDefaults(MultiThreadedHttpConnectionManager.this.params);
                   connection.setHttpConnectionManager(MultiThreadedHttpConnectionManager.this);
                   numConnections++;
                   hostPool.numConnections++;
  @@ -806,6 +842,9 @@
               }
           }
   
  +        /**
  +         * @deprecated
  +         */
           public boolean isStaleCheckingEnabled() {
               if (hasConnection()) {
                   return wrappedConnection.isStaleCheckingEnabled();
  @@ -821,7 +860,10 @@
                   throw new IllegalStateException("Connection has been released");
               }
           }
  -
  +    
  +        /**
  +         * @deprecated 
  +         */
           public void setStaleCheckingEnabled(boolean staleCheckEnabled) {
               if (hasConnection()) {
                   wrappedConnection.setStaleCheckingEnabled(staleCheckEnabled);
  @@ -1005,6 +1047,9 @@
               }
           }
   
  +        /**
  +         * @deprecated
  +         */
           public void setConnectionTimeout(int timeout) {
               if (hasConnection()) {
                   wrappedConnection.setConnectionTimeout(timeout);
  @@ -1069,6 +1114,9 @@
               }
           }
   
  +        /**
  +         * @deprecated
  +         */
           public void setSoTimeout(int timeout)
               throws SocketException, IllegalStateException {
               if (hasConnection()) {
  @@ -1138,6 +1186,9 @@
               }
           }
   
  +        /**
  +         * @deprecated
  +         */
           public int getSoTimeout() throws SocketException {
               if (hasConnection()) {
                   return wrappedConnection.getSoTimeout();
  @@ -1170,9 +1221,28 @@
               }
           }
   
  +        /**
  +         * @deprecated
  +         */
           public void setSendBufferSize(int sendBufferSize) throws SocketException {
               if (hasConnection()) {
                   wrappedConnection.setSendBufferSize(sendBufferSize);
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public HttpConnectionParams getParams() {
  +            if (hasConnection()) {
  +                return wrappedConnection.getParams();
  +            } else {
  +                throw new IllegalStateException("Connection has been released");
  +            }
  +        }
  +
  +        public void setParams(final HttpConnectionParams params) {
  +            if (hasConnection()) {
  +                wrappedConnection.setParams(params);
               } else {
                   throw new IllegalStateException("Connection has been released");
               }
  
  
  
  1.16      +43 -15    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SimpleHttpConnectionManager.java	12 Aug 2003 02:35:17 -0000	1.15
  +++ SimpleHttpConnectionManager.java	22 Oct 2003 19:31:00 -0000	1.16
  @@ -66,6 +66,8 @@
   import java.io.IOException;
   import java.io.InputStream;
   
  +import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
  +
   /**
    * A connection manager that provides access to a single HttpConnection.  This
    * manager makes no attempt to provide exclusive access to the contained
  @@ -84,15 +86,10 @@
       /** The http connection */
       private HttpConnection httpConnection;
   
  -    /** The value to set when calling setStaleCheckingEnabled() on connections */
  -    private boolean connectionStaleCheckingEnabled = true;
  -
       /**
  -     * Constructor for SimpleHttpConnectionManager.
  +     * Collection of parameters associated with this connection manager.
        */
  -    public SimpleHttpConnectionManager() {
  -        super();
  -    }
  +    private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); 
   
       /**
        * @see HttpConnectionManager#getConnection(HostConfiguration)
  @@ -107,9 +104,12 @@
        * @return <code>true</code> if stale checking will be enabled on HttpConections
        * 
        * @see HttpConnection#isStaleCheckingEnabled()
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#isStaleCheckingEnabled()},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public boolean isConnectionStaleCheckingEnabled() {
  -        return connectionStaleCheckingEnabled;
  +        return this.params.isStaleCheckingEnabled();
       }
   
       /**
  @@ -119,9 +119,12 @@
        * on HttpConections
        * 
        * @see HttpConnection#setStaleCheckingEnabled(boolean)
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#setStaleCheckingEnabled(boolean)},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled)
{
  -        this.connectionStaleCheckingEnabled = connectionStaleCheckingEnabled;
  +        this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
       }
       
       /**
  @@ -133,7 +136,7 @@
           if (httpConnection == null) {
               httpConnection = new HttpConnection(hostConfiguration);
               httpConnection.setHttpConnectionManager(this);
  -            httpConnection.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
  +            httpConnection.getParams().setDefaults(this.params);
           } else {
   
               // make sure the host and proxy are correct for this connection
  @@ -145,8 +148,6 @@
                       httpConnection.close();
                   }
   
  -                httpConnection.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
  -
                   httpConnection.setHost(hostConfiguration.getHost());
                   httpConnection.setVirtualHost(hostConfiguration.getVirtualHost());
                   httpConnection.setPort(hostConfiguration.getPort());
  @@ -201,5 +202,32 @@
                   conn.close();
               }
           }
  +    }
  +
  +    /**
  +     * Returns {@link HttpConnectionManagerParams parameters} associated 
  +     * with this connection manager.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionManagerParams
  +     */
  +    public HttpConnectionManagerParams getParams() {
  +        return this.params;
  +    }
  +
  +    /**
  +     * Assigns {@link HttpConnectionManagerParams parameters} for this 
  +     * connection manager.
  +     * 
  +     * @since 2.1
  +     * 
  +     * @see HttpConnectionManagerParams
  +     */
  +    public void setParams(final HttpConnectionManagerParams params) {
  +        if (params == null) {
  +            throw new IllegalArgumentException("Parameters may not be null");
  +        }
  +        this.params = params;
       }
   }
  
  
  
  1.3       +4 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartBase.java
  
  Index: PartBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartBase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PartBase.java	10 Oct 2003 04:18:35 -0000	1.2
  +++ PartBase.java	22 Oct 2003 19:31:00 -0000	1.3
  @@ -88,7 +88,7 @@
        * 
        * @param name The name of the part
        * @param contentType The content type, or <code>null</code>
  -     * @param charset The character encoding, or <code>null</code> 
  +     * @param charSet The character encoding, or <code>null</code> 
        * @param transferEncoding The transfer encoding, or <code>null</code>
        */
       public PartBase(String name, String contentType, String charSet, String transferEncoding)
{
  
  
  
  1.5       +5 -5      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HttpMethodParams.java	20 Oct 2003 22:17:12 -0000	1.4
  +++ HttpMethodParams.java	22 Oct 2003 19:31:00 -0000	1.5
  @@ -195,7 +195,7 @@
        * @see #getDefaultParams()
        */
       public HttpMethodParams() {
  -        super();
  +        super(null);
       }
   
       /**
  
  
  
  1.4       +18 -0     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NoHostHttpConnectionManager.java	17 Sep 2003 03:53:25 -0000	1.3
  +++ NoHostHttpConnectionManager.java	22 Oct 2003 19:31:00 -0000	1.4
  @@ -9,6 +9,8 @@
   import java.io.IOException;
   import java.io.InputStream;
   
  +import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
  +
   /**
    */
   public class NoHostHttpConnectionManager implements HttpConnectionManager {
  @@ -16,6 +18,8 @@
       private HttpConnection connection;
       
       private boolean connectionReleased = false;
  +    
  +    private HttpConnectionManagerParams params = new HttpConnectionManagerParams(); 
   
       public NoHostHttpConnectionManager() { 
           setConnection(new SimpleHttpConnection());
  @@ -34,6 +38,7 @@
       public void setConnection(HttpConnection connection) {
           this.connection = connection;
           connection.setHttpConnectionManager(this);
  +        connection.getParams().setDefaults(this.params);
       }
   
       public HttpConnection getConnection(HostConfiguration hostConfiguration) {
  @@ -63,6 +68,9 @@
           return connection;
       }
   
  +    /**
  +     * @deprecated
  +     */
       public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout)
           throws HttpException {
           return getConnection(hostConfiguration);
  @@ -103,5 +111,15 @@
           }
       }
   
  +    public HttpConnectionManagerParams getParams() {
  +        return this.params;
  +    }
  +
  +    public void setParams(final HttpConnectionManagerParams params) {
  +        if (params == null) {
  +            throw new IllegalArgumentException("Parameters may not be null");
  +        }
  +        this.params = params;
  +    }
   
   }
  
  
  
  1.12      +1 -1      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnection.java
  
  Index: TestHttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnection.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestHttpConnection.java	3 Oct 2003 20:57:36 -0000	1.11
  +++ TestHttpConnection.java	22 Oct 2003 19:31:00 -0000	1.12
  @@ -157,7 +157,7 @@
   
           HttpConnection conn = new HttpConnection(getHost(), getPort(), testProtocol);
           // 1 ms is short enough to make this fail
  -        conn.setConnectionTimeout(1);
  +        conn.getParams().setConnectionTimeout(1);
           try {
               conn.open();
               fail("Should have timed out");
  
  
  

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


Mime
View raw message