Reputation: 2263
I use HtmlUnit and Spring. I have a webservice which is accepting a POST method with XML. It is working fine then at some random occasion, it fails to communicate to the server throwing IOException with message The target server failed to respond.
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);
I see that some random requests is accept, but some reject. This situations was then I use Spring Boot! Because container doesn't handle response many (3) times. If I run test without spring, request executed per 3 attempts.
is it possible to configure the number of retries and if how?
Or how to avoid this problem and execute request at once?
Upvotes: 1
Views: 785
Reputation: 3522
Probably, it is a bug in the HttpClient.
If you are using the HttpClient 4.4, please try to upgrade to 4.4.1.
If you want for more information, please look at this link.
If you can't upgrade, the following links might be helpful.
http://www.nuxeo.com/blog/using-httpclient-properly-avoid-closewait-tcp-connections/
Upvotes: 1