I'm using the Apache HTTP commons DefaultHttpClient
and after construction, I'm setting its retry handler:
httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
@Override
public boolean retryRequest(final IOException ioe,
final int numRetry, final HttpContext context)
{
Log.d(TAG, "retry handler received exception of type: " + ioe.getClass().getName() + ", num retries: " + numRetry);
if (numRetry > 4) { // 3 retries
return false;
}
// Some exceptions we can retry without knowledge of which methods are being invoked
if (ioe instanceof NoHttpResponseException
|| ioe instanceof UnknownHostException
|| ioe instanceof SocketException) {
}
return false;
}
});
The server that I am sending my requests to frequently times out, and in the catch
of my execute() call, I receive an IO error, "The operation timed out" however I never see any the "retry handler received exception of type" log statement in my console output. All of my requests are POST requests, but they are idempotent--they're safe to call multiple times without adverse side-effects.
Am I setting up the retry handler incorrectly? Is the retry handler only invoked in certain scenarios?
Return true if you handled an exceptional case in your handler.
That should keep the exception from beeing thrown.
Also you could handle the Timeout exception in your handler as well.
httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
@Override
public boolean retryRequest(final IOException ioe,
final int numRetry, final HttpContext context)
{
Log.d(TAG, "retry handler received exception of type: " + ioe.getClass().getName() + ", num retries: " + numRetry);
if (numRetry > 4) { // 3 retries
return false;
}
// Some exceptions we can retry without knowledge of which methods are being invoked
if (ioe instanceof NoHttpResponseException
|| ioe instanceof UnknownHostException
|| ioe instanceof SocketException
// Replace with the actual type of the exception
|| ioe instanceof TimeoutException) {
return true;
}
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With