## com.gargoylesoftware.htmlunit.util
Class WebResponseWrapper

    java.lang.Object
      com.gargoylesoftware.htmlunit.util.WebResponseWrapper

All Implemented Interfaces:
  WebResponse, java.io.Serializable

    public class WebResponseWrapper

extends java.lang.Object
implements 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 connection object.

Version:
  $Revision: 4872 $
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()` Returns the response content as a byte array.
`java.io.InputStream` `getContentAsStream()` Returns the response content as an input stream.
`java.lang.String` `getContentAsString()` Returns the response content as a string, using the charset/encoding specified in the server response.
`java.lang.String` `getContentAsString(java.lang.String encoding)` Returns the response content as a string, using the specified charset/encoding, rather than the charset/encoding specified in the server response.
`java.lang.String` `getContentCharset()` Returns the content charset for this response, even if no charset was specified explicitly.
`java.lang.String` `getContentCharSet()` Deprecated. As of 2.6, please use @link `getContentCharset()`
`java.lang.String` `getContentCharsetOrNull()` Returns the content charset specified explicitly in the header or in the content, or `null` if none was specified.
`java.lang.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.
`HttpMethod` `getRequestMethod()` Deprecated. As of 2.6, please use `getRequestSettings()`.getHttpMethod()
`WebRequestSettings` `getRequestSettings()` Returns the request settings used to load this response.
`java.net.URL` `getRequestUrl()` Deprecated. As of 2.6, please use `getRequestSettings()`.getUrl()
`java.util.List<org.apache.commons.httpclient.NameValuePair>` `getResponseHeaders()` Returns the response headers as a list of `NameValuePair`s.
`java.lang.String` `getResponseHeaderValue(java.lang.String headerName)` Returns the value of the specified response header.
`int` `getStatusCode()` Returns the status code that was returned by the server.
`java.lang.String` `getStatusMessage()` Returns the status message that was returned from the server.
`java.net.URL` `getUrl()` Synonym for `WebResponse.getRequestUrl()`

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 java.lang.IllegalArgumentException

  Constructs a WebResponse object wrapping provided WebResponse.

  Parameters:
    `webResponse` - the webResponse that does the real work
  Throws:
    `java.lang.IllegalArgumentException` - if the connection is `null`

Method Detail

### getContentAsStream

    public java.io.InputStream getContentAsStream()
                                           throws java.io.IOException

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

  Specified by:
    `getContentAsStream` in interface `WebResponse`
  Returns:
    the response content as an input stream
  Throws:
    `java.io.IOException` - if an IO problem occurs

### getContentAsString

    public java.lang.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 connection object.

  Specified by:
    `getContentAsString` in interface `WebResponse`
  Returns:
    the response content as a string, using the charset/encoding specified in the server response

### getContentAsString

    public java.lang.String getContentAsString(java.lang.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 connection object.

  Specified by:
    `getContentAsString` in interface `WebResponse`
  Parameters:
    `encoding` - the charset/encoding to use to convert the response content into a string
  Returns:
    the response content as a string

### getContentAsBytes

    public byte[] getContentAsBytes()

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

  Specified by:
    `getContentAsBytes` in interface `WebResponse`
  Returns:
    the response content as a byte array

### getContentCharSet

    @Deprecated
    public java.lang.String getContentCharSet()

  Deprecated. As of 2.6, please use @link `getContentCharset()`

  Returns the content charset; may be `null`. The default behavior of this method is to return getContentCharSet() on the wrapped connection object.

  Specified by:
    `getContentCharSet` in interface `WebResponse`
  Returns:
    the content charset

### getContentCharsetOrNull

    public java.lang.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 connection object.

  Specified by:
    `getContentCharsetOrNull` in interface `WebResponse`
  Returns:
    the content charset specified explicitly in the header or in the content, or `null` if none was specified

### getContentCharset

    public java.lang.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 connection object.

  Specified by:
    `getContentCharset` in interface `WebResponse`
  Returns:
    the content charset for this response

### getContentType

    public java.lang.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 connection object.

  Specified by:
    `getContentType` in interface `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 connection object.

  Specified by:
    `getLoadTime` in interface `WebResponse`
  Returns:
    the time it took to load this web response, in milliseconds

### getRequestMethod

    @Deprecated
    public HttpMethod getRequestMethod()

  Deprecated. As of 2.6, please use `getRequestSettings()`.getHttpMethod()

  Returns the method used for the request resulting in this response. The default behavior of this method is to return getRequestMethod() on the wrapped connection object.

  Specified by:
    `getRequestMethod` in interface `WebResponse`
  Returns:
    the method used for the request resulting in this response

### getResponseHeaders

    public java.util.List<org.apache.commons.httpclient.NameValuePair> getResponseHeaders()

  Returns the response headers as a list of `NameValuePair`s. The default behavior of this method is to return getResponseHeaders() on the wrapped connection object.

  Specified by:
    `getResponseHeaders` in interface `WebResponse`
  Returns:
    the response headers as a list of `NameValuePair`s

### getResponseHeaderValue

    public java.lang.String getResponseHeaderValue(java.lang.String headerName)

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

  Specified by:
    `getResponseHeaderValue` in interface `WebResponse`
  Parameters:
    `headerName` - the name of the header whose value is to be returned
  Returns:
    the value of the specified response header

### 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 connection object.

  Specified by:
    `getStatusCode` in interface `WebResponse`
  Returns:
    the status code that was returned by the server

### getStatusMessage

    public java.lang.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 connection object.

  Specified by:
    `getStatusMessage` in interface `WebResponse`
  Returns:
    the status message that was returned from the server

### getRequestUrl

    @Deprecated
    public java.net.URL getRequestUrl()

  Deprecated. As of 2.6, please use `getRequestSettings()`.getUrl()

  Returns the URL that was used to load this page. The default behavior of this method is to return getRequestUrl() on the wrapped connection object.

  Specified by:
    `getRequestUrl` in interface `WebResponse`
  Returns:
    the URL that was used to load this page

### getUrl

    public java.net.URL getUrl()

  Description copied from interface: `WebResponse`
  Synonym for `WebResponse.getRequestUrl()`

  Specified by:
    `getUrl` in interface `WebResponse`

### getRequestSettings

    public WebRequestSettings getRequestSettings()

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

  Specified by:
    `getRequestSettings` in interface `WebResponse`
  Returns:
    the request settings used to load this response

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