Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.mockobjects.apache.commons.httpclient
Class MockHttpMethod  view MockHttpMethod download MockHttpMethod.java

java.lang.Object
  extended bycom.mockobjects.MockObject
      extended bycom.mockobjects.apache.commons.httpclient.MockMethodHelper
          extended bycom.mockobjects.apache.commons.httpclient.MockHttpMethod
All Implemented Interfaces:
org.apache.commons.httpclient.HttpMethod, com.mockobjects.Verifiable

public class MockHttpMethod
extends MockMethodHelper
implements org.apache.commons.httpclient.HttpMethod


Constructor Summary
MockHttpMethod()
           
 
Method Summary
 void addGetResponseHeader(java.lang.String key, org.apache.commons.httpclient.Header header)
           
 void addRequestHeader(org.apache.commons.httpclient.Header header)
          Adds the specified request header, not overwriting any previous value.
 void addRequestHeader(java.lang.String name, java.lang.String value)
          Adds the specified request header, not overwriting any previous value.
 int execute(org.apache.commons.httpclient.HttpState state, org.apache.commons.httpclient.HttpConnection connection)
          Executes this method using the specified HttpConnection and HttpState.
 boolean getFollowRedirects()
          Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.
 java.lang.String getName()
          Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".
 java.lang.String getPath()
          Returns the path of the HTTP method.
 java.lang.String getQueryString()
          Returns the query string of this HTTP method.
 org.apache.commons.httpclient.Header getRequestHeader(java.lang.String name)
          Gets the request header with the given name.
 org.apache.commons.httpclient.Header[] getRequestHeaders()
          Returns the current request headers for this HTTP method.
 byte[] getResponseBody()
          Returns the response body of the HTTP method, if any, as an array of bytes.
 java.io.InputStream getResponseBodyAsStream()
          Returns the response body of the HTTP method, if any, as an InputStream.
 java.lang.String getResponseBodyAsString()
          Returns the response body of the HTTP method, if any, as a java.lang.String.
 org.apache.commons.httpclient.Header getResponseHeader(java.lang.String key)
          Returns the specified response header.
 org.apache.commons.httpclient.Header[] getResponseHeaders()
          Returns the response headers from the most recent execution of this request.
 int getStatusCode()
          Returns the status code associated with the latest response.
 java.lang.String getStatusText()
          Returns the status text (or "reason phrase") associated with the latest response.
 boolean hasBeenUsed()
          Returns true if the HTTP method has been already executed 55 , but not recycled 55 .
 boolean isStrictMode()
          Returns the value of the strict mode flag.
 void recycle()
          Recycles the HTTP method so that it can be used again.
 void removeRequestHeader(java.lang.String name)
          Removes all request headers with the given name.
 void setFollowRedirects(boolean followRedirects)
          Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)
 void setPath(java.lang.String path)
          Sets the path of the HTTP method.
 void setQueryString(org.apache.commons.httpclient.NameValuePair[] nameValuePair)
          Sets the query string of this HTTP method.
 void setQueryString(java.lang.String queryString)
          Sets the query string of the HTTP method.
 void setRequestHeader(org.apache.commons.httpclient.Header header)
          Sets the specified request header, overwriting any previous value.
 void setRequestHeader(java.lang.String name, java.lang.String value)
          Sets the specified request header, overwriting any previous value.
 void setStrictMode(boolean strictMode)
          Defines how strictly the method follows the HTTP protocol specification.
 boolean validate()
          Returns true the method is ready to execute, false otherwise.
 
Methods inherited from class com.mockobjects.MockObject
assertEquals, assertEquals, assertTrue, fail, notImplemented, notYetImplemented, notYetImplemented, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.httpclient.HttpMethod
abort, addResponseFooter, getDoAuthentication, getHostAuthState, getHostConfiguration, getParams, getProxyAuthState, getRequestHeaders, getResponseFooter, getResponseFooters, getResponseHeader, getResponseHeaders, getStatusLine, getURI, isRequestSent, releaseConnection, removeRequestHeader, setDoAuthentication, setParams, setURI
 

Constructor Detail

MockHttpMethod

public MockHttpMethod()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Obtains the name of the HTTP method as used in the HTTP request line, for example "GET" or "POST".

Specified by:
getName in interface org.apache.commons.httpclient.HttpMethod

setPath

public void setPath(java.lang.String path)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Sets the path of the HTTP method. It is responsibility of the caller to ensure that the path is properly encoded (URL safe).

Specified by:
setPath in interface org.apache.commons.httpclient.HttpMethod

getPath

public java.lang.String getPath()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the path of the 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.

Specified by:
getPath in interface org.apache.commons.httpclient.HttpMethod

setStrictMode

public void setStrictMode(boolean strictMode)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Defines how strictly the method follows the HTTP protocol specification. (See RFC 2616 and other relevant RFCs.) In the strict mode the method 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.

Specified by:
setStrictMode in interface org.apache.commons.httpclient.HttpMethod

isStrictMode

public boolean isStrictMode()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the value of the strict mode flag.

Specified by:
isStrictMode in interface org.apache.commons.httpclient.HttpMethod

setRequestHeader

public void setRequestHeader(java.lang.String name,
                             java.lang.String value)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Sets the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.

Specified by:
setRequestHeader in interface org.apache.commons.httpclient.HttpMethod

setRequestHeader

public void setRequestHeader(org.apache.commons.httpclient.Header header)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Sets the specified request header, overwriting any previous value. Note that header-name matching is case insensitive.

Specified by:
setRequestHeader in interface org.apache.commons.httpclient.HttpMethod

addRequestHeader

public void addRequestHeader(java.lang.String name,
                             java.lang.String value)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Adds the specified request header, not overwriting any previous value. If the same header is added multiple times, perhaps with different values, multiple instances of that header will be sent in the HTTP request. Note that header-name matching is case insensitive.

Specified by:
addRequestHeader in interface org.apache.commons.httpclient.HttpMethod

addRequestHeader

public void addRequestHeader(org.apache.commons.httpclient.Header header)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Adds the specified request header, not overwriting any previous value. If the same header is added multiple times, perhaps with different values, multiple instances of that header will be sent in the HTTP request. Note that header-name matching is case insensitive.

Specified by:
addRequestHeader in interface org.apache.commons.httpclient.HttpMethod

getRequestHeader

public org.apache.commons.httpclient.Header getRequestHeader(java.lang.String name)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Gets the request header with the given name. If there are multiple headers with the same name, there values will be combined with the ',' separator as specified by RFC2616. Note that header-name matching is case insensitive.

Specified by:
getRequestHeader in interface org.apache.commons.httpclient.HttpMethod

removeRequestHeader

public void removeRequestHeader(java.lang.String name)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Removes all request headers with the given name. Note that header-name matching is case insensitive.

Specified by:
removeRequestHeader in interface org.apache.commons.httpclient.HttpMethod

getFollowRedirects

public boolean getFollowRedirects()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns true if the HTTP method should automatically follow HTTP redirects (status code 302, etc.), false otherwise.

Specified by:
getFollowRedirects in interface org.apache.commons.httpclient.HttpMethod

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Sets whether or not the HTTP method should automatically follow HTTP redirects (status code 302, etc.)

Specified by:
setFollowRedirects in interface org.apache.commons.httpclient.HttpMethod

setQueryString

public void setQueryString(java.lang.String queryString)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Sets the query string of the HTTP method. It is responsibility of the caller to ensure that the path is properly encoded (URL safe). The string must not include an initial '?' character.

Specified by:
setQueryString in interface org.apache.commons.httpclient.HttpMethod

setQueryString

public void setQueryString(org.apache.commons.httpclient.NameValuePair[] nameValuePair)
Description copied from interface: org.apache.commons.httpclient.HttpMethod
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.

Specified by:
setQueryString in interface org.apache.commons.httpclient.HttpMethod

getQueryString

public java.lang.String getQueryString()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the query string of this HTTP method.

Specified by:
getQueryString in interface org.apache.commons.httpclient.HttpMethod

getRequestHeaders

public org.apache.commons.httpclient.Header[] getRequestHeaders()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the current request headers for this HTTP method. The returned headers will be in the same order that they were added with addRequestHeader. If there are multiple request headers with the same name (e.g. Cookie), they will be returned as multiple entries in the array.

Specified by:
getRequestHeaders in interface org.apache.commons.httpclient.HttpMethod

validate

public boolean validate()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns true the method is ready to execute, false otherwise.

Specified by:
validate in interface org.apache.commons.httpclient.HttpMethod

getStatusCode

public int getStatusCode()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the status code associated with the latest response.

Specified by:
getStatusCode in interface org.apache.commons.httpclient.HttpMethod

getStatusText

public java.lang.String getStatusText()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the status text (or "reason phrase") associated with the latest response.

Specified by:
getStatusText in interface org.apache.commons.httpclient.HttpMethod

getResponseHeaders

public org.apache.commons.httpclient.Header[] getResponseHeaders()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the response headers from the most recent execution of this request.

Specified by:
getResponseHeaders in interface org.apache.commons.httpclient.HttpMethod

getResponseBody

public byte[] getResponseBody()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the response body of the HTTP method, if any, as an array of bytes. If the method has not yet been executed or the response has no body, null is returned. Note that this method does not propagate I/O exceptions. If an error occurs while reading the body, null will be returned.

Specified by:
getResponseBody in interface org.apache.commons.httpclient.HttpMethod

getResponseBodyAsString

public java.lang.String getResponseBodyAsString()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the response body of the HTTP method, if any, as a java.lang.String. If response body is not available or cannot be read, null is returned. The raw bytes in the body are converted to a String using the character encoding specified in the response's Content-Type header, or ISO-8859-1 if the response did not specify a character set.

Note that this method does not propagate I/O exceptions. If an error occurs while reading the body, null will be returned.

Specified by:
getResponseBodyAsString in interface org.apache.commons.httpclient.HttpMethod

getResponseBodyAsStream

public java.io.InputStream getResponseBodyAsStream()
                                            throws java.io.IOException
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns the response body of the HTTP method, if any, as an InputStream. If the response had no body or the method has not yet been executed, null is returned. Additionally, null may be returned if HttpMethod.releaseConnection()>HttpMethod.releaseConnection() 55 has been called or if this method was called previously and the resulting stream was closed.

Specified by:
getResponseBodyAsStream in interface org.apache.commons.httpclient.HttpMethod

hasBeenUsed

public boolean hasBeenUsed()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
Returns true if the HTTP method has been already executed 55 , but not recycled 55 .

Specified by:
hasBeenUsed in interface org.apache.commons.httpclient.HttpMethod

execute

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

Specified by:
execute in interface org.apache.commons.httpclient.HttpMethod

recycle

public void recycle()
Description copied from interface: org.apache.commons.httpclient.HttpMethod
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.

Specified by:
recycle in interface org.apache.commons.httpclient.HttpMethod

getResponseHeader

public org.apache.commons.httpclient.Header getResponseHeader(java.lang.String key)

addGetResponseHeader

public void addGetResponseHeader(java.lang.String key,
                                 org.apache.commons.httpclient.Header header)