2017-07-10 77 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次尝试一次执 是否可以配置重试次数,以及如何?
或者如何避免这个问题并立即执行请求?

回答

相关问题