|
|
|
@@ -24,6 +24,10 @@ import org.apache.http.StatusLine; |
|
|
|
import org.apache.http.client.HttpRequestRetryHandler; |
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
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.SSLConnectionSocketFactory; |
|
|
|
import org.apache.http.conn.ssl.TrustStrategy; |
|
|
|
@@ -75,7 +79,9 @@ public class PostBack |
|
|
|
private int threadsWaitingToPost; |
|
|
|
private TrustStrategy tustAllCerts; |
|
|
|
SSLContext sslContext; |
|
|
|
SSLConnectionSocketFactory connectionFactory; |
|
|
|
|
|
|
|
// Easy ssl certificate verification. |
|
|
|
SSLConnectionSocketFactory easyConnectionFactory; |
|
|
|
CloseableHttpClient httpclient; |
|
|
|
|
|
|
|
private int maxRetries; |
|
|
|
@@ -347,15 +353,22 @@ public class PostBack |
|
|
|
this.maxBatchSize = maxBatchSize; |
|
|
|
postQueue = new LinkedList<String>(); |
|
|
|
threadsWaitingToPost = 0; |
|
|
|
cm = new PoolingHttpClientConnectionManager(); |
|
|
|
cm.setMaxTotal(senderPoolSize); |
|
|
|
cm.setDefaultMaxPerRoute(senderPoolSize); |
|
|
|
|
|
|
|
|
|
|
|
tustAllCerts = new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) { return true; } }; |
|
|
|
|
|
|
|
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 |
|
|
|
maxRetries = RETRIES_DEFAULT; |
|
|
|
@@ -372,9 +385,8 @@ public class PostBack |
|
|
|
}; |
|
|
|
|
|
|
|
httpclient = HttpClientBuilder.create() |
|
|
|
// .setConnectionManager(cm) |
|
|
|
// .setRetryHandler(retryHandler) |
|
|
|
.setSSLSocketFactory(connectionFactory) |
|
|
|
.setConnectionManager(cm) |
|
|
|
.setRetryHandler(retryHandler) |
|
|
|
.build(); |
|
|
|
|
|
|
|
senderPool = new ArrayList<Sender>(); |
|
|
|
|