2015-10-28 116 views
0

如何將HttpClientConnectionManager上的超時設置爲超過2分鐘?在Apache 4.x客戶端中控制請求超時

我們正在連接一個長時間運行的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(); 

是我們缺少一些輔助設置,如設置超時這裏還設置一個標誌there or that this and that are set the same value?

當服務器預計不會響應超過2分鐘時,防止連接關閉的正確方法是什麼?

回答

0

NoHttpResponseException基本上意味着連接被相反的端點(或中介)終止。客戶端的超時設置看起來非常好。

+0

謝謝@oleg。我們正在確認代理超時,但我們已經被告知它已設置爲5分鐘。 – SCote