package net.etalia.client.http;

import java.util.concurrent.TimeUnit;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.SchemeRegistryFactory;

public class HttpClientHelper {

	public HttpClient createDefaultClient(int connections, int timeout) {
		PoolingClientConnectionManager cm = 
			new PoolingClientConnectionManager(
				SchemeRegistryFactory.createDefault(),
				timeout, TimeUnit.MILLISECONDS
			);
		cm.setDefaultMaxPerRoute(connections);
		cm.setMaxTotal(connections);
		
		DefaultHttpClient ret = new DefaultHttpClient(cm);
		
		ret.getParams().setParameter("http.socket.timeout", timeout);
		ret.getParams().setParameter("http.connection.timeout", timeout);
		//ret.getParams().setParameter("http.connection-manager.timeout", timeout);
		ret.getParams().setParameter("http.protocol.head-body-timeout", timeout);
		return ret;
	}
	
}

@@ -134,37 +134,259 @@
 ttp.
-impl.client.DefaultHttpClient
+client.config.RequestConfig;%0Aimport org.apache.http.conn.ssl.SSLConnectionSocketFactory;%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0Aimport org.apache.http.impl.client.DefaultHttpClient;%0Aimport org.apache.http.impl.client.HttpClientBuilder
 ;%0Aim
@@ -1205,12 +1205,623 @@
 ret;%0A%09%7D%0A
-%09
+%0A%09public HttpClient createDefaultClient(int connections, int timeout, SSLConnectionSocketFactory sslsf) %7B%0A%09%09HttpClientBuilder clientBuilder = HttpClientBuilder.create();%0A%09%09clientBuilder.setSSLSocketFactory(sslsf);%0A%09%09clientBuilder.setMaxConnPerRoute(connections);%0A%09%09clientBuilder.setMaxConnTotal(connections);%0A%09%09RequestConfig.Builder requestBuilder = RequestConfig.custom();%0A%09%09requestBuilder.setConnectTimeout(timeout);%0A%09%09requestBuilder.setConnectionRequestTimeout(timeout);%0A%09%09clientBuilder.setDefaultRequestConfig(requestBuilder.build());%0A%09%09CloseableHttpClient client = clientBuilder.build();%0A%09%09return client;%0A%09%7D
 %0A%7D%0A

Create HttpClient for SSL