mirror of https://github.com/apache/lucene.git
SOLR-9040 / SOLR-4509: Fix default SchemaRegistryProvider so javax.net.ssl.* system properties are respected by default
This commit is contained in:
parent
ebd120465a
commit
9ab76a1e41
|
@ -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();
|
||||||
|
httpClientBuilder = SolrHttpClientBuilder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class DefaultSchemaRegistryProvider extends SchemaRegistryProvider {
|
||||||
@Override
|
@Override
|
||||||
public Registry<ConnectionSocketFactory> getSchemaRegistry() {
|
public Registry<ConnectionSocketFactory> getSchemaRegistry() {
|
||||||
return RegistryBuilder.<ConnectionSocketFactory> create()
|
// this mimics PoolingHttpClientConnectionManager's default behavior,
|
||||||
.register("http", PlainConnectionSocketFactory.getSocketFactory()).build();
|
// 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();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
httpClientBuilder = SolrHttpClientBuilder.create();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue