Save This Page
Home » commons-httpclient-3.1-src » org.apache.commons » httpclient » [javadoc | source]
org.apache.commons.httpclient
abstract public class: HttpMethodBase [javadoc | source]
java.lang.Object
   org.apache.commons.httpclient.HttpMethodBase

All Implemented Interfaces:
    HttpMethod

Direct Known Subclasses:
    TraceMethod, UrlOptionsMethod, PutMethod, NoncompliantPostMethod, PostMethod, EntityEnclosingMethod, FakeHttpMethod, UrlGetMethod, UrlDeleteMethod, DeleteMethod, SimpleHttpMethod, UrlPostMethod, NoncompliantHeadMethod, GetMethod, MultipartPostMethod, ExpectContinueMethod, UrlPutMethod, ConnectMethod, UrlHeadMethod, OptionsMethod, HeadMethod

An abstract base implementation of HttpMethod.

At minimum, subclasses will need to override:

When a method requires additional request headers, subclasses will typically want to override:

When a method expects specific response headers, subclasses may want to override:

Field Summary
protected  StatusLine statusLine    The Status-Line from the response. 
protected  HttpVersion effectiveVersion    HTTP protocol version used for execution of this method. 
Constructor:
 public HttpMethodBase() 
 public HttpMethodBase(String uri) throws IllegalArgumentException, IllegalStateException 
    Constructor specifying a URI. It is responsibility of the caller to ensure that URI elements (path & query parameters) are properly encoded (URL safe).
    Parameters:
    uri - either an absolute or relative URI. The URI is expected to be URL-encoded
    Throws:
    IllegalArgumentException - when URI is invalid
    IllegalStateException - when protocol of the absolute URI is not recognised
Method from org.apache.commons.httpclient.HttpMethodBase Summary:
abort,   addCookieRequestHeader,   addHostRequestHeader,   addProxyConnectionHeader,   addRequestHeader,   addRequestHeader,   addRequestHeaders,   addResponseFooter,   addUserAgentRequestHeader,   checkNotUsed,   checkUsed,   execute,   fakeResponse,   generateRequestLine,   getAuthenticationRealm,   getContentCharSet,   getDoAuthentication,   getEffectiveVersion,   getFollowRedirects,   getHostAuthState,   getHostConfiguration,   getMethodRetryHandler,   getName,   getParams,   getPath,   getProxyAuthState,   getProxyAuthenticationRealm,   getQueryString,   getRecoverableExceptionCount,   getRequestCharSet,   getRequestHeader,   getRequestHeaderGroup,   getRequestHeaders,   getRequestHeaders,   getResponseBody,   getResponseBody,   getResponseBodyAsStream,   getResponseBodyAsString,   getResponseBodyAsString,   getResponseCharSet,   getResponseContentLength,   getResponseFooter,   getResponseFooters,   getResponseHeader,   getResponseHeaderGroup,   getResponseHeaders,   getResponseHeaders,   getResponseStream,   getResponseTrailerHeaderGroup,   getStatusCode,   getStatusLine,   getStatusText,   getURI,   hasBeenUsed,   isAborted,   isConnectionCloseForced,   isHttp11,   isRequestSent,   isStrictMode,   processCookieHeaders,   processResponseBody,   processResponseHeaders,   processStatusLine,   readResponse,   readResponseBody,   readResponseHeaders,   readStatusLine,   recycle,   releaseConnection,   removeRequestHeader,   removeRequestHeader,   responseBodyConsumed,   setConnectionCloseForced,   setDoAuthentication,   setFollowRedirects,   setHostConfiguration,   setHttp11,   setMethodRetryHandler,   setParams,   setPath,   setQueryString,   setQueryString,   setRequestHeader,   setRequestHeader,   setResponseStream,   setStrictMode,   setURI,   shouldCloseConnection,   validate,   writeRequest,   writeRequestBody,   writeRequestHeaders,   writeRequestLine
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.httpclient.HttpMethodBase Detail:
 public  void abort() 
    Aborts the execution of this method.
 protected  void addCookieRequestHeader(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Generates Cookie request headers for those cookie s that match the given host, port and path.
 protected  void addHostRequestHeader(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Generates Host request header, as long as no Host request header already exists.
 protected  void addProxyConnectionHeader(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Generates Proxy-Connection: Keep-Alive request header when communicating via a proxy server.
 public  void addRequestHeader(Header header) 
    Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
 public  void addRequestHeader(String headerName,
    String headerValue) 
    Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
 protected  void addRequestHeaders(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Generates all the required request header s to be submitted via the given connection .

    This implementation adds User-Agent, Host, Cookie, Authorization, Proxy-Authorization and Proxy-Connection headers, when appropriate.

    Subclasses may want to override this method to to add additional headers, and may choose to invoke this implementation (via super) to add the "standard" headers.

 public  void addResponseFooter(Header footer) 
    Use this method internally to add footers.
 protected  void addUserAgentRequestHeader(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Generates default User-Agent request header, as long as no User-Agent request header already exists.
 protected  void checkNotUsed() throws IllegalStateException 
 protected  void checkUsed() throws IllegalStateException 
 public int execute(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Executes this method using the specified HttpConnection and HttpState.
  void fakeResponse(StatusLine statusline,
    HeaderGroup responseheaders,
    InputStream responseStream) 
    This method is a dirty hack intended to work around current (2.0) design flaw that prevents the user from obtaining correct status code, headers and response body from the preceding HTTP CONNECT method. TODO: Remove this crap as soon as possible
 protected static String generateRequestLine(HttpConnection connection,
    String name,
    String requestPath,
    String query,
    String version) 
    Generates HTTP request line according to the specified attributes.
 public String getAuthenticationRealm() 
Deprecated! use - #getHostAuthState()

    Returns authentication realm, if it has been used during authentication process. Otherwise returns null.
 protected String getContentCharSet(Header contentheader) 
    Returns the character set from the Content-Type header.
 public boolean getDoAuthentication() 
    Returns true if the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.), false otherwise
 public HttpVersion getEffectiveVersion() 
    Returns the HTTP version used with this method (may be null if undefined, that is, the method has not been executed)
 public boolean getFollowRedirects() 
    Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.
 public AuthState getHostAuthState() 
 public HostConfiguration getHostConfiguration() 
Deprecated! no - longer applicable

 public MethodRetryHandler getMethodRetryHandler() 
Deprecated! use - HttpMethodParams

 abstract public String getName()
    Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".
 public HttpMethodParams getParams() 
 public String getPath() 
    Gets the path of this HTTP method. Calling this method after the request has been executed will return the actual path, following any redirects automatically handled by this HTTP method.
 public AuthState getProxyAuthState() 
 public String getProxyAuthenticationRealm() 
Deprecated! use - #getProxyAuthState()

    Returns proxy authentication realm, if it has been used during authentication process. Otherwise returns null.
 public String getQueryString() 
    Gets the query string of this HTTP method.
 public int getRecoverableExceptionCount() 
Deprecated! no - longer used Returns the number of "recoverable" exceptions thrown and handled, to allow for monitoring the quality of the connection.

 public String getRequestCharSet() 
    Returns the character encoding of the request from the Content-Type header.
 public Header getRequestHeader(String headerName) 
    Returns the specified request header. Note that header-name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.
 protected HeaderGroup getRequestHeaderGroup() 
 public Header[] getRequestHeaders() 
    Returns an array of the requests headers that the HTTP method currently has
 public Header[] getRequestHeaders(String headerName) 
 public byte[] getResponseBody() throws IOException 
    Returns the response body of the HTTP method, if any, as an array of bytes. If response body is not available or cannot be read, returns null. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.
 public byte[] getResponseBody(int maxlen) throws IOException 
    Returns the response body of the HTTP method, if any, as an array of bytes. If response body is not available or cannot be read, returns null. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. This method is safe if the content length of the response is unknown, because the amount of memory used is limited.

    If the response is large this method involves lots of array copying and many object allocations, which makes it unsuitable for high-performance / low-footprint applications. Those applications should use #getResponseBodyAsStream() .

 public InputStream getResponseBodyAsStream() throws IOException 
    Returns the response body of the HTTP method, if any, as an InputStream . If response body is not available, returns null. If the response has been buffered this method returns a new stream object on every call. If the response has not been buffered the returned stream can only be read once.
 public String getResponseBodyAsString() throws IOException 
    Returns the response body of the HTTP method, if any, as a String . If response body is not available or cannot be read, returns null The string conversion on the data is done using the character encoding specified in Content-Type header. Buffers the response and this method can be called several times yielding the same result each time. Note: This will cause the entire response body to be buffered in memory. A malicious server may easily exhaust all the VM memory. It is strongly recommended, to use getResponseAsStream if the content length of the response is unknown or resonably large.
 public String getResponseBodyAsString(int maxlen) throws IOException 
    Returns the response body of the HTTP method, if any, as a String . If response body is not available or cannot be read, returns null The string conversion on the data is done using the character encoding specified in Content-Type header. Buffers the response and this method can be called several times yielding the same result each time.

    Note: This will cause the entire response body to be buffered in memory. This method is safe if the content length of the response is unknown, because the amount of memory used is limited.

    If the response is large this method involves lots of array copying and many object allocations, which makes it unsuitable for high-performance / low-footprint applications. Those applications should use #getResponseBodyAsStream() .

 public String getResponseCharSet() 
    Returns the character encoding of the response from the Content-Type header.
 public long getResponseContentLength() 
    Return the length (in bytes) of the response body, as specified in a Content-Length header.

    Return -1 when the content-length is unknown.

 public Header getResponseFooter(String footerName) 
    Gets the response footer associated with the given name. Footer name matching is case insensitive. null will be returned if either footerName is null or there is no matching footer for footerName or there are no footers available. If there are multiple footers with the same name, there values will be combined with the ',' separator as specified by RFC2616.
 public Header[] getResponseFooters() 
    Returns an array of the response footers that the HTTP method currently has in the order in which they were read.
 public Header getResponseHeader(String headerName) 
    Gets the response header associated with the given name. Header name matching is case insensitive. null will be returned if either headerName is null or there is no matching header for headerName.
 protected HeaderGroup getResponseHeaderGroup() 
 public Header[] getResponseHeaders() 
    Returns an array of the response headers that the HTTP method currently has in the order in which they were read.
 public Header[] getResponseHeaders(String headerName) 
 protected InputStream getResponseStream() 
    Returns a stream from which the body of the current response may be read. If the method has not yet been executed, if responseBodyConsumed has been called, or if the stream returned by a previous call has been closed, null will be returned.
 protected HeaderGroup getResponseTrailerHeaderGroup() 
    Gets the header group storing the response trailer headers as per RFC 2616 section 3.6.1.
 public int getStatusCode() 
    Returns the response status code.
 public StatusLine getStatusLine() 
    Provides access to the response status line.
 public String getStatusText() 
    Returns the status text (or "reason phrase") associated with the latest response.
 public URI getURI() throws URIException 
    Returns the URI of the HTTP method
 public boolean hasBeenUsed() 
 public boolean isAborted() 
    Tests whether the execution of this method has been aborted
 protected boolean isConnectionCloseForced() 
    Tests if the connection should be force-closed when no longer needed.
 public boolean isHttp11() 
Deprecated! Use - HttpMethodParams#getVersion()

    Returns true if version 1.1 of the HTTP protocol should be used per default, false if version 1.0 should be used.
 public boolean isRequestSent() 
    Returns true if the HTTP has been transmitted to the target server in its entirety, false otherwise. This flag can be useful for recovery logic. If the request has not been transmitted in its entirety, it is safe to retry the failed method.
 public boolean isStrictMode() 
Deprecated! Use - org.apache.commons.httpclient.params.HttpParams#setParameter(String, Object) to exercise a more granular control over HTTP protocol strictness.

 protected  void processCookieHeaders(CookieSpec parser,
    Header[] headers,
    HttpState state,
    HttpConnection conn) 
 protected  void processResponseBody(HttpState state,
    HttpConnection conn) 
 protected  void processResponseHeaders(HttpState state,
    HttpConnection conn) 
    This method is invoked immediately after #readResponseHeaders(HttpState,HttpConnection) and can be overridden by sub-classes in order to provide custom response headers processing.

    This implementation will handle the Set-Cookie and Set-Cookie2 headers, if any, adding the relevant cookies to the given HttpState .

 protected  void processStatusLine(HttpState state,
    HttpConnection conn) 
 protected  void readResponse(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
 protected  void readResponseBody(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    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.

 protected  void readResponseHeaders(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Reads the response headers from the given connection .

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

    "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)

 protected  void readStatusLine(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
 public  void recycle() 
Deprecated! no - longer supported and will be removed in the future version of HttpClient

    Recycles the HTTP method so that it can be used again. Note that all of the instance variables will be reset once this method has been called. This method will also release the connection being used by this HTTP method.
 public  void releaseConnection() 
    Releases the connection being used by this HTTP method. In particular the connection is used to read the response(if there is one) and will be held until the response has been read. If the connection can be reused by other HTTP methods it is NOT closed at this point.
 public  void removeRequestHeader(String headerName) 
    Remove the request header associated with the given name. Note that header-name matching is case insensitive.
 public  void removeRequestHeader(Header header) 
    Removes the given request header.
 protected  void responseBodyConsumed() 
    A response has been consumed.

    The default behavior for this class is to check to see if the connection should be closed, and close if need be, and to ensure that the connection is returned to the connection manager - if and only if we are not still inside the execute call.

 protected  void setConnectionCloseForced(boolean b) 
    Sets whether or not the connection should be force-closed when no longer needed. This value should only be set to true in abnormal circumstances, such as HTTP protocol violations.
 public  void setDoAuthentication(boolean doAuthentication) 
    Sets whether or not the HTTP method should automatically handle HTTP authentication challenges (status code 401, etc.)
 public  void setFollowRedirects(boolean followRedirects) 
    Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)
 public  void setHostConfiguration(HostConfiguration hostconfig) 
Deprecated! no - longer applicable

 public  void setHttp11(boolean http11) 
Deprecated! Use - HttpMethodParams#setVersion(HttpVersion)

    Sets whether version 1.1 of the HTTP protocol should be used per default.
 public  void setMethodRetryHandler(MethodRetryHandler handler) 
Deprecated! use - HttpMethodParams

 public  void setParams(HttpMethodParams params) 
 public  void setPath(String path) 
    Sets the path of the HTTP method. It is responsibility of the caller to ensure that the path is properly encoded (URL safe).
 public  void setQueryString(String queryString) 
    Sets the query string of this HTTP method. The caller must ensure that the string is properly URL encoded. The query string should not start with the question mark character.
 public  void setQueryString(NameValuePair[] params) 
    Sets the query string of this HTTP method. The pairs are encoded as UTF-8 characters. To use a different charset the parameters can be encoded manually using EncodingUtil and set as a single String.
 public  void setRequestHeader(Header header) 
    Sets the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.
 public  void setRequestHeader(String headerName,
    String headerValue) 
    Set the specified request header, overwriting any previous value. Note that header-name matching is case-insensitive.
 protected  void setResponseStream(InputStream responseStream) 
    Sets the response stream.
 public  void setStrictMode(boolean strictMode) 
Deprecated! Use - org.apache.commons.httpclient.params.HttpParams#setParameter(String, Object) to exercise a more granular control over HTTP protocol strictness.

    Defines how strictly HttpClient follows the HTTP protocol specification (RFC 2616 and other relevant RFCs). In the strict mode HttpClient precisely implements the requirements of the specification, whereas in non-strict mode it attempts to mimic the exact behaviour of commonly used HTTP agents, which many HTTP servers expect.
 public  void setURI(URI uri) throws URIException 
    Sets the URI for this method.
 protected boolean shouldCloseConnection(HttpConnection conn) 
    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.
 public boolean validate() 
    Returns true the method is ready to execute, false otherwise.
 protected  void writeRequest(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
 protected boolean writeRequestBody(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Writes the request body to the given connection .

    This method should return true if the request body was actually sent (or is empty), or false if it could not be sent for some reason.

    This implementation writes nothing and returns true.

 protected  void writeRequestHeaders(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
 protected  void writeRequestLine(HttpState state,
    HttpConnection conn) throws IOException, HttpException 
    Writes the request line to the given connection .

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