commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java
Date Fri, 02 Aug 2002 06:37:26 GMT
dion        2002/08/01 23:37:26

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
  Log:
  Refactored execute method out
  
  Revision  Changes    Path
  1.41      +284 -201  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.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- HttpMethodBase.java	30 Jul 2002 03:01:47 -0000	1.40
  +++ HttpMethodBase.java	2 Aug 2002 06:37:26 -0000	1.41
  @@ -167,7 +167,8 @@
        * in the same way that most Http user agent's do (and many HTTP servers
        * expect.
        *
  -     * NOTE:  StrictMode is currently experimental and its functionlaity may change in
the future.
  +     * NOTE:  StrictMode is currently experimental and its functionlaity may
  +     *        change in the future.
        *
        */
       public void setStrictMode(boolean strictMode) {
  @@ -177,7 +178,8 @@
       /**
        * Returns the value of strictMode.
        *
  -     * NOTE:  StrictMode is currently experimental and its functionlaity may change in
the future.
  +     * NOTE:  StrictMode is currently experimental and its functionlaity may 
  +     *        change in the future.
        *
        * @return true if strict mode is enabled.
        */
  @@ -194,7 +196,7 @@
        */
       public void setRequestHeader(String headerName, String headerValue) {
           Header header = new Header(headerName, headerValue);
  -        requestHeaders.put(headerName.toLowerCase(),header);
  +        setRequestHeader(header);
       }
   
       /**
  @@ -222,16 +224,34 @@
           //   - HTTP/1.0 (4.3)
           Header header = (Header)(requestHeaders.get(headerName.toLowerCase()));
           if (null == header) {
  +            // header doesn't exist already, simply create with name and value
               header = new Header(headerName, headerValue);
           } else {
  -            header.setValue( (null == header.getValue() ? "" : header.getValue()) +
  -                             ", " +
  -                             (null == headerValue ? "" : headerValue));
  +            // header exists, add this value to the comma separated list
  +            header.setValue(getNewHeaderValue(header, headerValue));
           }
  -        requestHeaders.put(headerName.toLowerCase(),header);
  +        setRequestHeader(header);
       }
   
       /**
  +     * "It must be possible to combine the multiple header fields into
  +     * one "field-name: field-value" pair, without changing the
  +     * semantics of the message, by appending each subsequent field-value
  +     * to the first, each separated by a comma."
  +     */
  +    private String getNewHeaderValue(Header existingHeader, String value) {
  +        String existingValue = existingHeader.getValue();
  +        if (existingValue == null) {
  +            existingValue = "";
  +        }
  +        String newValue = value;
  +        if (value == null) {
  +            newValue = "";
  +        }
  +        return existingValue + ", " + newValue;
  +    }
  +    
  +    /**
        * Add the specified request header.
        *
        * If a header of the same name already exists, the new value will be
  @@ -242,26 +262,13 @@
        * @param header the header to add to the request
        */
       public void addRequestHeader(Header header) {
  -        // "It must be possible to combine the multiple header fields into
  -        // one "field-name: field-value" pair, without changing the
  -        // semantics of the message, by appending each subsequent field-value
  -        // to the first, each separated by a comma."
  -        //   - HTTP/1.0 (4.3)
           log.trace("HttpMethodBase.addRequestHeader(Header)");
   
  -        if (header == null){
  -	   log.debug("null header value ignored");
  -	}
  -
  -	// Preserve the original header if it exists
  -        Header orig = (Header)(requestHeaders.get(header.getName().toLowerCase()));
  -        if (null == orig) {
  -            orig = header;
  +        if (header == null) {
  +          log.debug("null header value ignored");
           } else {
  -            orig.setValue((null == orig.getValue() ? "" : orig.getValue())
  -                + ", " + (null == header.getValue() ? "" : header.getValue()));
  +            addRequestHeader(header.getName(), header.getValue());
           }
  -        requestHeaders.put(orig.getName().toLowerCase(), orig);
       }
   
       /**
  @@ -315,21 +322,20 @@
        */
       public void setQueryString(NameValuePair[] params) {
           log.trace("enter HttpMethodBase.setQueryString(NameValuePair[])");
  -
           StringBuffer buf = new StringBuffer();
           boolean needAmp = false;
  -        for(int i=0;i<params.length;i++) {
  -            if (needAmp) {
  -                buf.append("&");
  -            } else {
  -                needAmp = true;
  -            }
  -            if (null != params[i].getName()) {
  -                buf.append(URIUtil.encode(params[i].getName()));
  -            }
  -            if (null != params[i].getValue()) {
  -                buf.append("=");
  -                buf.append(URIUtil.encode(params[i].getValue()));
  +        for(int i = 0;i < params.length; i++) {
  +            if (params[i].getName() != null) {
  +                if (needAmp) {
  +                    buf.append("&");
  +                } else {
  +                    needAmp = true;
  +                }
  +                buf.append(URIUtil.encode(params[i].getName()))
  +                    .append("=");
  +                if (params[i].getValue() != null) {
  +                    buf.append(URIUtil.encode(params[i].getValue()));
  +                }
               }
           }
           queryString = buf.toString();
  @@ -346,7 +352,8 @@
        * Return an array of my request headers.
        */
       public Header[] getRequestHeaders() {
  -        return (Header[])(requestHeaders.values().toArray(new Header[requestHeaders.size()]));
  +        return (Header[])(requestHeaders.values().toArray(
  +            new Header[requestHeaders.size()]));
       }
   
       // ---------------------------------------------------------------- Queries
  @@ -369,7 +376,8 @@
       }
   
       /**
  -     * Return the status text (or "reason phrase") associated with the latest response.
  +     * Return the status text (or "reason phrase") associated with the latest
  +     * response.
        */
       public String getStatusText() {
           return statusText;
  @@ -379,7 +387,8 @@
        * Return an array my response headers.
        */
       public Header[] getResponseHeaders() {
  -        return (Header[])(responseHeaders.values().toArray(new Header[responseHeaders.size()]));
  +        return (Header[])(responseHeaders.values().toArray(
  +            new Header[responseHeaders.size()]));
       }
   
       /**
  @@ -413,7 +422,8 @@
        * Otherwise return <tt>null</tt>.
        */
       public InputStream getResponseBodyAsStream() throws IOException {
  -        return null == responseBody ? null : new ByteArrayInputStream(responseBody);
  +        return null == responseBody ? null : 
  +            new ByteArrayInputStream(responseBody);
       }
   
       /**
  @@ -424,26 +434,198 @@
          return used;
       }
   
  +    /**
  +     * Write a request and read the response. Retry, if needed, up to 
  +     * {@link #maxRetries} times.
  +     *
  +     * @param state the current state
  +     * @param connection the connection for communication
  +     * @throws HttpException when errors occur as part of the HTTP protocol
  +     *      conversation
  +     * @throws IOException when an I/O error occurs communicating with the 
  +     *      server
  +     */
  +    private void processRequest(HttpState state, HttpConnection connection)
  +    throws HttpException, IOException {
  +        for (int retryCount = 1; retryCount <= maxRetries; retryCount++) {
  +            try {
  +                if (!connection.isOpen()) {
  +                    log.debug("HttpMethodBase.execute(): opening connection.");
  +                    connection.open();
  +                }
  +                writeRequest(state, connection);
  +                used = true;
  +                readResponse(state,connection);
  +                return;
  +            } catch (HttpRecoverableException e) {
  +                connection.close();
  +                log.debug("HttpMethodBase.processRequest():  retrying...");
  +                if (retryCount == maxRetries) {
  +                    throw e;
  +                }
  +            }
  +        }
  +        // should never happen
  +        throw new HttpException("HttpMethodBase.processRequest(): retry count"
  +            + " exceeded");
  +    }
  +    
  +    /**
  +     * On a {@link HttpStatus#SC_CONTINUE continue}, if there are more request
  +     * bytes to be sent, write them to the connection
  +     *
  +     * @param state the current state
  +     * @param connection the connection for communication
  +     * @throws HttpException when errors occur as part of the HTTP protocol
  +     *      conversation
  +     * @throws IOException when an I/O error occurs communicating with the 
  +     *      server
  +     */
  +    private void writeRemainingRequestBody(HttpState state, 
  +    HttpConnection connection) throws HttpException, IOException {
  +        if (HttpStatus.SC_CONTINUE == statusCode) {
  +            if (!bodySent) {
  +                bodySent = writeRequestBody(state, connection);
  +            } else {
  +                log.warn("HttpMethodBase.execute(): received 100 response, "
  +                    + "but I've already sent the response. Ignoring.");
  +                // According to RFC 2616 this respose should be ignored
  +            }
  +            readResponse(state,connection);
  +        }
  +    }
  +
  +    /**
  +     * Close the provided HTTP connection, if:
  +     *  http 1.0 and not using the 'connect' method, or
  +     *  http 1.1 and the Connection: close header is sent
  +     *
  +     * @param connection the HTTP connection to process
  +     */
  +    private void closeConnection(HttpConnection connection) {
  +        if (!http11) {
  +            if (getName().equals(ConnectMethod.NAME) 
  +                && (statusCode == HttpStatus.SC_OK)) {
  +                log.debug("HttpMethodBase.execute(): leaving connection "
  +                    + "open for tunneling");
  +            } else {
  +                log.debug("HttpMethodBase.execute(): closing connection "
  +                    + "since we're using HTTP/1.0");
  +                connection.close();
  +            }
  +        } else {
  +            Header connectionHeader = getResponseHeader("connection");
  +            if (null != connectionHeader
  +                && "close".equalsIgnoreCase(connectionHeader.getValue())) {
  +                log.debug("HttpMethodBase.execute(): closing connection "
  +                    + "since \"Connection: close\" header found.");
  +                connection.close();
  +            }
  +        }
  +
  +    }
  +    
  +    /**
  +     * process a response that requires authentication
  +     *
  +     * @param state the current state
  +     * @param connection the connection for communication
  +     * @return true if the request has completed process, false if more attempts
  +     *      are needed
  +     */
  +    private boolean processAuthenticationResponse(HttpState state, 
  +    HttpConnection connection) {
  +
  +        Set realms = new HashSet();
  +        Set proxyRealms = new HashSet();
  +
  +        // handle authentication required
  +        Header wwwauth = null;
  +        Set realmsUsed = null;
  +        switch (statusCode) {
  +            case HttpStatus.SC_UNAUTHORIZED:
  +                wwwauth = getResponseHeader(Authenticator.WWW_AUTH);
  +                realmsUsed = realms;
  +                break;
   
  +            case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
  +                wwwauth = getResponseHeader(Authenticator.PROXY_AUTH);
  +                realmsUsed = proxyRealms;
  +                break;
  +        }
  +        boolean authenticated = false;
  +        // if there was a header requesting authentication
  +        if (null != wwwauth) {
  +            String pathAndCreds = getPath() + ":" + wwwauth.getValue();
  +            if (realmsUsed.contains(pathAndCreds)) {
  +                if (log.isInfoEnabled()) {
  +                    log.info("Already tried to authenticate to \"" 
  +                        + wwwauth.getValue() + "\" but still receiving "
  +                        + statusCode + ".");
  +                }
  +                return true;
  +            } else {
  +                realmsUsed.add(pathAndCreds);
  +            }
  +
  +            try {
  +                //remove preemptive header and reauthenticate
  +                switch (statusCode) {
  +                    case HttpStatus.SC_UNAUTHORIZED:
  +                        removeRequestHeader(Authenticator.WWW_AUTH_RESP);
  +                        authenticated = Authenticator.authenticate(this, state);
  +                        break;
  +                    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
  +                        removeRequestHeader(Authenticator.PROXY_AUTH_RESP); 
  +                        authenticated = Authenticator.authenticateProxy(this,state);
  +                        break;
  +                }
  +            } catch (HttpException httpe) {
  +                log.warn("Exception thrown authenticating", httpe);
  +                return true; // finished request
  +            } catch (UnsupportedOperationException uoe) {
  +                log.warn("Exception thrown authenticating", uoe);
  +                return true; // finished request
  +            }
  +
  +            if (!authenticated) {
  +                // won't be able to authenticate to this challenge
  +                // without additional information
  +                log.debug("HttpMethodBase.execute(): Server demands "
  +                    + "authentication credentials, but none are "
  +                    + "available, so aborting.");
  +            } else {
  +                log.debug("HttpMethodBase.execute(): Server demanded "
  +                    + "authentication credentials, will try again.");
  +                // let's try it again, using the credentials
  +            }
  +        }
  +        
  +        return !authenticated; // finished processing if we aren't authenticated
  +    }
  +    
       // --------------------------------------------------------- Action Methods
   
   
       /**
        * Execute this method.
        *
  -     * @param state {@link HttpState} information to associate with this request. Must
be non-null.
  -     * @param connection the {@link HttpConnection} to write to/read from. Must be non-null.
  +     * @param state {@link HttpState} information to associate with this 
  +     *      request. Must be non-null.
  +     * @param connection the {@link HttpConnection} to write to/read from.
  +     *      Must be non-null.
        *
        * @throws IOException if an I/O error occurs
        * @throws HttpException  if an protocol exception occurs
        *
        * @return the integer status code if one was obtained, or <tt>-1</tt>
        */
  -    public int execute(HttpState state, HttpConnection connection)
  +    public int execute(HttpState state, HttpConnection connection) 
       throws HttpException, IOException {
           // FIXME: This method is too large
           log.trace("enter HttpMethodBase.execute(HttpState, HttpConnection)");
   
  +
           if (null == state) {
               throw new NullPointerException("HttpState parameter");
           }
  @@ -462,138 +644,39 @@
   
           //pre-emptively add the authorization header, if required.
           Authenticator.authenticate(this, state);
  -        if (connection.isProxied()) Authenticator.authenticateProxy(this, state);
  +        if (connection.isProxied()) {
  +            Authenticator.authenticateProxy(this, state);
  +        }
   
           Set visited = new HashSet();
  -        Set realms = new HashSet();
  -        Set proxyRealms = new HashSet();
  -        int retryCount = 0;
  +        retryCount = 0;
           for(;;) {
  -            visited.add(connection.getHost() + ":" + connection.getPort() + "|" + HttpMethodBase.generateRequestLine(connection,
getName(),getPath(),getQueryString(),(http11 ? "HTTP/1.1" : "HTTP/1.0")));
  -
  -            if (log.isDebugEnabled()) {
  -                log.debug("HttpMethodBase.execute(): looping.");
  -            }
  -
  -
  -            try{
  -                if (!connection.isOpen()) {
  -                    if (log.isDebugEnabled()) {
  -                        log.debug("HttpMethodBase.execute(): opening connection.");
  -                    }
  -                    connection.open();
  -                }
  -
  -                writeRequest(state,connection);
  -                used = true;
  -
  -                // need to close output?, but when?
  -                readResponse(state,connection);
  -            }catch(HttpRecoverableException e){
  -                if(retryCount >= maxRetries){
  -                    throw new HttpException(e.toString());
  -                }
  -                retryCount++;
  -                connection.close();
  -                log.debug("HttpMethodBase.execute():  Caught recoverable exception, retrying...");
  -                continue;
  -            }
  -            if (HttpStatus.SC_CONTINUE == statusCode) {
  -                if (!bodySent) {
  -                    bodySent = writeRequestBody(state,connection);
  -                } else {
  -                    log.warn("HttpMethodBase.execute(): received 100 response, but I've
already sent the response.");
  -                    // According to RFC 2616 this respose should be ignored
  -                }
  -                readResponse(state,connection);
  -            }
  -
  -            if (!http11) {
  -                if (getName().equals(ConnectMethod.NAME) && (statusCode == HttpStatus.SC_OK))
{
  -                    log.debug("HttpMethodBase.execute(): leaving connection open for tunneling");
  -                } else {
  -                if (log.isDebugEnabled()) {
  -                	log.debug("HttpMethodBase.execute(): closing connection since we're using
HTTP/1.0");
  -                }
  -                connection.close();
  -                }
  -            } else {
  -                Header connectionHeader = getResponseHeader("connection");
  -                if (null != connectionHeader && "close".equalsIgnoreCase(connectionHeader.getValue()))
{
  -                    if (log.isDebugEnabled()) {
  -                    		log.debug("HttpMethodBase.execute(): closing connection since \"Connection:
close\" header found.");
  -                    }
  -                    connection.close();
  -                }
  -            }
  +            visited.add(connection.getHost() + ":" + connection.getPort() + "|"
  +                + HttpMethodBase.generateRequestLine(
  +                connection, getName(), getPath(), getQueryString(), 
  +                (http11 ? "HTTP/1.1" : "HTTP/1.0")));
  +
  +            log.debug("HttpMethodBase.execute(): looping.");
  +
  +            processRequest(state, connection);
  +            writeRemainingRequestBody(state, connection);
  +            closeConnection(connection); // if needed
   
  +            // process authentication response
               if ((HttpStatus.SC_UNAUTHORIZED == statusCode)
                   || (HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED == statusCode)) {
  -
  -                Header wwwauth = null;
  -                Set realmsUsed = null;
  -                switch (statusCode) {
  -                    case HttpStatus.SC_UNAUTHORIZED:
  -                        wwwauth = getResponseHeader(Authenticator.WWW_AUTH);
  -                        realmsUsed = realms;
  -                        break;
  -
  -                    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
  -                        wwwauth = getResponseHeader(Authenticator.PROXY_AUTH);
  -                        realmsUsed = proxyRealms;
  -                        break;
  -                }
  -                if (null != wwwauth) {
  -                    String pathAndCreds = getPath() + ":" + wwwauth.getValue();
  -                    if (realmsUsed.contains(pathAndCreds)) {
  -                        if (log.isInfoEnabled()) {
  -                            log.info("Already tried to authenticate to \"" + wwwauth.getValue()
+ "\" but still receiving " + statusCode + ".");
  -                        }
  -                        break;
  -                    } else {
  -                        realmsUsed.add(pathAndCreds);
  -                    }
  -
  -                    boolean authenticated = false;
  -                    try {
  -                        switch (statusCode) {
  -                            case HttpStatus.SC_UNAUTHORIZED:
  -                                removeRequestHeader(Authenticator.WWW_AUTH_RESP); //remove
preemptively header
  -                        authenticated = Authenticator.authenticate(this, state);
  -                                break;
  -
  -                            case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
  -                                removeRequestHeader(Authenticator.PROXY_AUTH_RESP); //remove
preemptively header
  -                                authenticated = Authenticator.authenticateProxy(this,state);
  -                                break;
  -                        }
  -                    } catch (HttpException httpe) {
  -                        log.warn(httpe.getMessage());
  -                    } catch (UnsupportedOperationException uoe) {
  -                        log.warn(uoe.getMessage());
  -                    }
  -
  -                    if (!authenticated) {
  -                        // won't be able to authenticate to this challenge
  -                        // without additional information
  -                        if (log.isDebugEnabled()) {
  -                            log.debug("HttpMethodBase.execute(): Server demands authentication
credentials, but none are available, so aborting.");
  -                        }
  -                        break;
  -                    } else {
  -                        if (log.isDebugEnabled()) {
  -                            log.debug("HttpMethodBase.execute(): Server demanded authentication
credentials, will try again.");
  -                        }
  -                        // let's try it again, using the credentials
  -                        continue;
  -                    }
  +                if (processAuthenticationResponse(state, connection)) {
  +                    break;
  +                } else {
  +                    continue;
                   }
               } else if (HttpStatus.SC_MOVED_TEMPORARILY == statusCode ||
  -               HttpStatus.SC_MOVED_PERMANENTLY == statusCode ||
  -               HttpStatus.SC_TEMPORARY_REDIRECT == statusCode) {
  +                HttpStatus.SC_MOVED_PERMANENTLY == statusCode ||
  +                HttpStatus.SC_TEMPORARY_REDIRECT == statusCode) {
  +                // process redirect
                   if (getFollowRedirects()) {
                       //
  -                    // Note that we cannot current support
  +                    // Note that we cannot currently support
                       // redirects that change the HttpConnection
                       // parameters (host, port, protocol)
                       // because we don't yet have a good way to
  @@ -746,10 +829,9 @@
        * @param state the client state
        * @param conn the {@link HttpConnection} to write the request to
        */
  -    protected void writeRequest(HttpState state, HttpConnection conn) 
  +    protected void writeRequest(HttpState state, HttpConnection conn)
       throws IOException, HttpException {
           log.trace("enter HttpMethodBase.writeRequest(HttpState, HttpConnection)");
  -	
           writeRequestLine(state,conn);
           writeRequestHeaders(state,conn);
           conn.writeLine(); // close head
  @@ -771,9 +853,8 @@
       protected void writeRequestLine(HttpState state, HttpConnection conn)
       throws IOException, HttpException {
           log.trace("enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection)");
  -
  -        String requestLine = HttpMethodBase.generateRequestLine(conn, getName(), getPath(),
  -	      getQueryString(),(http11 ? "HTTP/1.1" : "HTTP/1.0"));
  +        String requestLine = HttpMethodBase.generateRequestLine(conn, getName(),
  +            getPath(),getQueryString(),(http11 ? "HTTP/1.1" : "HTTP/1.0"));
           conn.print(requestLine);
       }
   
  @@ -795,8 +876,7 @@
        */
       protected void writeRequestHeaders(HttpState state, HttpConnection conn)
       throws IOException, HttpException {
  -        log.trace("enter HttpMethodBase.writeRequestHeaders(HttpState, HttpConnection)");
  -
  +        log.trace("enter HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)");
           addRequestHeaders(state,conn);
           Iterator it = requestHeaders.values().iterator();
           while(it.hasNext()) {
  @@ -841,8 +921,8 @@
        * as long as no <tt>User-Agent</tt> request header
        * already exists.
        */
  -    protected void addUserAgentRequestHeader(HttpState state, HttpConnection conn)
  -    throws IOException, HttpException {
  +    protected void addUserAgentRequestHeader(HttpState state, 
  +    HttpConnection conn) throws IOException, HttpException {
           log.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)");
   
           if (!requestHeaders.containsKey("user-agent")) {
  @@ -855,10 +935,9 @@
        * as long as no <tt>Host</tt> request header
        * already exists.
        */
  -    protected void addHostRequestHeader(HttpState state, HttpConnection conn)
  +    protected void addHostRequestHeader(HttpState state, HttpConnection conn) 
       throws IOException, HttpException {
           log.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)");
  -
           // Per 19.6.1.1 of RFC 2616, it is legal for HTTP/1.0 based 
           // applications to send the Host request-header.
           // TODO: Add the ability to disable the sending of this header for HTTP/1.0 requests.
  @@ -886,9 +965,10 @@
       throws IOException, HttpException {
           log.trace("enter HttpMethodBase.addCookieRequestHeaders(HttpState, HttpConnection)");
   
  -        Header cookieHeader = Cookie.createCookieHeader(conn.getHost(), conn.getPort(),

  -	      getPath(), conn.isSecure(), new Date(), state.getCookies());
  -        if(null != cookieHeader) {
  +        Header cookieHeader = Cookie.createCookieHeader(conn.getHost(), 
  +            conn.getPort(), getPath(), conn.isSecure(), new Date(), 
  +            state.getCookies());
  +        if (null != cookieHeader) {
               setRequestHeader(cookieHeader);
           }
       }
  @@ -898,8 +978,8 @@
        * as long as no <tt>Authorization</tt> request header
        * already exists.
        */
  -    protected void addAuthorizationRequestHeader(HttpState state, HttpConnection conn)
  -    throws IOException, HttpException {
  +    protected void addAuthorizationRequestHeader(HttpState state, 
  +    HttpConnection conn) throws IOException, HttpException {
           log.trace("enter HttpMethodBase.addAuthorizationRequestHeader(HttpState, HttpConnection)");
   
           // add authorization header, if needed
  @@ -920,8 +1000,8 @@
        * as long as no <tt>Proxy-Authorization</tt> request header
        * already exists.
        */
  -    protected void addProxyAuthorizationRequestHeader(HttpState state, HttpConnection conn)
  -    throws IOException, HttpException {
  +    protected void addProxyAuthorizationRequestHeader(HttpState state, 
  +    HttpConnection conn) throws IOException, HttpException {
           log.trace("enter HttpMethodBase.addProxyAuthorizationRequestHeader(HttpState, HttpConnection)");
   
           // add proxy authorization header, if needed
  @@ -943,8 +1023,8 @@
        * as long as no <tt>Content-Length</tt> request header
        * already exists.
        */
  -    protected void addContentLengthRequestHeader(HttpState state, HttpConnection conn)
  -    throws IOException, HttpException {
  +    protected void addContentLengthRequestHeader(HttpState state, 
  +    HttpConnection conn) throws IOException, HttpException {
           log.trace("enter HttpMethodBase.addProxyAuthorizationRequestHeader(HttpState, HttpConnection)");
   
           // add content length or chunking
  @@ -1035,8 +1115,7 @@
        */
       protected void readResponse(HttpState state, HttpConnection conn)
       throws IOException, HttpException {
  -        log.debug("enter HttpMethodBase.readResponse(HttpState, HttpConnection)");
  -
  +        log.trace("enter HttpMethodBase.readResponse(HttpState, HttpConnection)");
           readStatusLine(state,conn);
           processStatusLine(state,conn);
           readResponseHeaders(state,conn);
  @@ -1059,7 +1138,7 @@
        * @param state the client state
        * @param conn the {@link HttpConnection} to read the response from
        */
  -    protected void readStatusLine(HttpState state, HttpConnection conn)
  +    protected void readStatusLine(HttpState state, HttpConnection conn) 
       throws IOException, HttpException {
           log.trace("enter HttpMethodBase.readStatusLine(HttpState, HttpConnection)");
   
  @@ -1147,7 +1226,8 @@
           // to the first, each separated by a comma."
           //   - HTTP/1.0 (4.3)
   
  -        log.trace("enter HttpMethodBase.readResponseHeaders(HttpState, HttpConnection)");
  +        log.trace("enter HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)");
  +
           responseHeaders.clear();
   
           String name = null;
  @@ -1227,9 +1307,9 @@
        * @param state the client state
        * @param conn the {@link HttpConnection} to read the response from
        */
  -    protected void processResponseHeaders(HttpState state, HttpConnection conn) {
  +    protected void processResponseHeaders(HttpState state, HttpConnection conn) 
  +    {
           log.trace("enter HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)");
  -
           // add cookies, if any
           // should we set cookies?
           Header setCookieHeader = getResponseHeader("set-cookie2");
  @@ -1241,8 +1321,9 @@
               try {
                   Cookie[] cookies = Cookie.parse(conn.getHost(), conn.getPort(), getPath(),
conn.isSecure(), setCookieHeader);
                   state.addCookies(cookies);
  -            } catch (Exception ex) {
  -                log.error("Exception caught when processing cookies", ex);
  +            } catch (Exception e) {
  +                // FIXME: Shouldn't be catching exception!
  +                log.error("Exception processing response headers", e);
               }
           }
       }
  @@ -1294,8 +1375,8 @@
        * @param conn the {@link HttpConnection} to read the response from
        * @param out OutputStream to write the response body to
        */
  -    protected void readResponseBody(HttpState state, HttpConnection conn, OutputStream
out)
  -    throws IOException {
  +    protected void readResponseBody(HttpState state, HttpConnection conn, 
  +    OutputStream out) throws IOException {
           log.trace("enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)");
   
           responseBody = null;
  @@ -1436,7 +1517,8 @@
        * Generate an HTTP/S request line according to
        * the specified attributes.
        */
  -    protected static String generateRequestLine(HttpConnection connection, String name,
String reqPath, String qString, String protocol) {
  +    protected static String generateRequestLine(HttpConnection connection,
  +    String name, String reqPath, String qString, String protocol) {
           log.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, String, String,
String, String)");
   
           StringBuffer buf = new StringBuffer();
  @@ -1558,7 +1640,8 @@
       private int maxRetries = 3;
       /** True if we're in strict mode. */
       private boolean strictMode = true;
  -
  +    /** number of times a request has attempted recoverable execution */
  +    private int retryCount;
       // -------------------------------------------------------------- Constants
   
       /** Log object for this class. */
  
  
  

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


Mime
View raw message