I am using apache http client to test my WS. I have write a get WS in jersey. URL for this WS is
http://localhost:8080/mobilestore/rest/sysgestockmobilews/g
I went through the links from here and got to this answer: get NoHttpResponseException for load testing
That set me on the right track. To update the answer a bit here is the solution using the current http-client 4.5 API:
private final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(createHttpClient());
private CloseableHttpClient createHttpClient() {
return HttpClients.custom().setRetryHandler((exception, executionCount, context) -> {
if (executionCount > 3) {
LOGGER.warn("Maximum tries reached for client http pool ");
return false;
}
if (exception instanceof org.apache.http.NoHttpResponseException) {
LOGGER.warn("No response from server on " + executionCount + " call");
return true;
}
return false;
}).build();
}
I also use spring-web there so I used the client as a parameter for RestTemplate factory since I want it to be used in the RestTemplate.