org.archive.httpclient
Class HttpRecorderGetMethod

java.lang.Object
  extended by org.apache.commons.httpclient.HttpMethodBase
      extended by org.apache.commons.httpclient.methods.GetMethod
          extended by org.archive.httpclient.HttpRecorderGetMethod
All Implemented Interfaces:
org.apache.commons.httpclient.HttpMethod

public class HttpRecorderGetMethod
extends org.apache.commons.httpclient.methods.GetMethod

Override of GetMethod that marks the passed HttpRecorder w/ the transition from HTTP head to body and that forces a close on the http connection. The actions done in this subclass used to be done by copying org.apache.commons.HttpMethodBase, overlaying our version in place of the one that came w/ httpclient. Here is the patch of the difference between shipped httpclient code and our mods:

    -- -1338,6 +1346,12 --

        public void releaseConnection() {

   +        // HERITRIX always ants the streams closed.
   +        if (responseConnection != null)
   +        {
   +            responseConnection.close();
   +        }
   +
            if (responseStream != null) {
                try {
                    // FYI - this may indirectly invoke responseBodyConsumed.
   -- -1959,6 +1973,11 --
                        this.statusLine = null;
                    }
                }
   +            // HERITRIX mark transition from header to content.
   +            if (this.httpRecorder != null)
   +            {
   +                this.httpRecorder.markContentBegin();
   +            }
                readResponseBody(state, conn);
                processResponseBody(state, conn);
            } catch (IOException e) {
 

We're not supposed to have access to the underlying connection object; am only violating contract because see cases where httpclient is skipping out w/o cleaning up after itself.

Version:
$Revision: 4646 $, $Date: 2006-09-22 17:23:04 +0000 (Fri, 22 Sep 2006) $
Author:
stack

Field Summary
protected  HttpRecorderMethod httpRecorderMethod
          Instance of http recorder method.
protected static java.util.logging.Logger logger
           
 
Constructor Summary
HttpRecorderGetMethod(java.lang.String uri, HttpRecorder recorder)
           
 
Method Summary
protected  void addProxyConnectionHeader(org.apache.commons.httpclient.HttpState state, org.apache.commons.httpclient.HttpConnection conn)
          Generates Proxy-Connection: Keep-Alive request header when communicating via a proxy server.
 int execute(org.apache.commons.httpclient.HttpState state, org.apache.commons.httpclient.HttpConnection conn)
          Executes this method using the specified HttpConnection and HttpState.
protected  void readResponseBody(org.apache.commons.httpclient.HttpState state, org.apache.commons.httpclient.HttpConnection connection)
          Read the response body from the given HttpConnection.
protected  boolean shouldCloseConnection(org.apache.commons.httpclient.HttpConnection conn)
          Tests if the connection should be closed after the method has been executed.
 
Methods inherited from class org.apache.commons.httpclient.methods.GetMethod
getName, recycle
 
Methods inherited from class org.apache.commons.httpclient.HttpMethodBase
abort, addCookieRequestHeader, addHostRequestHeader, addRequestHeader, addRequestHeader, addRequestHeaders, addResponseFooter, addUserAgentRequestHeader, checkNotUsed, checkUsed, generateRequestLine, getAuthenticationRealm, getContentCharSet, getDoAuthentication, getEffectiveVersion, getFollowRedirects, getHostAuthState, getHostConfiguration, getMethodRetryHandler, getParams, getPath, getProxyAuthenticationRealm, getProxyAuthState, getQueryString, getRecoverableExceptionCount, getRequestCharSet, getRequestHeader, getRequestHeaderGroup, getRequestHeaders, getRequestHeaders, getResponseBody, getResponseBodyAsStream, getResponseBodyAsString, getResponseCharSet, getResponseContentLength, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaderGroup, getResponseHeaders, getResponseHeaders, getResponseStream, getResponseTrailerHeaderGroup, getStatusCode, getStatusLine, getStatusText, getURI, hasBeenUsed, isAborted, isConnectionCloseForced, isHttp11, isRequestSent, isStrictMode, processResponseBody, processResponseHeaders, processStatusLine, readResponse, readResponseHeaders, readStatusLine, releaseConnection, removeRequestHeader, removeRequestHeader, responseBodyConsumed, setConnectionCloseForced, setDoAuthentication, setFollowRedirects, setHostConfiguration, setHttp11, setMethodRetryHandler, setParams, setPath, setQueryString, setQueryString, setRequestHeader, setRequestHeader, setResponseStream, setStrictMode, setURI, validate, writeRequest, writeRequestBody, writeRequestHeaders, writeRequestLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static java.util.logging.Logger logger

httpRecorderMethod

protected HttpRecorderMethod httpRecorderMethod
Instance of http recorder method.

Constructor Detail

HttpRecorderGetMethod

public HttpRecorderGetMethod(java.lang.String uri,
                             HttpRecorder recorder)
Method Detail

readResponseBody

protected void readResponseBody(org.apache.commons.httpclient.HttpState state,
                                org.apache.commons.httpclient.HttpConnection connection)
                         throws java.io.IOException,
                                org.apache.commons.httpclient.HttpException
Description copied from class: org.apache.commons.httpclient.HttpMethodBase
Read the response body from the given HttpConnection.

The current implementation wraps the socket level stream with an appropriate stream for the type of response (chunked, content-length, or auto-close). If there is no response body, the connection associated with the request will be returned to the connection manager.

Subclasses may want to override this method to to customize the processing.

Overrides:
readResponseBody in class org.apache.commons.httpclient.HttpMethodBase
Parameters:
state - the state information associated with this method
connection - the connection used to execute this HTTP method
Throws:
java.io.IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.
See Also:
HttpMethodBase.readResponse(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection), HttpMethodBase.processResponseBody(org.apache.commons.httpclient.HttpState, org.apache.commons.httpclient.HttpConnection)

shouldCloseConnection

protected boolean shouldCloseConnection(org.apache.commons.httpclient.HttpConnection conn)
Description copied from class: org.apache.commons.httpclient.HttpMethodBase
Tests if the connection should be closed after the method has been executed. The connection will be left open when using HTTP/1.1 or if Connection: keep-alive header was sent.

Overrides:
shouldCloseConnection in class org.apache.commons.httpclient.HttpMethodBase
Parameters:
conn - the connection in question
Returns:
boolean true if we should close the connection.

execute

public int execute(org.apache.commons.httpclient.HttpState state,
                   org.apache.commons.httpclient.HttpConnection conn)
            throws org.apache.commons.httpclient.HttpException,
                   java.io.IOException
Description copied from class: org.apache.commons.httpclient.HttpMethodBase
Executes this method using the specified HttpConnection and HttpState.

Specified by:
execute in interface org.apache.commons.httpclient.HttpMethod
Overrides:
execute in class org.apache.commons.httpclient.HttpMethodBase
Parameters:
state - state information to associate with this request. Must be non-null.
conn - the connection to used to execute this HTTP method. Must be non-null.
Returns:
the integer status code if one was obtained, or -1
Throws:
HttpException - if a protocol exception occurs.
java.io.IOException - if an I/O (transport) error occurs

addProxyConnectionHeader

protected void addProxyConnectionHeader(org.apache.commons.httpclient.HttpState state,
                                        org.apache.commons.httpclient.HttpConnection conn)
                                 throws java.io.IOException,
                                        org.apache.commons.httpclient.HttpException
Description copied from class: org.apache.commons.httpclient.HttpMethodBase
Generates Proxy-Connection: Keep-Alive request header when communicating via a proxy server.

Overrides:
addProxyConnectionHeader in class org.apache.commons.httpclient.HttpMethodBase
Parameters:
state - the state information associated with this method
conn - the connection used to execute this HTTP method
Throws:
java.io.IOException - if an I/O (transport) error occurs. Some transport exceptions can be recovered from.
HttpException - if a protocol exception occurs. Usually protocol exceptions cannot be recovered from.


Copyright © 2003-2011 Internet Archive. All Rights Reserved.