SOLR-9040 / SOLR-4509: Fix default SchemaRegistryProvider so javax.net.ssl.* system properties are respected by default

This commit is contained in:
Chris Hostetter 2016-04-27 15:40:41 -07:00
parent ebd120465a
commit 9ab76a1e41
1 changed files with 18 additions and 12 deletions

View File

@ -47,6 +47,7 @@ import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.HttpEntityWrapper; import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@ -124,6 +125,7 @@ public class HttpClientUtil {
} }
public static abstract class SchemaRegistryProvider { public static abstract class SchemaRegistryProvider {
/** Must be non-null */
public abstract Registry<ConnectionSocketFactory> getSchemaRegistry(); public abstract Registry<ConnectionSocketFactory> getSchemaRegistry();
} }
@ -172,16 +174,22 @@ public class HttpClientUtil {
} }
public static void resetHttpClientBuilder() { public static void resetHttpClientBuilder() {
schemaRegistryProvider = new SchemaRegistryProvider() { schemaRegistryProvider = new DefaultSchemaRegistryProvider();
@Override
public Registry<ConnectionSocketFactory> getSchemaRegistry() {
return RegistryBuilder.<ConnectionSocketFactory> create()
.register("http", PlainConnectionSocketFactory.getSocketFactory()).build();
}
};
httpClientBuilder = SolrHttpClientBuilder.create(); httpClientBuilder = SolrHttpClientBuilder.create();
}
private static final class DefaultSchemaRegistryProvider extends SchemaRegistryProvider {
@Override
public Registry<ConnectionSocketFactory> getSchemaRegistry() {
// this mimics PoolingHttpClientConnectionManager's default behavior,
// except that we explicitly use SSLConnectionSocketFactory.getSystemSocketFactory()
// to pick up the system level default SSLContext (where javax.net.ssl.* properties
// related to keystore & truststore are specified)
RegistryBuilder<ConnectionSocketFactory> builder = RegistryBuilder.<ConnectionSocketFactory>create();
builder.register("http", PlainConnectionSocketFactory.getSocketFactory());
builder.register("https", SSLConnectionSocketFactory.getSystemSocketFactory());
return builder.build();
}
} }
/** /**
@ -192,9 +200,7 @@ public class HttpClientUtil {
* configuration (no additional configuration) is created. * configuration (no additional configuration) is created.
*/ */
public static CloseableHttpClient createClient(SolrParams params) { public static CloseableHttpClient createClient(SolrParams params) {
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(schemaRegistryProvider.getSchemaRegistry()); return createClient(params, new PoolingHttpClientConnectionManager(schemaRegistryProvider.getSchemaRegistry()));
return createClient(params, cm);
} }
public static CloseableHttpClient createClient(SolrParams params, PoolingHttpClientConnectionManager cm) { public static CloseableHttpClient createClient(SolrParams params, PoolingHttpClientConnectionManager cm) {