Skip to content

Instantly share code, notes, and snippets.

@ravibharathii
Created April 21, 2020 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravibharathii/b5b2d772a6621da4c28f2880732a5097 to your computer and use it in GitHub Desktop.
Save ravibharathii/b5b2d772a6621da4c28f2880732a5097 to your computer and use it in GitHub Desktop.
Suppress Domain Name mismatch SSL error
final SSLConnectionSocketFactory sslsf;
try {
sslsf = new SSLConnectionSocketFactory(SSLContext.getDefault(),
NoopHostnameVerifier.INSTANCE);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory())
.register("https", sslsf)
.build();
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
cm.setMaxTotal(100);
HttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.setConnectionManager(cm)
.build();
// new HttpSolrClient.Builder().withHttpClient(httpClient).withBaseSolrUrl(solrHost);
final CloudSolrClient client ;
CloudSolrClient.Builder builder = new CloudSolrClient.Builder();
if (httpClient != null) {
builder = builder.withHttpClient(httpClient);
}
builder.withSolrUrl(solrHost);
client = builder.build();
client.setDefaultCollection(collection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment