Java Apache HttpClient HttpRequestRetryHandler从未调用

Java Apache HttpClient HttpRequestRetryHandler从未调用,java,android,httpclient,Java,Android,Httpclient,我正在使用Apache HTTP commonsDefaultHttpClient,构建之后,我将设置其重试处理程序: httpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() { @Override public boolean retryRequest(final IOException ioe, fi

我正在使用Apache HTTP commons
DefaultHttpClient
,构建之后,我将设置其重试处理程序:


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;
                }
        });
我向其发送请求的服务器经常超时,在execute()调用的
catch
中,我收到一个IO错误,“操作超时”,但我从未在控制台输出中看到任何“retry handler received exception of type”日志语句。我所有的请求都是POST请求,但它们是幂等的——它们可以安全地多次调用,而不会产生不良副作用


我是否错误地设置了重试处理程序?重试处理程序是否仅在某些情况下调用?

尝试使用DefaultHttpRequestRetryHandler,它是HttpRequestRetryHandler的子类,如果在处理程序中处理了异常情况,则返回true

这样可以防止抛出异常

您还可以在处理程序中处理超时异常

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

不幸的是,我不再有权访问项目源代码,所以我无法尝试。