I'm working with Spring 4.0.3.RELEASE version. I'm able to make restful calls successfully. However, I learnt that HTTP connections are expensive and thought of using connection pool. I read few articles like this and this. Everything is fine when I include the dependency with Maven3 and compile. The problems arise during runtime. With this code, I get class not found exception for PoolingHttpClientConnectionManager.
public RestTemplate restTemplate(){
HttpHost host = new HttpHost("localhost", 9081);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// Increase max total connection to 200
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(50);
cm.setMaxPerRoute(new HttpRoute(host), 20);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(cm);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
httpClientBuilder.build());
return new RestTemplate(requestFactory);
}
And with this code, I get class not found exception for HttpClients.
public RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(20000);
requestFactory.setReadTimeout(20000);
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}
I'm deploying on Websphere 8.5. And I tried different versions of httpclient from 4.0.1 to 4.5.2 with different scope (provided, compile) with no luck. Thanks in advance for any hint in the right direction.