重置与Jersey客户端的连接

重置与Jersey客户端的连接,第1张

重置与Jersey客户端的连接

如您所说,

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5506719.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存