hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <o.kalnichev...@dplanet.ch>
Subject Re: PATCH: Allow custom HttpState in HttpClient.executeMethod
Date Fri, 02 May 2003 18:51:31 GMT
Folks,
In my opinion the patch is good to be committed. If nobody complains
loudly I'll commit it sometime this weekend. I just would use
IllegalArgumentException instead of NullPointerException to be
consistent with the programming practices used throughout HttpClient,
but that has nothing to do with Laura's patch. It just caught my
attention.

Oleg

On Fri, 2003-05-02 at 03:25, Laura Werner wrote:
> Hi all,
> 
> I just finished an initial conversion of our project to use the latest 
> CVS Head of httpclient.  (Gotta love eclipse!)  It went pretty smoothly, 
> and the improvements in httpclient (and my understanding of it) made our 
> code a lot cleaner.  As I work through this, I'm going to suggest a few 
> patches for consideration. 
> 
> Patch #1 adds an override of HttpClient.executeMethod that lets the 
> caller specify an HttpState object.  This allows advanced clients that 
> need to mess around with the http state (e.g. different cookies for 
> different threads) to use HttpClient rather than manipulating 
> connections and connection managers directly.  As more functionality 
> gets moved from HttpMethodBase into HttpClient (e.g. redirects), I think 
> this is going to be extremely important.
> 
> Here's the patch.  I'm just pasting it here inline since it's so small....
> 
> Laura Werner
> BeVocal
> 
> Index: src/java/org/apache/commons/httpclient/HttpClient.java
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
> retrieving revision 1.73
> diff -u -r1.73 HttpClient.java
> --- src/java/org/apache/commons/httpclient/HttpClient.java    10 Apr 
> 2003 21:01:00 -0000    1.73
> +++ src/java/org/apache/commons/httpclient/HttpClient.java    2 May 2003 
> 01:23:35 -0000
> @@ -503,11 +503,34 @@
>         
>      }
>     
> +    /**
> +     * Executes the given method.
> +     *
> +     * @param hostConfiguration The configuration to use.
> +     * @param method the {@link HttpMethod} to execute.
> +     * @return the method's response code
> +     *
> +     * @throws IOException if an I/O error occurs
> +     * @throws HttpException if a protocol exception occurs
> +     * @since 2.0
> +     */
> +    public int executeMethod(HostConfiguration hostConfiguration,
> +        HttpMethod method)
> +        throws IOException, HttpException  {
> +           
> +            LOG.trace("enter 
> HttpClient.executeMethod(HostConfiguration,HttpMethod)");
> +           
> +            return executeMethod(hostConfiguration, method, null);       
> +    }
> +   
>      /**
>       * Executes the given method.
>       *
>       * @param hostConfiguration The configuration to use.
>       * @param method the {@link HttpMethod} to execute.
> +     * @param state the {@link HttpState} to use when executing the method.
> +     * If <code>null</code>, the state returned by {@link #getState} 
> will be used instead.
> +     *
>       * @return the method's response code
>       *
>       * @throws IOException if an I/O error occurs
> @@ -515,10 +538,10 @@
>       * @since 2.0
>       */
>      public int executeMethod(HostConfiguration hostConfiguration,
> -        HttpMethod method)
> +        HttpMethod method, HttpState state)
>          throws IOException, HttpException  {
>             
> -        LOG.trace("enter 
> HttpClient.executeMethod(HostConfiguration,HttpMethod)");
> +        LOG.trace("enter 
> HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)");
>  
>          if (null == method) {
>              throw new NullPointerException("HttpMethod parameter");
> @@ -528,7 +551,6 @@
>          boolean strictMode = false;
>          int connectionTimeout = 0;
>          long httpConnectionTimeout = 0;
> -        HttpState state = null;
>          HostConfiguration defaultHostConfiguration = null;
>  
>          /* access all synchronized data in a single block, this will 
> keeps us
> @@ -540,7 +562,9 @@
>              strictMode = this.strictMode;
>              connectionTimeout = this.connectionTimeout;
>              httpConnectionTimeout = this.httpConnectionTimeout;
> -            state = getState();
> +            if (state == null) {
> +                state = getState();
> +            }
>              defaultHostConfiguration = getHostConfiguration();
>          }
>  
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


Mime
View raw message