com.gargoylesoftware.htmlunit.util
Class WebResponseWrapper

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.WebResponse
      extended by com.gargoylesoftware.htmlunit.util.WebResponseWrapper
All Implemented Interfaces:
Serializable

public class WebResponseWrapper
extends WebResponse

Provides a convenient implementation of the WebResponse interface that can be subclassed by developers wishing to adapt a particular WebResponse. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped web response object.

Version:
$Revision: 5835 $
Author:
Marc Guillemot, Ahmed Ashour
See Also:
Serialized Form

Constructor Summary
WebResponseWrapper(WebResponse webResponse)
          Constructs a WebResponse object wrapping provided WebResponse.
 
Method Summary
 byte[] getContentAsBytes()
          Deprecated. as of 2.8, use either getContentAsString() or getContentAsStream().
 InputStream getContentAsStream()
          Returns the response content as an input stream.
 String getContentAsString()
          Returns the response content as a string, using the charset/encoding specified in the server response.
 String getContentAsString(String encoding)
          Returns the response content as a string, using the specified charset/encoding, rather than the charset/encoding specified in the server response.
 String getContentCharset()
          Returns the content charset for this response, even if no charset was specified explicitly.
 String getContentCharsetOrNull()
          Returns the content charset specified explicitly in the header or in the content, or null if none was specified.
 String getContentType()
          Returns the content type returned from the server, e.g.
 long getLoadTime()
          Returns the time it took to load this web response, in milliseconds.
 WebRequest getRequestSettings()
          Deprecated. as of 2.8, please use getWebRequest() instead
 URL getRequestUrl()
          Returns the URL that was used to load this page.
 List<NameValuePair> getResponseHeaders()
          Returns the response headers as a list of NameValuePairs.
 String getResponseHeaderValue(String headerName)
          Returns the value of the specified response header.
 int getStatusCode()
          Returns the status code that was returned by the server.
 String getStatusMessage()
          Returns the status message that was returned from the server.
 WebRequest getWebRequest()
          Returns the request used to load this response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebResponseWrapper

public WebResponseWrapper(WebResponse webResponse)
                   throws IllegalArgumentException
Constructs a WebResponse object wrapping provided WebResponse.

Parameters:
webResponse - the webResponse that does the real work
Throws:
IllegalArgumentException - if the webResponse is null
Method Detail

getContentAsStream

public InputStream getContentAsStream()
Returns the response content as an input stream. The default behavior of this method is to return getContentAsStream() on the wrapped webResponse object.

Overrides:
getContentAsStream in class WebResponse
Returns:
the response content as an input stream

getContentAsString

public String getContentAsString()
Returns the response content as a string, using the charset/encoding specified in the server response. The default behavior of this method is to return getContentAsString() on the wrapped webResponse object.

Overrides:
getContentAsString in class WebResponse
Returns:
the response content as a string, using the charset/encoding specified in the server response

getContentAsString

public String getContentAsString(String encoding)
Returns the response content as a string, using the specified charset/encoding, rather than the charset/encoding specified in the server response. If the specified charset/encoding is not supported then the default system encoding is used. The default behavior of this method is to return getContentAsString(String) on the wrapped webResponse object.

Overrides:
getContentAsString in class WebResponse
Parameters:
encoding - the charset/encoding to use to convert the response content into a string
Returns:
the response content as a string

getContentAsBytes

@Deprecated
public byte[] getContentAsBytes()
Deprecated. as of 2.8, use either getContentAsString() or getContentAsStream().

Returns the response content as a byte array. The default behavior of this method is to return getContentAsBytes() on the wrapped webResponse object.

Overrides:
getContentAsBytes in class WebResponse
Returns:
the response content as a byte array

getContentCharsetOrNull

public String getContentCharsetOrNull()
Returns the content charset specified explicitly in the header or in the content, or null if none was specified. The default behavior of this method is to return getContentCharsetOrNull() on the wrapped webResponse object.

Overrides:
getContentCharsetOrNull in class WebResponse
Returns:
the content charset specified explicitly in the header or in the content, or null if none was specified

getContentCharset

public String getContentCharset()
Returns the content charset for this response, even if no charset was specified explicitly. This method always returns a valid charset. This method first checks the "Content-Type" header; if not found, it checks the response content; as a last resort, this method returns TextUtil.DEFAULT_CHARSET. The default behavior of this method is to return getContentCharset() on the wrapped webResponse object.

Overrides:
getContentCharset in class WebResponse
Returns:
the content charset for this response

getContentType

public String getContentType()
Returns the content type returned from the server, e.g. "text/html". The default behavior of this method is to return getContentType() on the wrapped webResponse object.

Overrides:
getContentType in class WebResponse
Returns:
the content type returned from the server, e.g. "text/html"

getLoadTime

public long getLoadTime()
Returns the time it took to load this web response, in milliseconds. The default behavior of this method is to return getLoadTime() on the wrapped webResponse object.

Overrides:
getLoadTime in class WebResponse
Returns:
the time it took to load this web response, in milliseconds

getResponseHeaders

public List<NameValuePair> getResponseHeaders()
Returns the response headers as a list of NameValuePairs. The default behavior of this method is to return getResponseHeaders() on the wrapped webResponse object.

Overrides:
getResponseHeaders in class WebResponse
Returns:
the response headers as a list of NameValuePairs

getResponseHeaderValue

public String getResponseHeaderValue(String headerName)
Returns the value of the specified response header. The default behavior of this method is to return getResponseHeaderValue() on the wrapped webResponse object.

Overrides:
getResponseHeaderValue in class WebResponse
Parameters:
headerName - the name of the header whose value is to be returned
Returns:
the header value, null if no response header exists with this name

getStatusCode

public int getStatusCode()
Returns the status code that was returned by the server. The default behavior of this method is to return getStatusCode() on the wrapped webResponse object.

Overrides:
getStatusCode in class WebResponse
Returns:
the status code that was returned by the server

getStatusMessage

public String getStatusMessage()
Returns the status message that was returned from the server. The default behavior of this method is to return getStatusMessage() on the wrapped webResponse object.

Overrides:
getStatusMessage in class WebResponse
Returns:
the status message that was returned from the server

getRequestSettings

@Deprecated
public WebRequest getRequestSettings()
Deprecated. as of 2.8, please use getWebRequest() instead

Returns the request used to load this response. The default behavior of this method is to return getRequestSettings() on the wrapped webResponse object.

Overrides:
getRequestSettings in class WebResponse
Returns:
the request used to load this response

getWebRequest

public WebRequest getWebRequest()
Returns the request used to load this response. The default behavior of this method is to return getWebRequest() on the wrapped webResponse object.

Overrides:
getWebRequest in class WebResponse
Returns:
the request used to load this response

getRequestUrl

public URL getRequestUrl()
Returns the URL that was used to load this page.

Overrides:
getRequestUrl in class WebResponse
Returns:
the URL that was used to load this page


Copyright © 2002-2010 Gargoyle Software Inc.. All Rights Reserved.