2017-07-10 50 views
1

我使用HtmlUnit和Spring。我有一個web服務正在接受使用XML的POST方法。它工作正常,然後在某些隨機場合,它無法與服務器通信,拋出IOException異常,並顯示消息目標服務器無法響應。如何配置Spring中重試HtmlUnit請求的次數?

19:32:01.489 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 5][route: {}->http://][total kept alive: 0; route allocated: 0 of 6; total allocated: 0 of 20] 
19:32:01.489 [main] INFO org.apache.http.impl.execchain.RetryExec - I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http:// The target server failed to respond 
19:32:01.489 [main] DEBUG org.apache.http.impl.execchain.RetryExec - The target server failed to respond 
org.apache.http.NoHttpResponseException: The target server failed to respond 


    WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52); 
    webClient.getOptions().setTimeout(20000); 
    webClient.getOptions().setThrowExceptionOnScriptError(false); 
    webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); 
    webClient.getOptions().setCssEnabled(false); 
    webClient.getOptions().setJavaScriptEnabled(true); 
    webClient.getOptions().setUseInsecureSSL(true); 
    webClient.getOptions().setRedirectEnabled(true); 
    webClient.waitForBackgroundJavaScriptStartingBefore(20000); 

我看到一些隨機請求是接受,但一些拒絕。這種情況是我使用Spring Boot的!因爲容器不處理響應很多(3)次。如果我在沒有彈簧的情況下運行測試,請求每3次嘗試一次執 是否可以配置重試次數,以及如何?
或者如何避免這個問題並立即執行請求?

回答

相關問題