| @@ -24,6 +24,10 @@ import org.apache.http.StatusLine; | |||||
| import org.apache.http.client.HttpRequestRetryHandler; | import org.apache.http.client.HttpRequestRetryHandler; | ||||
| import org.apache.http.client.methods.CloseableHttpResponse; | import org.apache.http.client.methods.CloseableHttpResponse; | ||||
| import org.apache.http.client.methods.HttpPost; | import org.apache.http.client.methods.HttpPost; | ||||
| import org.apache.http.config.Registry; | |||||
| import org.apache.http.config.RegistryBuilder; | |||||
| import org.apache.http.conn.socket.ConnectionSocketFactory; | |||||
| import org.apache.http.conn.socket.PlainConnectionSocketFactory; | |||||
| import org.apache.http.conn.ssl.NoopHostnameVerifier; | import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||||
| import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | ||||
| import org.apache.http.conn.ssl.TrustStrategy; | import org.apache.http.conn.ssl.TrustStrategy; | ||||
| @@ -75,7 +79,9 @@ public class PostBack | |||||
| private int threadsWaitingToPost; | private int threadsWaitingToPost; | ||||
| private TrustStrategy tustAllCerts; | private TrustStrategy tustAllCerts; | ||||
| SSLContext sslContext; | SSLContext sslContext; | ||||
| SSLConnectionSocketFactory connectionFactory; | |||||
| // Easy ssl certificate verification. | |||||
| SSLConnectionSocketFactory easyConnectionFactory; | |||||
| CloseableHttpClient httpclient; | CloseableHttpClient httpclient; | ||||
| private int maxRetries; | private int maxRetries; | ||||
| @@ -347,15 +353,22 @@ public class PostBack | |||||
| this.maxBatchSize = maxBatchSize; | this.maxBatchSize = maxBatchSize; | ||||
| postQueue = new LinkedList<String>(); | postQueue = new LinkedList<String>(); | ||||
| threadsWaitingToPost = 0; | threadsWaitingToPost = 0; | ||||
| cm = new PoolingHttpClientConnectionManager(); | |||||
| cm.setMaxTotal(senderPoolSize); | |||||
| cm.setDefaultMaxPerRoute(senderPoolSize); | |||||
| tustAllCerts = new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) { return true; } }; | tustAllCerts = new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) { return true; } }; | ||||
| sslContext = SSLContextBuilder.create().loadTrustMaterial(tustAllCerts).build(); | sslContext = SSLContextBuilder.create().loadTrustMaterial(tustAllCerts).build(); | ||||
| connectionFactory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); | |||||
| easyConnectionFactory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); | |||||
| Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() | |||||
| .register("http", PlainConnectionSocketFactory.getSocketFactory()) | |||||
| .register("https", easyConnectionFactory) | |||||
| .build(); | |||||
| // Connection manager cm handles ssl certificate verification via the socket registry | |||||
| cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry); | |||||
| cm.setMaxTotal(senderPoolSize); | |||||
| cm.setDefaultMaxPerRoute(senderPoolSize); | |||||
| // | // | ||||
| // Retry handler | // Retry handler | ||||
| maxRetries = RETRIES_DEFAULT; | maxRetries = RETRIES_DEFAULT; | ||||
| @@ -372,9 +385,8 @@ public class PostBack | |||||
| }; | }; | ||||
| httpclient = HttpClientBuilder.create() | httpclient = HttpClientBuilder.create() | ||||
| // .setConnectionManager(cm) | |||||
| // .setRetryHandler(retryHandler) | |||||
| .setSSLSocketFactory(connectionFactory) | |||||
| .setConnectionManager(cm) | |||||
| .setRetryHandler(retryHandler) | |||||
| .build(); | .build(); | ||||
| senderPool = new ArrayList<Sender>(); | senderPool = new ArrayList<Sender>(); | ||||