如何将HttpClientConnectionManager
的超时时间设置为超过2分钟?
我们正在连接一个长期运行的SOAP服务,该服务在返回HTTP响应之前会处理几(5-8)分钟。我们无法控制此服务,因此我们需要在收到回复之前允许长时间的活动。
使用Apache HttpClient 4.3.2库,我们注意到连接管理器似乎因2分钟后因不活动而关闭连接:
16:14:45.805 DEBUG o.a.h.headers.onRequestSubmitted(124) - http-outgoing-0 >> POST /someendpoint.do?SOAP HTTP/1.1
16:14:45.805 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> content-type: application/soap+xml
16:14:45.805 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> Content-Length: 536
16:14:45.806 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> Host: someserver.com
16:14:45.806 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> Connection: Keep-Alive
16:14:45.806 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.2 (java 1.5)
16:14:45.806 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> Accept-Encoding: gzip,deflate
16:14:45.806 DEBUG o.a.h.headers.onRequestSubmitted(127) - http-outgoing-0 >> Authorization: Basic Y290GARBAGE36Om9uZXR
16:16:46.750 DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection.close(79) - http-outgoing-0: Close connection
16:16:46.750 DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection.shutdown(87) - http-outgoing-0: Shutdown connection
16:16:46.750 DEBUG o.a.h.i.e.MainClientExec.abortConnection(126) - Connection discarded
16:16:46.751 DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection.close(79) - http-outgoing-0: Close connection
16:16:46.751 DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager.releaseConnection(282) - Connection released: [id: 0][route: {tls}->http://http-proxy.mydomain.com:8080->https://someserver.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
16:16:46.753 INFO o.a.h.i.e.RetryExec.execute(93) - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
16:16:46.758 DEBUG o.a.h.i.e.RetryExec.execute(98) - The target server failed to respond
org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143) ~[httpclient-4.3.2.jar:4.3.2]
我们已尝试connMgr.closeIdleConnections( 10, TimeUnit.MINUTES );
,指定我们自己的ConnectionKeepAliveStrategy
,并在请求配置中设置超时:
config = RequestConfig.copy(RequestConfig.DEFAULT)
.setSocketTimeout(soTimeout)
.setConnectTimeout(connTimeout)
.setConnectionRequestTimeout(rqTimeout)
.build();
我们是否缺少一些补充设置,例如设置超时此处以及设置标志 或 this 和 设置为相同的值?
当预计服务器响应时间超过2分钟时,阻止连接关闭的正确方法是什么?
答案 0 :(得分:0)
NoHttpResponseException基本上意味着连接被相对的端点(或中间件)终止。您在客户端的超时设置看起来非常好。