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 2003/10/26 10:49:16 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestHttpConnection.java TestHttpConnectionManager.java

olegk       2003/10/26 01:49:16

  Modified:    httpclient/src/examples ClientApp.java CookieDemoApp.java
                        MultipartFileUploadApp.java TrivialApp.java
               httpclient/src/java/org/apache/commons/httpclient
                        HttpClient.java
                        MultiThreadedHttpConnectionManager.java
               httpclient/src/java/org/apache/commons/httpclient/params
                        HttpClientParams.java
                        HttpConnectionManagerParams.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestHttpConnection.java
                        TestHttpConnectionManager.java
  Log:
  PR #15435 (New Preferences Architecture)
  
  - SocketTimeout/ConnectionTimeout removed from the HttpClientParams class.
  - MultithreadedConnectionManager updated to take advantage of the new preference architecture
  
  Contributed by Oleg Kalnichevski
  Reviewed by Michael Becke
  
  Revision  Changes    Path
  1.13      +2 -1      jakarta-commons/httpclient/src/examples/ClientApp.java
  
  Index: ClientApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/ClientApp.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ClientApp.java	3 Oct 2003 20:57:35 -0000	1.12
  +++ ClientApp.java	26 Oct 2003 09:49:16 -0000	1.13
  @@ -121,7 +121,8 @@
           
           public HttpClientFrame() {            
               client = new HttpClient(new MultiThreadedHttpConnectionManager());
  -            client.getParams().setConnectionTimeout(30000);
  +            client.getHttpConnectionManager().
  +                getParams().setConnectionTimeout(30000);
   
               JPanel panInput = new JPanel(new FlowLayout());
   
  
  
  
  1.13      +5 -4      jakarta-commons/httpclient/src/examples/CookieDemoApp.java
  
  Index: CookieDemoApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- CookieDemoApp.java	20 Oct 2003 22:17:11 -0000	1.12
  +++ CookieDemoApp.java	26 Oct 2003 09:49:16 -0000	1.13
  @@ -111,7 +111,8 @@
   
           // Get HTTP client instance
           HttpClient httpclient = new HttpClient();
  -        httpclient.getParams().setConnectionTimeout(30000);
  +        httpclient.getHttpConnectionManager().
  +            getParams().setConnectionTimeout(30000);
           httpclient.setState(initialState);
   
           // RFC 2101 cookie management spec is used per default
  
  
  
  1.8       +2 -1      jakarta-commons/httpclient/src/examples/MultipartFileUploadApp.java
  
  Index: MultipartFileUploadApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/MultipartFileUploadApp.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MultipartFileUploadApp.java	3 Oct 2003 20:57:35 -0000	1.7
  +++ MultipartFileUploadApp.java	26 Oct 2003 09:49:16 -0000	1.8
  @@ -188,7 +188,8 @@
                           appendMessage("Uploading " + targetFile.getName() + " to " + targetURL);
                           filePost.addParameter(targetFile.getName(), targetFile);
                           HttpClient client = new HttpClient();
  -                        client.getParams().setConnectionTimeout(5000);
  +                        client.getHttpConnectionManager().
  +                            getParams().setConnectionTimeout(5000);
                           int status = client.executeMethod(filePost);
                           if (status == HttpStatus.SC_OK) {
                               appendMessage(
  
  
  
  1.15      +5 -4      jakarta-commons/httpclient/src/examples/TrivialApp.java
  
  Index: TrivialApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/TrivialApp.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TrivialApp.java	3 Oct 2003 20:57:35 -0000	1.14
  +++ TrivialApp.java	26 Oct 2003 09:49:16 -0000	1.15
  @@ -110,7 +110,8 @@
           HttpClient client = new HttpClient();
   
           //establish a connection within 5 seconds
  -        client.getParams().setConnectionTimeout(5000);
  +        client.getHttpConnectionManager().
  +            getParams().setConnectionTimeout(5000);
   
           //set the default credentials
           if (creds != null) {
  
  
  
  1.88      +10 -10    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.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- HttpClient.java	22 Oct 2003 19:31:00 -0000	1.87
  +++ HttpClient.java	26 Oct 2003 09:49:16 -0000	1.88
  @@ -296,12 +296,12 @@
        *
        * @param newTimeoutInMilliseconds Timeout in milliseconds
        * 
  -     * @deprecated Use {@link HttpClientParams#setSoTimeout(int)},
  -     * {@link HttpClient#getParams()}.
  +     * @deprecated Use {@link HttpConnectionManagerParams#setSoTimeout(int)},
  +     * {@link HttpConnectionManager#getParams()}.
        *
        */
       public synchronized void setTimeout(int newTimeoutInMilliseconds) {
  -        this.params.setSoTimeout(newTimeoutInMilliseconds);
  +        this.httpConnectionManager.getParams().setSoTimeout(newTimeoutInMilliseconds);
       }
   
       /**
  @@ -327,11 +327,11 @@
        * @see HttpConnection#setConnectionTimeout(int)
        * @param newTimeoutInMilliseconds Timeout in milliseconds.
        * 
  -     * @deprecated Use {@link HttpClientParams#setConnectionTimeout(int)},
  -     * {@link HttpClient#getParams()}.
  +     * @deprecated Use {@link HttpConnectionManagerParams#setConnectionTimeout(int)},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public synchronized void setConnectionTimeout(int newTimeoutInMilliseconds) {
  -       this.params.setConnectionTimeout(newTimeoutInMilliseconds);
  +       this.httpConnectionManager.getParams().setConnectionTimeout(newTimeoutInMilliseconds);
       }
   
       // --------------------------------------------------------- Public Methods
  
  
  
  1.27      +34 -13    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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- MultiThreadedHttpConnectionManager.java	22 Oct 2003 19:31:00 -0000	1.26
  +++ MultiThreadedHttpConnectionManager.java	26 Oct 2003 09:49:16 -0000	1.27
  @@ -111,12 +111,6 @@
        */
       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;
  -
       /** Connection Pool */
       private ConnectionPool connectionPool;
   
  @@ -177,9 +171,14 @@
        *
        * @param maxHostConnections the number of connections allowed for each
        * hostConfiguration
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#MAX_HOST_CONNECTIONS},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public void setMaxConnectionsPerHost(int maxHostConnections) {
  -        this.maxHostConnections = maxHostConnections;
  +        this.params.setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
  +            maxHostConnections);
       }
   
       /**
  @@ -188,27 +187,42 @@
        *
        * @return The maximum number of connections allowed for a given
        * hostConfiguration.
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#MAX_HOST_CONNECTIONS},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public int getMaxConnectionsPerHost() {
  -        return maxHostConnections;
  +        return this.params.getIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
  +            DEFAULT_MAX_HOST_CONNECTIONS);
       }
   
       /**
        * Sets the maximum number of connections allowed in the system.
        *
        * @param maxTotalConnections the maximum number of connections allowed
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#MAX_TOTAL_CONNECTIONS},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public void setMaxTotalConnections(int maxTotalConnections) {
  -        this.maxTotalConnections = maxTotalConnections;
  +        this.params.setIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
  +            maxTotalConnections);
       }
   
       /**
        * Gets the maximum number of connections allowed in the system.
        *
        * @return The maximum number of connections allowed
  +     * 
  +     * @deprecated Use {@link HttpConnectionManagerParams#MAX_TOTAL_CONNECTIONS},
  +     * {@link HttpConnectionManager#getParams()}.
        */
       public int getMaxTotalConnections() {
  -        return maxTotalConnections;
  +        return this.params.getIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
  +            DEFAULT_MAX_TOTAL_CONNECTIONS);
       }
   
       /**
  @@ -291,6 +305,13 @@
   
           HttpConnection connection = null;
   
  +        int maxHostConnections = this.params.getIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
  +            DEFAULT_MAX_HOST_CONNECTIONS);
  +        int maxTotalConnections = this.params.getIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
  +            DEFAULT_MAX_TOTAL_CONNECTIONS);
  +        
           synchronized (connectionPool) {
   
               // we clone the hostConfiguration
  
  
  
  1.3       +4 -61     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpClientParams.java
  
  Index: HttpClientParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpClientParams.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpClientParams.java	23 Sep 2003 19:51:49 -0000	1.2
  +++ HttpClientParams.java	26 Oct 2003 09:49:16 -0000	1.3
  @@ -83,21 +83,6 @@
       private static final Log LOG = LogFactory.getLog(HttpParams.class);
   
       /**
  -     * Sets the socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the 
  -     * timeout for waiting for data. A timeout value of zero is interpreted as an 
  -     * infinite timeout.
  -     * This parameter expects a value of type {@link Integer}.
  -     */
  -    public static final String SO_TIMEOUT = "http.socket.timeout"; 
  -
  -    /**
  -     * Sets the timeout until a connection is etablished. A value of zero 
  -     * means the timeout is not used. The default value is zero.
  -     * This parameter expects a value of type {@link Integer}.
  -     */
  -    public static final String CONNECTION_TIMEOUT = "http.connection.timeout"; 
  -
  -    /**
        * Sets the timeout in milliseconds used when retrieving an 
        * {@link org.apache.commons.httpclient.HttpConnection HTTP connection} from the
        * {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}.
  @@ -150,48 +135,6 @@
        */
       public HttpClientParams(HttpParams defaults) {
           super(defaults);
  -    }
  -
  -    /**
  -     * Returns the socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the 
  -     * timeout for waiting for data. A timeout value of zero is interpreted as an 
  -     * infinite timeout.
  -     *
  -     * @return timeout in milliseconds
  -     */
  -    public int getSoTimeout() {
  -        return getIntParameter(SO_TIMEOUT, 0);
  -    }
  -
  -    /**
  -     * Sets the socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the 
  -     * timeout for waiting for data. A timeout value of zero is interpreted as an 
  -     * infinite timeout.
  -     *
  -     * @param timeout Timeout in milliseconds
  -     */
  -    public void setSoTimeout(int timeout) {
  -        setIntParameter(SO_TIMEOUT, timeout);
  -    }
  -
  -    /**
  -     * Returns the timeout until a connection is etablished. A value of zero 
  -     * means the timeout is not used. The default value is zero.
  -     * 
  -     * @return timeout in milliseconds.
  -     */
  -    public int getConnectionTimeout() {
  -        return getIntParameter(CONNECTION_TIMEOUT, 0);
  -    }
  -
  -    /**
  -     * Sets the timeout until a connection is etablished. A value of zero 
  -     * means the timeout is not used. The default value is zero.
  -     * 
  -     * @param timeout Timeout in milliseconds.
  -     */
  -    public void setConnectionTimeout(int timeout) {
  -        setIntParameter(CONNECTION_TIMEOUT, timeout);
       }
   
       /**
  
  
  
  1.2       +21 -4     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java
  
  Index: HttpConnectionManagerParams.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpConnectionManagerParams.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpConnectionManagerParams.java	22 Oct 2003 19:35:33 -0000	1.1
  +++ HttpConnectionManagerParams.java	26 Oct 2003 09:49:16 -0000	1.2
  @@ -75,4 +75,21 @@
    * @version $Revision$
    */
   public class HttpConnectionManagerParams extends HttpConnectionParams {
  +
  +    /** 
  +     * Defines the maximum number of connections allowed per host 
  +     * <p>
  +     * This parameter expects a value of type {@link Integer}.
  +     * </p>
  +     */
  +    public static String MAX_HOST_CONNECTIONS = "http.connection-manager.max-per-host";
  +
  +    /** 
  +     * Defines the maximum number of connections allowed overall 
  +     * <p>
  +     * This parameter expects a value of type {@link Integer}.
  +     * </p>
  +     */
  +    public static String MAX_TOTAL_CONNECTIONS = "http.connection-manager.max-total";
  +
   }
  
  
  
  1.13      +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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestHttpConnection.java	22 Oct 2003 19:31:00 -0000	1.12
  +++ TestHttpConnection.java	26 Oct 2003 09:49:16 -0000	1.13
  @@ -129,7 +129,7 @@
           connectionManager.setConnection(new HttpConnection(getHost(), getPort(), testProtocol));
           HttpClient client = createHttpClient(connectionManager);
           client.getHostConfiguration().setHost(getHost(), getPort(), testProtocol);
  -        client.getParams().setConnectionTimeout(1);
  +        client.getHttpConnectionManager().getParams().setConnectionTimeout(1);
           
           try {
               GetMethod get = new GetMethod();
  
  
  
  1.12      +29 -27    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java
  
  Index: TestHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestHttpConnectionManager.java	3 Oct 2003 20:57:36 -0000	1.11
  +++ TestHttpConnectionManager.java	26 Oct 2003 09:49:16 -0000	1.12
  @@ -71,6 +71,7 @@
   import junit.framework.TestSuite;
   
   import org.apache.commons.httpclient.methods.GetMethod;
  +import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
   import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
   
  @@ -102,17 +103,6 @@
   
       // ----------------------------------------------------------- Test Methods
   
  -    // Test the accessor methods
  -    public void testMaxConnectionsAccessors() {
  -        MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
  -
  -        // First test the default value
  -        assertEquals("Default MaxConnections", 2, mgr.getMaxConnectionsPerHost());
  -
  -        mgr.setMaxConnectionsPerHost(10);
  -        assertEquals("MaxConnections", 10, mgr.getMaxConnectionsPerHost());
  -    }
  -
       /**
        * Test that the ConnectMethod correctly releases connections when
        * CONNECT fails.
  @@ -120,7 +110,8 @@
       public void testConnectMethodFailureRelease() {
           
           MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
  -        mgr.setMaxTotalConnections(1);
  +        mgr.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 1);
           HttpClient client = createHttpClient(mgr);
           
           // we're going to execute a connect method against the localhost, assuming
  @@ -226,7 +217,8 @@
       public void testReleaseConnection() {
   
           MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 1);
   
           HttpClient client = createHttpClient(connectionManager);
           // we shouldn't have to wait if a connection is available
  @@ -275,7 +267,8 @@
       public void testResponseAutoRelease() {
   
           MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 1);
   
           HttpClient client = createHttpClient(connectionManager);
           // we shouldn't have to wait if a connection is available
  @@ -312,8 +305,10 @@
       public void testConnectionReclaiming() {
           
           MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  -        connectionManager.setMaxTotalConnections(1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 1);
   
           HostConfiguration host1 = new HostConfiguration();
           host1.setHost("host1", -1, "http");
  @@ -342,8 +337,10 @@
       public void testMaxConnections() {
           
           MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  -        connectionManager.setMaxTotalConnections(2);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 2);
   
           HostConfiguration host1 = new HostConfiguration();
           host1.setHost("host1", -1, "http");
  @@ -378,8 +375,10 @@
       public void testHostReusePreference() {
           
           final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  -        connectionManager.setMaxTotalConnections(1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 1);
   
           final HostConfiguration host1 = new HostConfiguration();
           host1.setHost("host1", -1, "http");
  @@ -426,7 +425,8 @@
       public void testMaxConnectionsPerServer() {
        
           MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 1);
   
           HttpClient client = createHttpClient(connectionManager);
           // we shouldn't have to wait if a connection is available
  @@ -458,7 +458,8 @@
       public void testReclaimUnusedConnection() {
   
           MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
  -        connectionManager.setMaxConnectionsPerHost(1);
  +        connectionManager.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 1);
   
           HttpClient client = createHttpClient(connectionManager);
           // we shouldn't have to wait if a connection is available
  @@ -520,7 +521,8 @@
   
       public void testTimeout() {
           MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
  -        mgr.setMaxConnectionsPerHost(2);
  +        mgr.getParams().setIntParameter(
  +            HttpConnectionManagerParams.MAX_HOST_CONNECTIONS, 2);
           
           try{
               HostConfiguration hostConfig = new HostConfiguration();
  
  
  

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