DefaultRequestDirector
确实有这种故意忽略的硬编码逻辑
IOException
您需要覆盖
DefaultHttpRequestRetryHandler
这也忽略了
ConnectionException
,但以一种更可配置的方式,通过定义一个不可重试类的列表(不幸的是,这个构造函数受到保护,因此需要创建一个子类来公开该构造函数)。
CustomHttpRequestRetryHandler myRetryHandler = new CustomHttpRequestRetryHandler(3, false,
Collections.<Class<? extends IOException>>emptyList());
CloseableHttpClient client = HttpClients.custom()
.setRetryHandler(myRetryHandler)
.build();
private static class CustomHttpRequestRetryHandler extends DefaultHttpRequestRetryHandler {
public CustomHttpRequestRetryHandler(int retryCount, boolean requestSentRetryEnabled, Collection<Class<? extends IOException>> clazzes) {
super(retryCount, requestSentRetryEnabled, clazzes);
}
}