Apache HttpClient HttpRequestRetryHandler is never called

I use the Apache HTTP community DefaultHttpClientand, after building, I install 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 to which I send my requests for a frequent timeout, and in catchmy call to execute (), I get an I / O error "Operation timeout", however I never see the "retry handler" received exception like "log expression in my console release.All my requests are POST requests, but they are idempotent - they are safe to call several times without adverse side effects.

Am I setting the retry handler incorrectly? Is the retry handler only called in certain scenarios?

+5
2

true, .

.

Timeout .

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;
                }
        });
+1

DefaultHttpRequestRetryHandler, HttpRequestRetryHandler

0

All Articles