|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--HTTPClient.HTTPResponse
This defines the http-response class returned by the requests. It's basically a wrapper around the Response class which first lets all the modules handle the response before finally giving the info to the user.
Fields inherited from interface HTTPClient.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 |
Method Summary | |
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. |
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. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Method Detail |
public final int getStatusCode() throws IOException, ModuleException
public final String getReasonLine() throws IOException, ModuleException
public final String getVersion() throws IOException, ModuleException
public final String getServer() throws IOException, ModuleException
getHeader("Server")
instead.
getHeader(java.lang.String)
public final URI getOriginalURI()
public final URL getEffectiveURL() throws IOException, ModuleException
getEffectiveURI()
public final URI getEffectiveURI() throws IOException, ModuleException
public String getHeader(String hdr) throws IOException, ModuleException
hdr
- the header name.public int getHeaderAsInt(String hdr) throws IOException, ModuleException, NumberFormatException
hdr
- the header name.public Date getHeaderAsDate(String hdr) throws IOException, IllegalArgumentException, ModuleException
hdr
- the header name.public Enumeration listHeaders() throws IOException, ModuleException
public String getTrailer(String trailer) throws IOException, ModuleException
getData()
to force the data to be read.trailer
- the trailer name.getData()
public int getTrailerAsInt(String trailer) throws IOException, ModuleException, NumberFormatException
trailer
- the tailer name.public Date getTrailerAsDate(String trailer) throws IOException, IllegalArgumentException, ModuleException
trailer
- the trailer name.public Enumeration listTrailers() throws IOException, ModuleException
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.
getInputStream()
public String getText() throws IOException, ModuleException, ParseException
getData()
, the caveats of that method apply here as well.getData()
public InputStream getInputStream() throws IOException, ModuleException
getData()
had been previously invoked it will
actually return a ByteArrayInputStream created from that data.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).
public String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |