|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.noderunner.http.RetryHttpClient
public class RetryHttpClient
A HttpClient implementation that retries contacting a remote URL and
allows for persistant connections. For each retry, this client waits an
additional second before attempting a new connection. Note that if a
failure occurs reading the server response, retries may or may not be made
only for non-POST and PUT methods. Refer to
readResponse on this is handled.
Also, this client handles most redirects, on either the same host or
different host. By default, note that redirects will only be followed for
non-POST and PUT methods.
Refer to setFollowRedirects on this.
HTTPS (HTTP over SSL) relies on the javax.net.ssl library, and
may require com.sun.net.ssl.internal.ssl.Provider to be
installed using the java.security.Security.addProvider method.
Many of the protected methods may be overriden
to supply specific functionality. For example, by default
the underlying HttpClient is the BasicHttpClient,
this can be easily changed.
| Field Summary | |
|---|---|
static int |
DEFAULT_MAX_TRIES
Default number of tries. |
| Constructor Summary | |
|---|---|
RetryHttpClient(java.net.URL url)
Constructs a RetryHttpClient that retries 3 times. |
|
RetryHttpClient(java.net.URL url,
int maxTries)
Constructs a RetryHttpClient that retries a number of times. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the wrapped HttpClient. |
java.io.OutputStream |
getOutputStream()
Returns a stream for writing data to, if data is to be sent to the server. |
protected HttpClient |
makeHttpClient(java.net.URL url)
Returns a newly constructed HTTP client for a given URL. |
protected java.net.Socket |
makeSocket(java.net.URL url)
Returns a newly constructed socket for a given URL. |
protected java.net.Socket |
makeSSLSocket(java.net.URL url)
Returns a newly constructed SSL socket for a given URL. |
ClientResponse |
readResponse()
Reads the response data from the HTTP server. |
protected void |
retrySendRequest(java.io.IOException e,
int failures)
Callback that indicates the connection failed and will be retried. |
void |
setFollowRedirects(boolean followRedirects)
Sets whether HTTP redirects should be followed. |
void |
setSkipContinues(boolean skipContinues)
Sets whether HTTP continue responses should be skipped. |
protected void |
setSocketOptions(java.net.Socket socket)
Sets the socket options to use. |
java.lang.String |
toString()
Returns debug information. |
void |
writeRequest(ClientRequest request)
Attempts to send an HTTP request, and may retry to send a certain number of times. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_MAX_TRIES
| Constructor Detail |
|---|
public RetryHttpClient(java.net.URL url,
int maxTries)
RetryHttpClient that retries a number of times.
maxTries - must be greater than zeropublic RetryHttpClient(java.net.URL url)
RetryHttpClient that retries 3 times.
| Method Detail |
|---|
protected void retrySendRequest(java.io.IOException e,
int failures)
failures - number of failures (counting from 0)
protected java.net.Socket makeSocket(java.net.URL url)
throws java.io.IOException
java.io.IOException
protected java.net.Socket makeSSLSocket(java.net.URL url)
throws java.io.IOException
java.io.IOException
protected void setSocketOptions(java.net.Socket socket)
throws java.io.IOException
java.io.IOException
protected HttpClient makeHttpClient(java.net.URL url)
throws java.io.IOException
makeSocket(java.net.URL) to construct a network socket
for HTTP, makeSSLSocket(java.net.URL) for HTTPS.
Calls setSocketOptions(java.net.Socket) to set socket options.
java.io.IOException
public void writeRequest(ClientRequest request)
throws java.io.IOException
makeHttpClient(java.net.URL) to construct a new client.
writeRequest in interface HttpClientjava.io.IOExceptionpublic java.io.OutputStream getOutputStream()
getOutputStream in interface HttpClient
public ClientResponse readResponse()
throws java.io.IOException
If the response data cannot be read, then the connection will be
closed, and writeRequest will be called
up to the maximum of retries as previously set.
The original request will not retried if the request method was
PUT or POST and ClientRequest.getDataPoster() returns null.
If a redirection response was read, it is followed only if redirection is enabled.
readResponse in interface HttpClientHttpException - if the server returned an invalid HTTP
response
java.io.IOException
public void close()
throws java.io.IOException
HttpClient.
The underlying client may not be re-used.
close in interface HttpClientjava.io.IOExceptionpublic void setFollowRedirects(boolean followRedirects)
public void setSkipContinues(boolean skipContinues)
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||