org.apache.commons.httpclient
Interface HttpMethod

All Known Subinterfaces:
HttpUrlMethod
All Known Implementing Classes:
HttpMethodBase

public interface HttpMethod

A request to be applied to an HttpConnection, and a container for the associated response.

Version:
$Revision: 1.16 $ $Date: 2002/09/03 01:36:26 $
Author:
Remy Maucherat, Rod Waldhoff

Method Summary
 void addRequestHeader(Header header)
          Adds the specified request header, NOT overwriting any previous value.
 void addRequestHeader(java.lang.String headerName, java.lang.String headerValue)
          Adds the specified request header, NOT overwriting any previous value.
 void addResponseFooter(Header footer)
          Use this method internally to add footers.
 int execute(HttpState state, HttpConnection connection)
          Execute this method.
 boolean getFollowRedirects()
          Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 java.lang.String getName()
          Obtain the name of this method, suitable for use in the "request line", for example "GET" or "POST".
 java.lang.String getPath()
          Get the path part of my request.
 java.lang.String getQueryString()
          Get my query string.
 Header getRequestHeader(java.lang.String headerName)
          Get the request header associated with the given name.
 Header[] getRequestHeaders()
          Return an array of my request headers.
 byte[] getResponseBody()
          Return my response body, if any, as a byte array.
 java.io.InputStream getResponseBodyAsStream()
          Return my response body, if any, as an InputStream.
 java.lang.String getResponseBodyAsString()
          Return my response body, if any, as a String.
 Header getResponseFooter(java.lang.String footerName)
          Return the specified response footer.
 Header[] getResponseFooters()
          Return an array of my response footers
 Header getResponseHeader(java.lang.String headerName)
          Return the specified response header.
 Header[] getResponseHeaders()
          Return an array of my response headers.
 int getStatusCode()
          Return the status code associated with the latest response.
 java.lang.String getStatusText()
          Return the status text (or "reason phrase") associated with the latest response.
 boolean hasBeenUsed()
          Return true if I have been executed but not recycled.
 boolean isStrictMode()
          Returns the value of strictMode.
 void recycle()
          Recycle this method so that it can be used again.
 void removeRequestHeader(java.lang.String headerName)
          Remove all request headers associated with the given name.
 void setFollowRedirects(boolean followRedirects)
          Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 void setPath(java.lang.String path)
          Set the path part of my request.
 void setQueryString(NameValuePair[] params)
          Set my query string.
 void setQueryString(java.lang.String queryString)
          Set my query string.
 void setRequestHeader(Header header)
          Set the specified request header, overwriting any previous value.
 void setRequestHeader(java.lang.String headerName, java.lang.String headerValue)
          Set the specified request header, overwriting any previous value.
 void setStrictMode(boolean strictMode)
          Turns strict mode on or off.
 boolean validate()
          Confirm that I am ready to execute.
 

Method Detail

getName

public java.lang.String getName()
Obtain the name of this method, suitable for use in the "request line", for example "GET" or "POST".
Returns:
the name of this method

setPath

public void setPath(java.lang.String path)
Set the path part of my request.
Parameters:
path - the path to request

getPath

public java.lang.String getPath()
Get the path part of my request. Calling this method AFTER the request has been executed will return the ACTUAL path, following any 301 or 302 redirects (except for redirects off the initial server, which are not supported, or when HttpClient is set to not follow redirects; in either case, HttpClient returns the 301 or 302 status code).
Returns:
the path to request

setStrictMode

public void setStrictMode(boolean strictMode)
Turns strict mode on or off. In strict mode (the default) we following the letter of RFC 2616, the Http 1.1 specification. If strict mode is turned off we attempt to violate the specification 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.

isStrictMode

public boolean isStrictMode()
Returns the value of strictMode. NOTE: StrictMode is currently experimental and its functionlaity may change in the future.
Returns:
true if strict mode is enabled.

setRequestHeader

public void setRequestHeader(java.lang.String headerName,
                             java.lang.String headerValue)
Set the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
headerName - the header's name
headerValue - the header's value

setRequestHeader

public void setRequestHeader(Header header)
Set the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
header - the header

addRequestHeader

public void addRequestHeader(java.lang.String headerName,
                             java.lang.String headerValue)
Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
headerName - the header's name
headerValue - the header's value

addRequestHeader

public void addRequestHeader(Header header)
Adds the specified request header, NOT overwriting any previous value. Note that header-name matching is case insensitive.
Parameters:
header - the header

getRequestHeader

public Header getRequestHeader(java.lang.String headerName)
Get the request header associated with the given name. Note that header-name matching is case insensitive.
Parameters:
headerName - the header name
Returns:
the header

removeRequestHeader

public void removeRequestHeader(java.lang.String headerName)
Remove all request headers associated with the given name. Note that header-name matching is case insensitive.
Parameters:
headerName - the header name

getFollowRedirects

public boolean getFollowRedirects()
Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
Returns:
true if I will automatically follow HTTP redirects

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)

setQueryString

public void setQueryString(java.lang.String queryString)
Set my query string.
Parameters:
queryString - the query string

setQueryString

public void setQueryString(NameValuePair[] params)
Set my query string.
Parameters:
params - an array of NameValuePairs to add as query string parameterss

getQueryString

public java.lang.String getQueryString()
Get my query string.
Returns:
my query string

getRequestHeaders

public Header[] getRequestHeaders()
Return an array of my request headers.

validate

public boolean validate()
Confirm that I am ready to execute.

getStatusCode

public int getStatusCode()
Return the status code associated with the latest response.

getStatusText

public java.lang.String getStatusText()
Return the status text (or "reason phrase") associated with the latest response.

getResponseHeaders

public Header[] getResponseHeaders()
Return an array of my response headers.

getResponseHeader

public Header getResponseHeader(java.lang.String headerName)
Return the specified response header. Note that header-name matching is case insensitive.

getResponseFooters

public Header[] getResponseFooters()
Return an array of my response footers
Returns:
null if no footers are available

getResponseFooter

public Header getResponseFooter(java.lang.String footerName)
Return the specified response footer. Note that footer-name matching is case insensitive.

getResponseBody

public byte[] getResponseBody()
Return my response body, if any, as a byte array. Otherwise return null.

getResponseBodyAsString

public java.lang.String getResponseBodyAsString()
Return my response body, if any, as a String. Otherwise return null.

getResponseBodyAsStream

public java.io.InputStream getResponseBodyAsStream()
                                            throws java.io.IOException
Return my response body, if any, as an InputStream. Otherwise return null.

hasBeenUsed

public boolean hasBeenUsed()
Return true if I have been executed but not recycled.

execute

public int execute(HttpState state,
                   HttpConnection connection)
            throws HttpException,
                   java.io.IOException
Execute this method.
Parameters:
state - state information to associate with this request
connection - the HttpConnection to write to/read from
Returns:
the integer status code if one was obtained, or -1
Throws:
java.io.IOException - if an I/O error occurs
HttpException - if an protocol exception occurs

recycle

public void recycle()
Recycle this method so that it can be used again. Note that all of my instance variables will be reset once this method has been called.

addResponseFooter

public void addResponseFooter(Header footer)
Use this method internally to add footers.


Copyright (c) 2001 - Apache Software Foundation