diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index f8955c31878..540f5417779 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -61,7 +61,10 @@ New Features Improvements --------------------- * SOLR-14316: Remove unchecked type conversion warning in JavaBinCodec's readMapEntry's equals() method - (Aroop Ganguly, Tomás Fernández Löbbe, Noble Paul, Anshum Gupta) + (Aroop Ganguly, Tomás Fernández Löbbe, Noble Paul, Anshum Gupta) + +* SOLR-14260: Make SolrJ ConnectionSocketFactory pluggable via SocketFactoryRegistryProvider setting on HttpClientUtil + (Andy Throgmorton via David Smiley) Optimizations --------------------- diff --git a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java index 20609784b0e..5981922c25d 100644 --- a/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java +++ b/solr/core/src/java/org/apache/solr/update/UpdateShardHandler.java @@ -95,9 +95,9 @@ public class UpdateShardHandler implements SolrInfoBean { private int connectionTimeout = HttpClientUtil.DEFAULT_CONNECT_TIMEOUT; public UpdateShardHandler(UpdateShardHandlerConfig cfg) { - updateOnlyConnectionManager = new InstrumentedPoolingHttpClientConnectionManager(HttpClientUtil.getSchemaRegisteryProvider().getSchemaRegistry()); - recoveryOnlyConnectionManager = new InstrumentedPoolingHttpClientConnectionManager(HttpClientUtil.getSchemaRegisteryProvider().getSchemaRegistry()); - defaultConnectionManager = new InstrumentedPoolingHttpClientConnectionManager(HttpClientUtil.getSchemaRegisteryProvider().getSchemaRegistry()); + updateOnlyConnectionManager = new InstrumentedPoolingHttpClientConnectionManager(HttpClientUtil.getSocketFactoryRegistryProvider().getSocketFactoryRegistry()); + recoveryOnlyConnectionManager = new InstrumentedPoolingHttpClientConnectionManager(HttpClientUtil.getSocketFactoryRegistryProvider().getSocketFactoryRegistry()); + defaultConnectionManager = new InstrumentedPoolingHttpClientConnectionManager(HttpClientUtil.getSocketFactoryRegistryProvider().getSocketFactoryRegistry()); ModifiableSolrParams clientParams = new ModifiableSolrParams(); if (cfg != null ) { updateOnlyConnectionManager.setMaxTotal(cfg.getMaxUpdateConnections()); diff --git a/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java b/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java index fc8ec9f63a6..c43bf6ce6ac 100644 --- a/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java +++ b/solr/core/src/test/org/apache/solr/cloud/SSLMigrationTest.java @@ -71,7 +71,7 @@ public class SSLMigrationTest extends AbstractFullDistribZkTestBase { runner.stop(); } - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); for(int i = 0; i < this.jettys.size(); i++) { JettySolrRunner runner = jettys.get(i); JettyConfig config = JettyConfig.builder() diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java index b659a1f397b..4c455372983 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterSSL.java @@ -87,13 +87,13 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { public void before() { // undo the randomization of our super class log.info("NOTE: This Test ignores the randomized SSL & clientAuth settings selected by base class"); - HttpClientUtil.resetHttpClientBuilder(); // also resets SchemaRegistryProvider + HttpClientUtil.resetHttpClientBuilder(); // also resets SocketFactoryRegistryProvider Http2SolrClient.resetSslContextFactory(); System.clearProperty(ZkStateReader.URL_SCHEME); } @After public void after() { - HttpClientUtil.resetHttpClientBuilder(); // also resets SchemaRegistryProvider + HttpClientUtil.resetHttpClientBuilder(); // also resets SocketFactoryRegistryProvider Http2SolrClient.resetSslContextFactory(); System.clearProperty(ZkStateReader.URL_SCHEME); SSLContext.setDefault(DEFAULT_SSL_CONTEXT); @@ -101,7 +101,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { public void testNoSsl() throws Exception { final SSLTestConfig sslConfig = new SSLTestConfig(false, false); - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "http"); checkClusterWithNodeReplacement(sslConfig); @@ -112,7 +112,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { // but we test it anyway for completeness of sanity checking the behavior of code that looks at those // options. final SSLTestConfig sslConfig = new SSLTestConfig(false, true); - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "http"); checkClusterWithNodeReplacement(sslConfig); @@ -120,7 +120,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { public void testSslAndNoClientAuth() throws Exception { final SSLTestConfig sslConfig = new SSLTestConfig(true, false); - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "https"); checkClusterWithNodeReplacement(sslConfig); @@ -131,7 +131,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { final SSLTestConfig sslConfig = new SSLTestConfig(true, true); - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "https"); checkClusterWithNodeReplacement(sslConfig); @@ -140,7 +140,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { // commented out on: 17-Feb-2019 @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018 public void testSslWithCheckPeerName() throws Exception { final SSLTestConfig sslConfig = new SSLTestConfig(true, false, true); - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "https"); checkClusterWithNodeReplacement(sslConfig); @@ -185,7 +185,7 @@ public class TestMiniSolrCloudClusterSSL extends SolrTestCaseJ4 { // NOTE: first initialize the cluster w/o peer name checks, which means our server will use // certs with a bogus hostname/ip and clients shouldn't care... final SSLTestConfig sslConfig = new SSLTestConfig(true, false, false); - HttpClientUtil.setSchemaRegistryProvider(sslConfig.buildClientSchemaRegistryProvider()); + HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "https"); final JettyConfig config = JettyConfig.builder().withSSLConfig(sslConfig.buildServerSSLConfig()).build(); diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java index 21177afd5b5..12c491939aa 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpClientUtil.java @@ -100,12 +100,12 @@ public class HttpClientUtil { public static final String PROP_BASIC_AUTH_PASS = "httpBasicAuthPassword"; /** - * System property consulted to determine if the default {@link SchemaRegistryProvider} + * System property consulted to determine if the default {@link SocketFactoryRegistryProvider} * will require hostname validation of SSL Certificates. The default behavior is to enforce * peer name validation. *
- * This property will have no effect if {@link #setSchemaRegistryProvider} is used to override - * the default {@link SchemaRegistryProvider} + * This property will have no effect if {@link #setSocketFactoryRegistryProvider} is used to override + * the default {@link SocketFactoryRegistryProvider} *
*/ public static final String SYS_PROP_CHECK_PEER_NAME = "solr.ssl.checkPeerName"; @@ -132,6 +132,12 @@ public class HttpClientUtil { */ public static final String SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY = "solr.httpclient.builder.factory"; + /** + * A Java system property to select the {@linkplain SocketFactoryRegistryProvider} used for + * configuring the Apache HTTP clients. + */ + public static final String SYS_PROP_SOCKET_FACTORY_REGISTRY_PROVIDER = "solr.httpclient.socketFactory.registry.provider"; + static final DefaultHttpRequestRetryHandler NO_RETRY = new DefaultHttpRequestRetryHandler( 0, false); @@ -139,7 +145,7 @@ public class HttpClientUtil { private static SolrHttpClientContextBuilder httpClientRequestContextBuilder = new SolrHttpClientContextBuilder(); - private static volatile SchemaRegistryProvider schemaRegistryProvider; + private static volatile SocketFactoryRegistryProvider socketFactoryRegistryProvider; private static volatile String cookiePolicy; private static final ListSchemaRegistryProvider
will only support HTTPS (no HTTP scheme) using the
+ * SocketFactoryRegistryProvider
will only support HTTPS (no HTTP scheme) using the
* appropriate certs. When {@link #isSSLMode} is false, only HTTP (no HTTPS scheme) will be
* supported.
*/
- public SchemaRegistryProvider buildClientSchemaRegistryProvider() {
+ public SocketFactoryRegistryProvider buildClientSocketFactoryRegistryProvider() {
if (isSSLMode()) {
SSLConnectionSocketFactory sslConnectionFactory = buildClientSSLConnectionSocketFactory();
assert null != sslConnectionFactory;
- return new SSLSchemaRegistryProvider(sslConnectionFactory);
+ return new SSLSocketFactoryRegistryProvider(sslConnectionFactory);
} else {
return HTTP_ONLY_SCHEMA_PROVIDER;
}
@@ -268,23 +268,23 @@ public class SSLTestConfig {
return sslConnectionFactory;
}
- /** A SchemaRegistryProvider that only knows about SSL using a specified SSLConnectionSocketFactory */
- private static class SSLSchemaRegistryProvider extends SchemaRegistryProvider {
+ /** A SocketFactoryRegistryProvider that only knows about SSL using a specified SSLConnectionSocketFactory */
+ private static class SSLSocketFactoryRegistryProvider extends SocketFactoryRegistryProvider {
private final SSLConnectionSocketFactory sslConnectionFactory;
- public SSLSchemaRegistryProvider(SSLConnectionSocketFactory sslConnectionFactory) {
+ public SSLSocketFactoryRegistryProvider(SSLConnectionSocketFactory sslConnectionFactory) {
this.sslConnectionFactory = sslConnectionFactory;
}
@Override
- public Registry