com.gargoylesoftware.htmlunit
Class WebResponseImpl

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.WebResponseImpl
All Implemented Interfaces:
WebResponse, Serializable
Direct Known Subclasses:
StringWebResponse

public class WebResponseImpl
extends Object
implements WebResponse, Serializable

Simple base class for WebResponse.

Version:
$Revision: 2132 $
Author:
Brad Clarke, Ahmed Ashour
See Also:
Serialized Form

Constructor Summary
WebResponseImpl(WebResponseData responseData, String charset, URL url, SubmitMethod requestMethod, long loadTime)
          Construct with all data
WebResponseImpl(WebResponseData responseData, URL url, SubmitMethod requestMethod, long loadTime)
          Construct with all data
 
Method Summary
 InputStream getContentAsStream()
          Return the content from the server as an input stream
 String getContentAsString()
          Return the content from the server as a string
 String getContentCharSet()
          Return the content charset value. If no charset is specified in headers, then try to guess it from the content.
 String getContentType()
          Return the content type returned from the server.
 long getLoadTimeInMilliSeconds()
          Return the time it took to load this web response in milliseconds.
 SubmitMethod getRequestMethod()
          Return the method used for the request resulting into this response.
 byte[] getResponseBody()
          Return the response body as byte array.
 List getResponseHeaders()
          Return the response headers as a List of NameValuePairs.
 String getResponseHeaderValue(String headerName)
          Return the value of the specified header from this response.
 int getStatusCode()
          Return the status code that was returned by the server
 String getStatusMessage()
          Return the status message that was returned from the server
 URL getUrl()
          Return the URL that was used to load this page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebResponseImpl

public WebResponseImpl(WebResponseData responseData,
                       URL url,
                       SubmitMethod requestMethod,
                       long loadTime)
Construct with all data

Parameters:
responseData - Data that was send back
url - Where this response came from
requestMethod - The method used to get this response
loadTime - How long the response took to be sent

WebResponseImpl

public WebResponseImpl(WebResponseData responseData,
                       String charset,
                       URL url,
                       SubmitMethod requestMethod,
                       long loadTime)
Construct with all data

Parameters:
responseData - Data that was send back
charset - Charset used if not returned in the response.
url - Where this response came from
requestMethod - The method used to get this response
loadTime - How long the response took to be sent
Method Detail

getStatusCode

public int getStatusCode()
Return the status code that was returned by the server

Specified by:
getStatusCode in interface WebResponse
Returns:
See above.

getStatusMessage

public String getStatusMessage()
Return the status message that was returned from the server

Specified by:
getStatusMessage in interface WebResponse
Returns:
See above

getContentType

public String getContentType()
Return the content type returned from the server. Ie "text/html"

Specified by:
getContentType in interface WebResponse
Returns:
See above

getContentAsString

public String getContentAsString()
Return the content from the server as a string

Specified by:
getContentAsString in interface WebResponse
Returns:
See above

getContentAsStream

public InputStream getContentAsStream()
                               throws IOException
Return the content from the server as an input stream

Specified by:
getContentAsStream in interface WebResponse
Returns:
See above
Throws:
IOException - If an IO problem occurs

getUrl

public URL getUrl()
Return the URL that was used to load this page.

Specified by:
getUrl in interface WebResponse
Returns:
The originating URL

getRequestMethod

public SubmitMethod getRequestMethod()
Return the method used for the request resulting into this response.

Specified by:
getRequestMethod in interface WebResponse
Returns:
the method

getResponseHeaders

public List getResponseHeaders()
Return the response headers as a List of NameValuePairs.

Specified by:
getResponseHeaders in interface WebResponse
Returns:
a List of NameValuePairs.

getResponseHeaderValue

public String getResponseHeaderValue(String headerName)
Return the value of the specified header from this response.

Specified by:
getResponseHeaderValue in interface WebResponse
Parameters:
headerName - The name of the header
Returns:
The value of the specified header

getLoadTimeInMilliSeconds

public long getLoadTimeInMilliSeconds()
Return the time it took to load this web response in milliseconds.

Specified by:
getLoadTimeInMilliSeconds in interface WebResponse
Returns:
The load time.

getContentCharSet

public String getContentCharSet()
Return the content charset value. If no charset is specified in headers, then try to guess it from the content. Currently only UTF-8 with BOM marker is detected this way.

Specified by:
getContentCharSet in interface WebResponse
Returns:
the charset, TextUtil.DEFAULT_CHARSET if it can't be determined
See Also:
Wikipedia - Byte Order Mark

getResponseBody

public byte[] getResponseBody()
Return the response body as byte array.

Specified by:
getResponseBody in interface WebResponse
Returns:
response body.


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