apache http client org.apache.http.NoHttpResponseException: The target server failed to respond

前端 未结 1 1402
挽巷
挽巷 2021-01-17 15:34

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         


        
相关标签:
1条回答
  • 2021-01-17 15:55

    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.

    0 讨论(0)
提交回复
热议问题