【发布时间】:2017-07-10 17:00:49
【问题描述】:
我使用 HtmlUnit 和 Spring。我有一个接受 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 次尝试执行一次请求。
是否可以配置重试次数以及如何配置?
或者如何避免这个问题并立即执行请求?
【问题讨论】:
标签: java spring-boot htmlunit