如您所说,
ConnectionReset可能是由许多可能的原因引起的。一种可能的情况是服务器在处理请求时超时,这就是为什么客户端收到连接重置的原因。在这里,已回答问题的注释部分详细讨论了连接重置的可能原因。我可以想到的一种可能的解决方案是配置
HttpClient为在失败的情况下重试请求。您可以设置
HttpMethodRetryHandler如下所示的代码(参考)。您可能需要根据收到的异常来修改代码。
HttpMethodRetryHandler retryHandler = new HttpMethodRetryHandler() { public boolean retryMethod( final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= 5) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }; ApacheHttpClient client = ApacheHttpClient.create(); HttpClient hc = client.getClientHandler().getHttpClient(); hc.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);client.resource("/stores/"+storeId).type(MediaType.APPLICATION_JSON_TYPE).put(ClientResponse.class,indexableStore);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)