marcsaeg    02/03/15 15:28:59

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMultiClient.java
  Log:
  Improved javadoc comments.
  Improved parameter checking in executeMethod method.
  Improved exception handling in the "executeMethod" method.
  Minor code re-formatting.
  
  Submitted by:  Sean C. Sullivan
  
  Revision  Changes    Path
  1.2       +58 -11    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java
  
  Index: HttpMultiClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpMultiClient.java      22 Feb 2002 19:24:23 -0000      1.1
  +++ HttpMultiClient.java      15 Mar 2002 23:28:59 -0000      1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v
 1.1 2002/02/22 19:24:23 marcsaeg Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/22 19:24:23 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v
 1.2 2002/03/15 23:28:59 marcsaeg Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/03/15 23:28:59 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -67,10 +67,15 @@
   import org.apache.commons.httpclient.log.*;
   
   /**
  + *
    * An Http user-agent that supports multiple connections
    * to Http servers.
    *
    * @author Marc A. Saegesser
  + * @author Sean C. Sullivan
  + *
  + * @see HttpClient
  + *
    */
   public class HttpMultiClient
   {
  @@ -87,6 +92,9 @@
   
       /**
        * No-args constructor.
  +     *
  +     * HttpMultiClient objects will have strictMode enabled by default.
  +     *
        */
       public HttpMultiClient()
       {
  @@ -96,6 +104,9 @@
        * Set the shared state.
        *
        * @param state - the new shared state
  +     *
  +     * @see #getState()
  +     *
        */
       public void setState(HttpSharedState state)
       {
  @@ -106,10 +117,14 @@
        * Get the shared state
        *
        * @return the shared state
  +     *
  +     * @see #setState(HttpSharedState)
  +     *
        */
       public HttpSharedState getState()
       {
  -        if(state == null){
  +        if (state == null)
  +        {
               state = new HttpSharedState();
           }
   
  @@ -118,6 +133,10 @@
   
       /**
        *
  +     * @param strictMode <code>true</code> if strict mode should be used
  +     *
  +     * @see #isStrictMode()
  +     *
        */
       public void setStrictMode(boolean strictMode)
       {
  @@ -126,6 +145,10 @@
   
       /**
        *
  +     * @return <code>true</code> if strict mode being used
  +     *
  +     * @see #setStrictMode(boolean)
  +     *
        */
       public boolean isStrictMode()
       {
  @@ -133,31 +156,55 @@
       }
   
       /**
  -     * Execute the given {@link HttpMethod} using my current
  +     *
  +     * Execute the given {@link HttpUrlMethod} using my current
        * {@link HttpConnection connection} and {@link HttpState}.
        *
  -     * @param method the {@link HttpMethod} to execute
  +     * @param method the {@link HttpMethod} to execute. Must be non-null.
        * @return the method's response code
        *
        * @throws IOException if an I/O error occurs
        * @throws HttpException if a protocol exception occurs
  +     *
        */
       public int executeMethod(HttpUrlMethod method) throws IOException, HttpException
       {
  +
  +        if (null == method)
  +        {
  +            throw new NullPointerException("method parameter");
  +        }
  +
           HttpConnection connection = mgr.getConnection(method.getUrl());
           
           int status = 0;
   
           method.setStrictMode(strictMode);
   
  -        status = method.execute(getState(),connection);
  -        mgr.releaseConnection(connection);
  +        try
  +        {
  +            status = method.execute(getState(),connection);
  +        }
  +        catch (java.io.IOException ex)
  +        {
  +            throw ex;
  +        }
  +        catch (HttpException ex)
  +        {
  +            throw ex;
  +        }
  +        finally
  +        {
  +            mgr.releaseConnection(connection);
  +        }
   
  -        if(status == 301 || status == 302 || 
  -           status == 303 || status == 307){
  +        if (status == 301 || status == 302 || 
  +            status == 303 || status == 307)
  +        {
               Header header = method.getResponseHeader("Location");
               String url = header.getValue();
  -            if(url == null){
  +            if (url == null)
  +            {
                   log.error("HttpMultiClient.executeMethod:  Received redirect 
without Location header.");
                   throw new HttpException("Received redirect without Location 
header.");
               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to