|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectHTTPClient.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.
| Field Summary | |
(package private) Response |
response
the current response |
| 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 |
| Constructor Summary | |
(package private) |
HTTPResponse(HTTPClientModule[] modules,
int timeout,
Request orig)
Creates a new HTTPResponse. |
| 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. |
(package private) HTTPClientModule[] |
getModules()
|
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. |
(package private) int |
getTimeout()
|
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. |
(package private) boolean |
handleResponse()
Processes a Response. |
(package private) void |
init(Response resp)
Copies the relevant fields from Response and marks this as initialized. |
(package private) void |
invokeTrailerHandlers(boolean force)
This is invoked by the RespInputStream when it is close()'d. |
Enumeration |
listHeaders()
Returns an enumeration of all the headers available via getHeader(). |
Enumeration |
listTrailers()
Returns an enumeration of all the trailers available via getTrailer(). |
(package private) void |
markAborted()
Mark this request as having been aborted. |
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. |
(package private) void |
set(Request req,
HttpOutputStream out_stream)
|
(package private) void |
set(Request req,
Response resp)
|
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 |
| Field Detail |
Response response
| Constructor Detail |
HTTPResponse(HTTPClientModule[] modules,
int timeout,
Request orig)
modules - the list of modules handling this responsetimeout - the timeout to be used on stream read()'s| Method Detail |
void set(Request req,
Response resp)
req - the requestresp - the response
void set(Request req,
HttpOutputStream out_stream)
req - the request
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 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 data
ModuleException - 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 text
ModuleException - 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.public String toString()
HTTPClientModule[] getModules()
boolean handleResponse()
throws IOException,
ModuleException
IOException - if any handler throws an IOException.
ModuleException - if any module encounters an exception.void init(Response resp)
resp - the Response class to copy from
void invokeTrailerHandlers(boolean force)
throws IOException,
ModuleException
force - invoke the handlers even if not initialized yet?
IOException - if thrown by any module
ModuleException - if thrown by any modulevoid markAborted()
int getTimeout()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||