如何在Spring中配置重试次数HtmlUnit?

时间:2017-07-10 17:00:49

标签: java spring-boot htmlunit

我使用HtmlUnit和Spring。我有一个web服务,它接受一个带有XML的POST方法。它工作正常,然后在一些随机的情况下,它无法与服务器通信抛出IOException消息目标服务器无法响应。

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

1 个答案:

答案 0 :(得分:1)

可能是HttpClient中的一个错误。

如果您使用的是HttpClient 4.4,请尝试升级到4.4.1。

如果您想了解更多信息,请查看this link

如果您无法升级,以下链接可能会有所帮助。

http://www.nuxeo.com/blog/using-httpclient-properly-avoid-closewait-tcp-connections/