栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

重置与Jersey客户端的连接

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

重置与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);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号