package com.signalfx.metrics.connection;

import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;

import com.signalfx.endpoint.SignalFxReceiverEndpoint;
import com.signalfx.metrics.SignalFxMetricsException;

public class HttpDataPointProtobufReceiverFactory implements DataPointReceiverFactory {
    public static final int DEFAULT_TIMEOUT_MS = 2000;
    public static final int DEFAULT_VERSION = 2;

    private final SignalFxReceiverEndpoint endpoint;
    private HttpClientConnectionManager httpClientConnectionManager =
            new BasicHttpClientConnectionManager();
    private int timeoutMs = DEFAULT_TIMEOUT_MS;
    private int version = DEFAULT_VERSION;

    public HttpDataPointProtobufReceiverFactory(SignalFxReceiverEndpoint endpoint) {
        this.endpoint = endpoint;
    }

    public HttpDataPointProtobufReceiverFactory setTimeoutMs(int timeoutMs) {
        this.timeoutMs = timeoutMs;
        return this;
    }

    public HttpDataPointProtobufReceiverFactory setVersion(int version) {
        this.version = version;
        return this;
    }

    public void setHttpClientConnectionManager(
            HttpClientConnectionManager httpClientConnectionManager) {
        this.httpClientConnectionManager = httpClientConnectionManager;
    }

    @Override
    public DataPointReceiver createDataPointReceiver() throws
            SignalFxMetricsException {
        if (version == 1) {
            return new HttpDataPointProtobufReceiverConnection(endpoint, this.timeoutMs, httpClientConnectionManager);
        } else {
            return new HttpDataPointProtobufReceiverConnectionV2(endpoint, this.timeoutMs, httpClientConnectionManager);
        }

    }
}

@@ -46,54 +46,419 @@
 ort 
-org.apache.http.conn.HttpClientConnectionManag
+javax.net.ssl.SSLContext;%0A%0Aimport org.apache.http.config.RegistryBuilder;%0Aimport org.apache.http.conn.HttpClientConnectionManager;%0Aimport org.apache.http.conn.socket.ConnectionSocketFactory;%0Aimport org.apache.http.conn.socket.PlainConnectionSocketFactory;%0Aimport org.apache.http.conn.ssl.SSLConnectionSocketFactory;%0Aimport org.apache.http.conn.ssl.SSLContexts;%0Aimport org.apache.http.conn.ssl.X509HostnameVerifi
 er;%0A
@@ -952,61 +952,8 @@
 ager
- =%0A            new BasicHttpClientConnectionManager()
 ;%0A  
@@ -1123,24 +1123,24 @@
 endpoint) %7B%0A
-
         this
@@ -1156,24 +1156,564 @@
  = endpoint;
+%0A%0A        // Same as new BasicHttpClientConnectionManager() but with STRICT_HOSTNAME_VERIFIER.%0A        this.httpClientConnectionManager = new BasicHttpClientConnectionManager(%0A                RegistryBuilder.%3CConnectionSocketFactory%3Ecreate()%0A                    .register(%22http%22, PlainConnectionSocketFactory.getSocketFactory())%0A                    .register(%22https%22, new SSLConnectionSocketFactory(SSLContexts.createDefault(),%0A                            SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER))%0A                    .build());
 %0A    %7D%0A%0A    

Use the STRICT_HOSTNAME_VERIFIER to validate SSL certificates' hostnames