com.sun.slamd.http
Class HTTPResponse

java.lang.Object
  extended by com.sun.slamd.http.HTTPResponse

public class HTTPResponse
extends java.lang.Object

This class defines a means of encapsulating an HTTP response returned by a server in response to an HTTP request.

Author:
Neil A. Wilson

Constructor Summary
HTTPResponse(java.net.URL requestURL, int statusCode, java.lang.String protocolVersion, java.lang.String responseMessage)
          Creates a new HTTP response with the provided status code.
 
Method Summary
 void addHeader(java.lang.String headerName, java.lang.String headerValue)
          Adds a header with the given name and value to this response.
 int getContentLength()
          Retrieves the content length associated with this response.
 java.lang.String getContentType()
          Retrieves the content type associated with this response.
 java.lang.String[] getCookieValues()
          Retrieves an array containing the values of the cookies that should be set based on the information in this response.
 java.lang.String getHeader(java.lang.String headerName)
          Retrieves the value of the header with the specified name.
 java.lang.String[][] getHeaderElements()
          Retrieves a two-dimensional array containing the header data for this response, with each element being an array containing a name/value pair.
 java.lang.String[] getHeaderValues(java.lang.String headerName)
          Retrieves the set of values for the specified header.
 HTMLDocument getHTMLDocument()
          Retrieves the HTML document associated with this response.
 java.lang.String getProtocolVersion()
          Retrieves the protocol version for this HTTP response.
 java.net.URL getRequestURL()
          Retrieves the URL of the request that generated this HTTP response.
 byte[] getResponseData()
          Retrieves the raw data included in this HTTP response.
 java.lang.String getResponseMessage()
          Retrieves the response message for this HTTP response.
 int getStatusCode()
          Retrieves the status code for this HTTP response.
 void parseAsHTMLDocument(java.net.URL requestURL)
          Parses the data associated with this response as an HTML document.
 void setResponseData(byte[] responseData)
          Sets the actual data associated with this response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPResponse

public HTTPResponse(java.net.URL requestURL,
                    int statusCode,
                    java.lang.String protocolVersion,
                    java.lang.String responseMessage)
Creates a new HTTP response with the provided status code.

Parameters:
requestURL - The URL of the request that generated this response.
statusCode - The HTTP status code for this response.
protocolVersion - The protocol and version for this response.
responseMessage - The message associated with this response.
Method Detail

getRequestURL

public java.net.URL getRequestURL()
Retrieves the URL of the request that generated this HTTP response.

Returns:
The URL of the request that generated this HTTP response.

getStatusCode

public int getStatusCode()
Retrieves the status code for this HTTP response.

Returns:
The status code for this HTTP response.

getProtocolVersion

public java.lang.String getProtocolVersion()
Retrieves the protocol version for this HTTP response.

Returns:
The protocol version for this HTTP response.

getResponseMessage

public java.lang.String getResponseMessage()
Retrieves the response message for this HTTP response.

Returns:
The response message for this HTTP response.

getHeader

public java.lang.String getHeader(java.lang.String headerName)
Retrieves the value of the header with the specified name. If the specified header has more than one value, then only the first will be retrieved.

Parameters:
headerName - The name of the header to retrieve.
Returns:
The value of the header with the specified name, or null if no such header is available.

getHeaderValues

public java.lang.String[] getHeaderValues(java.lang.String headerName)
Retrieves the set of values for the specified header.

Parameters:
headerName - The name of the header to retrieve.
Returns:
The set of values for the specified header.

addHeader

public void addHeader(java.lang.String headerName,
                      java.lang.String headerValue)
Adds a header with the given name and value to this response.

Parameters:
headerName - The name of the header to add to this response.
headerValue - The value of the header to add to this response.

getHeaderElements

public java.lang.String[][] getHeaderElements()
Retrieves a two-dimensional array containing the header data for this response, with each element being an array containing a name/value pair.

Returns:
A two-dimensional array containing the header data for this response.

getResponseData

public byte[] getResponseData()
Retrieves the raw data included in this HTTP response. If the response did not include any data, an empty array will be returned.

Returns:
The raw data included in this HTTP response.

setResponseData

public void setResponseData(byte[] responseData)
                     throws java.io.IOException
Sets the actual data associated with this response.

Parameters:
responseData - The actual data associated with this response.
Throws:
java.io.IOException - If the data is GZIP-compressed and a problem occurs during decompression.

getContentLength

public int getContentLength()
Retrieves the content length associated with this response.

Returns:
The content length associated with this response, or -1 if no content length is available.

getContentType

public java.lang.String getContentType()
Retrieves the content type associated with this response.

Returns:
The content type associated with this response, or null if no content type is available.

getCookieValues

public java.lang.String[] getCookieValues()
Retrieves an array containing the values of the cookies that should be set based on the information in this response.

Returns:
An array containing the values of the cookies that should be set based on the information in this response.

getHTMLDocument

public HTMLDocument getHTMLDocument()
Retrieves the HTML document associated with this response.

Returns:
The HTML document associated with this response, or null if no HTML document is available.

parseAsHTMLDocument

public void parseAsHTMLDocument(java.net.URL requestURL)
Parses the data associated with this response as an HTML document.

Parameters:
requestURL - The URL of the request that triggered this response.