【问题标题】:How to configure the number of retries HtmlUnit request in Spring?Spring中如何配置重试HtmlUnit请求的次数?
【发布时间】: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


    【解决方案1】:

    可能是 HttpClient 的 bug。

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

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

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

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

    【讨论】:

    • 感谢您的回答。如果使用 HtmlUnit,我不明白如何尝试将 HttpClient 4.4 升级到 4.4.1???
    猜你喜欢
    • 2016-10-15
    • 1970-01-01
    • 2016-03-04
    • 2017-08-10
    • 2019-05-31
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多