public class HTTPResponse extends Object implements HTTPClientModuleConstants
REQ_CONTINUE, REQ_NEWCON_RST, REQ_NEWCON_SND, REQ_RESPONSE, REQ_RESTART, REQ_RETURN, REQ_SHORTCIRC, RSP_CONTINUE, RSP_NEWCON_REQ, RSP_NEWCON_SND, RSP_REQUEST, RSP_RESTART, RSP_SEND, RSP_SHORTCIRC
Modifier and Type | Method and Description |
---|---|
byte[] |
getData()
Reads all the response data into a byte array.
|
URI |
getEffectiveURI()
Get the final URI of the document.
|
URL |
getEffectiveURL()
Deprecated.
use getEffectiveURI() instead
|
String |
getHeader(String hdr)
Retrieves the value for a given header.
|
Date |
getHeaderAsDate(String hdr)
Retrieves the value for a given header.
|
int |
getHeaderAsInt(String hdr)
Retrieves the value for a given header.
|
InputStream |
getInputStream()
Gets an input stream from which the returned data can be read.
|
URI |
getOriginalURI()
Get the original URI used in the request.
|
String |
getReasonLine()
Give the reason line associated with the status code.
|
String |
getServer()
Deprecated.
This method is a remnant of V0.1; use
getHeader("Server") instead. |
int |
getStatusCode()
Give the status code for this request.
|
String |
getText()
Reads all the response data into a buffer and turns it into a string
using the appropriate character converter.
|
long |
getTimeToFirstByte()
++GRINDER MODIFICATION
|
String |
getTrailer(String trailer)
Retrieves the value for a given trailer.
|
Date |
getTrailerAsDate(String trailer)
Retrieves the value for a given trailer.
|
int |
getTrailerAsInt(String trailer)
Retrieves the value for a given tailer.
|
String |
getVersion()
Get the HTTP version used for the response.
|
Enumeration |
listHeaders()
Returns an enumeration of all the headers available via getHeader().
|
Enumeration |
listTrailers()
Returns an enumeration of all the trailers available via getTrailer().
|
boolean |
retryRequest()
Should the request be retried by the application? If the application
used an HttpOutputStream in the request then various
modules (such as the redirection and authorization modules) are not
able to resend the request themselves.
|
String |
toString()
produces a full list of headers and their values, one per line.
|
public final int getStatusCode() throws IOException, ModuleException
IOException
- if any exception occurs on the socket.ModuleException
- if any module encounters an exception.public final String getReasonLine() throws IOException, ModuleException
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.public final String getVersion() throws IOException, ModuleException
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.public final String getServer() throws IOException, ModuleException
getHeader("Server")
instead.IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.getHeader(java.lang.String)
public final URI getOriginalURI()
public final URL getEffectiveURL() throws IOException, ModuleException
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.getEffectiveURI()
public final URI getEffectiveURI() throws IOException, ModuleException
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.public String getHeader(String hdr) throws IOException, ModuleException
hdr
- the header name.IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.public int getHeaderAsInt(String hdr) throws IOException, ModuleException, NumberFormatException
hdr
- the header name.NumberFormatException
- if the header's value is not a number
or if the header does not exist.IOException
- if any exception occurs on the socket.ModuleException
- if any module encounters an exception.public Date getHeaderAsDate(String hdr) throws IOException, IllegalArgumentException, ModuleException
hdr
- the header name.IllegalArgumentException
- if the header's value is neither a
legal date nor a number.IOException
- if any exception occurs on the socket.ModuleException
- if any module encounters an exception.public Enumeration listHeaders() throws IOException, ModuleException
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.public long getTimeToFirstByte()
public String getTrailer(String trailer) throws IOException, ModuleException
getData()
to force the data to be read.trailer
- the trailer name.IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.getData()
public int getTrailerAsInt(String trailer) throws IOException, ModuleException, NumberFormatException
trailer
- the tailer name.NumberFormatException
- if the trailer's value is not a number
or if the trailer does not exist.IOException
- if any exception occurs on the socket.ModuleException
- if any module encounters an exception.public Date getTrailerAsDate(String trailer) throws IOException, IllegalArgumentException, ModuleException
trailer
- the trailer name.IllegalArgumentException
- if the trailer's value is neither a
legal date nor a number.IOException
- if any exception occurs on the socket.ModuleException
- if any module encounters an exception.public Enumeration listTrailers() throws IOException, ModuleException
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.public byte[] getData() throws IOException, ModuleException
getInputStream()
had been previously invoked
then this method only returns any unread data remaining on the stream
and then closes it.
Note to the unwary: code like
System.out.println("The data: " + resp.getData())will probably not do what you want - use
System.out.println("The data: " + resp.getText())instead.
IOException
- If any io exception occured while reading
the dataModuleException
- if any module encounters an exception.getInputStream()
public String getText() throws IOException, ModuleException, ParseException
getData()
, the caveats of that method apply here as well.IOException
- If any io exception occured while reading
the data, or if the content is not textModuleException
- if any module encounters an exception.ParseException
- if an error occured trying to parse the
content-type header fieldgetData()
public InputStream getInputStream() throws IOException, ModuleException
getData()
had been previously invoked it will
actually return a ByteArrayInputStream created from that data.IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.getData()
public boolean retryRequest() throws IOException, ModuleException
If the application resends the request then it must use the same HttpOutputStream instance. This is because the modules use this to recognize the retried request and to perform the necessary work on the request before it's sent.
Here is a skeleton example of usage:
OutputStream out = new HttpOutputStream(1234); do { rsp = con.Post("/cgi-bin/my_cgi", out); out.write(...); out.close(); } while (rsp.retryRequest()); if (rsp.getStatusCode() >= 300) ...
Note that for this to ever return true, the java system property HTTPClient.deferStreamed must be set to true at the beginning of the application (before the HTTPConnection class is loaded). This prevents unwary applications from causing inadvertent memory leaks. If an application does set this, then it must resend any request whose response returns true here in order to prevent memory leaks (a switch to JDK 1.2 will allow us to use weak references and eliminate this problem).
IOException
- If any exception occurs on the socket.ModuleException
- if any module encounters an exception.Copyright © 2000-2014. All Rights Reserved.