All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class HTTPClient.Response

java.lang.Object
   |
   +----HTTPClient.Response

public final class Response
extends Object
implements RoResponse, GlobalConstants
This class represents an intermediate response. It's used internally by the modules. When all modules have handled the response then the HTTPResponse fills in its fields with the data from this class.

Version:
0.3-2 18/06/1999
Author:
Ronald Tschalär

Variable Index

 o inp_stream
our input stream (usually from the stream demux).

Constructor Index

 o Response(String, int, String, NVPair[], byte[], InputStream, int)
Create a new response with the given info.

Method Index

 o deleteHeader(String)
Removes a header field from the list of headers.
 o deleteTrailer(String)
Removes a trailer field from the list of trailers.
 o getData()
Reads all the response data into a byte array.
 o getEffectiveURI()
get the final URI of the document.
 o getEffectiveURL()
get the final URL of the document. Deprecated.
 o getHeader(String)
retrieves the field for a given header.
 o getHeaderAsDate(String)
retrieves the field for a given header.
 o getHeaderAsInt(String)
retrieves the field for a given header.
 o getInputStream()
Gets an input stream from which the returned data can be read.
 o getReasonLine()
give the reason line associated with the status code.
 o getStatusCode()
give the status code for this request.
 o getTrailer(String)
Retrieves the field for a given trailer.
 o getTrailerAsDate(String)
Retrieves the field for a given trailer.
 o getTrailerAsInt(String)
Retrieves the field for a given tailer.
 o getVersion()
get the HTTP version used for the response.
 o hasEntity()
Some responses such as those from a HEAD or with certain status codes don't have an entity.
 o setEffectiveURI(URI)
set the final URI of the document.
 o setEffectiveURL(URL)
set the final URL of the document. Deprecated.
 o setHeader(String, String)
Set a header field in the list of headers.
 o setTrailer(String, String)
Set a trailer field in the list of trailers.

Variables

 o inp_stream
 public InputStream inp_stream
our input stream (usually from the stream demux). Push input streams onto this if necessary.

Constructors

 o Response
 public Response(String version,
                 int status,
                 String reason,
                 NVPair headers[],
                 byte data[],
                 InputStream is,
                 int cont_len)
Create a new response with the given info. This is used when creating a response in a requestHandler().

If data is not null then that is used; else if the is is not null that is used; else the entity is empty. If the input stream is used then cont_len specifies the length of the data that can be read from it, or -1 if unknown.

Parameters:
version - the response version (such as "HTTP/1.1")
status - the status code
reason - the reason line
headers - the response headers
data - the response entity
is - the response entity as an InputStream
cont_len - the length of the data in the InputStream

Methods

 o getStatusCode
 public final int getStatusCode() throws IOException
give the status code for this request. These are grouped as follows:

Throws: IOException
If any exception occurs on the socket.
 o getReasonLine
 public final String getReasonLine() throws IOException
give the reason line associated with the status code.

Throws: IOException
If any exception occurs on the socket.
 o getVersion
 public final String getVersion() throws IOException
get the HTTP version used for the response.

Throws: IOException
If any exception occurs on the socket.
 o getEffectiveURI
 public final URI getEffectiveURI() throws IOException
get the final URI of the document. This is set if the original request was deferred via the "moved" (301, 302, or 303) return status.

Returns:
the new URI, or null if not redirected
Throws: IOException
If any exception occurs on the socket.
 o setEffectiveURI
 public void setEffectiveURI(URI final_uri)
set the final URI of the document. This is only for internal use.

 o getEffectiveURL
 public final URL getEffectiveURL() throws IOException
Note: getEffectiveURL() is deprecated. use getEffectiveURI() instead

get the final URL of the document. This is set if the original request was deferred via the "moved" (301, 302, or 303) return status.

Throws: IOException
If any exception occurs on the socket.
See Also:
getEffectiveURI
 o setEffectiveURL
 public void setEffectiveURL(URL final_url)
Note: setEffectiveURL() is deprecated. use setEffectiveURI() instead

set the final URL of the document. This is only for internal use.

See Also:
setEffectiveURI
 o getHeader
 public String getHeader(String hdr) throws IOException
retrieves the field for a given header.

Parameters:
hdr - the header name.
Returns:
the value for the header, or null if non-existent.
Throws: IOException
If any exception occurs on the socket.
 o getHeaderAsInt
 public int getHeaderAsInt(String hdr) throws IOException, NumberFormatException
retrieves the field for a given header. The value is parsed as an int.

Parameters:
hdr - the header name.
Returns:
the value for the header if the header exists
Throws: NumberFormatException
if the header's value is not a number or if the header does not exist.
Throws: IOException
if any exception occurs on the socket.
 o getHeaderAsDate
 public Date getHeaderAsDate(String hdr) throws IOException, IllegalArgumentException
retrieves the field for a given header. The value is parsed as a date; if this fails it is parsed as a long representing the number of seconds since 12:00 AM, Jan 1st, 1970. If this also fails an IllegalArgumentException is thrown.

Note: When sending dates use Util.httpDate().

Parameters:
hdr - the header name.
Returns:
the value for the header, or null if non-existent.
Throws: IOException
If any exception occurs on the socket.
Throws: IllegalArgumentException
If the header cannot be parsed as a date or time.
 o setHeader
 public void setHeader(String header,
                       String value)
Set a header field in the list of headers. If the header already exists it will be overwritten; otherwise the header will be added to the list. This is used by some modules when they process the header so that higher level stuff doesn't get confused when the headers and data don't match.

Parameters:
header - The name of header field to set.
value - The value to set the field to.
 o deleteHeader
 public void deleteHeader(String header)
Removes a header field from the list of headers. This is used by some modules when they process the header so that higher level stuff doesn't get confused when the headers and data don't match.

Parameters:
header - The name of header field to remove.
 o getTrailer
 public String getTrailer(String trailer) throws IOException
Retrieves the field for a given trailer. Note that this should not be invoked until all the response data has been read. If invoked before, it will force the data to be read via getData().

Parameters:
trailer - the trailer name.
Returns:
the value for the trailer, or null if non-existent.
Throws: IOException
If any exception occurs on the socket.
 o getTrailerAsInt
 public int getTrailerAsInt(String trailer) throws IOException, NumberFormatException
Retrieves the field for a given tailer. The value is parsed as an int.

Parameters:
trailer - the tailer name.
Returns:
the value for the trailer if the trailer exists
Throws: NumberFormatException
if the trailer's value is not a number or if the trailer does not exist.
Throws: IOException
if any exception occurs on the socket.
 o getTrailerAsDate
 public Date getTrailerAsDate(String trailer) throws IOException, IllegalArgumentException
Retrieves the field for a given trailer. The value is parsed as a date; if this fails it is parsed as a long representing the number of seconds since 12:00 AM, Jan 1st, 1970. If this also fails an IllegalArgumentException is thrown.

Note: When sending dates use Util.httpDate().

Parameters:
trailer - the trailer name.
Returns:
the value for the trailer, or null if non-existent.
Throws: IllegalArgumentException
if the trailer's value is neither a legal date nor a number.
Throws: IOException
if any exception occurs on the socket.
Throws: IllegalArgumentException
If the header cannot be parsed as a date or time.
 o setTrailer
 public void setTrailer(String trailer,
                        String value)
Set a trailer field in the list of trailers. If the trailer already exists it will be overwritten; otherwise the trailer will be added to the list. This is used by some modules when they process the trailer so that higher level stuff doesn't get confused when the trailer and data don't match.

Parameters:
trailer - The name of trailer field to set.
value - The value to set the field to.
 o deleteTrailer
 public void deleteTrailer(String trailer)
Removes a trailer field from the list of trailers. This is used by some modules when they process the trailer so that higher level stuff doesn't get confused when the trailers and data don't match.

Parameters:
trailer - The name of trailer field to remove.
 o getData
 public synchronized byte[] getData() throws IOException
Reads all the response data into a byte array. Note that this method won't return until all the data has been received (so for instance don't invoke this method if the server is doing a server push). If getInputStream() had been previously called then this method only returns any unread data remaining on the stream and then closes it.

Returns:
an array containing the data (body) returned. If no data was returned then it's set to a zero-length array.
Throws: IOException
If any io exception occured while reading the data
See Also:
getInputStream
 o getInputStream
 public synchronized InputStream getInputStream() throws IOException
Gets an input stream from which the returned data can be read. Note that if getData() had been previously called it will actually return a ByteArrayInputStream created from that data.

Returns:
the InputStream.
Throws: IOException
If any exception occurs on the socket.
See Also:
getData
 o hasEntity
 public synchronized boolean hasEntity() throws IOException
Some responses such as those from a HEAD or with certain status codes don't have an entity. This is detected by the client and can be queried here. Note that this won't try to do a read() on the input stream (it will however cause the headers to be read and parsed if not already done).

Returns:
true if the response has an entity, false otherwise

All Packages  Class Hierarchy  This Package  Previous  Next  Index