Skip to content

Instantly share code, notes, and snippets.

@sdavids13
Created March 16, 2014 01:23
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 sdavids13/9577027 to your computer and use it in GitHub Desktop.
Save sdavids13/9577027 to your computer and use it in GitHub Desktop.
package org.apache.solr.client.solrj.impl;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SchemeRegistryFactory;
import org.apache.solr.common.params.SolrParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SSLHttpClientConfigurer extends HttpClientConfigurer {
private static final Logger LOG = LoggerFactory.getLogger(SSLHttpClientConfigurer.class);
private static Scheme httpsScheme;
static {
httpsScheme = SchemeRegistryFactory.createSystemDefault().getScheme("https");
if (httpsScheme == null) {
LOG.warn("Unable to configure https support, verify the appropriate javax.net.ssl.* system properties are set.");
} else {
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) httpsScheme.getSchemeSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
}
protected void configure(DefaultHttpClient httpClient, SolrParams config) {
super.configure(httpClient, config);
if (httpsScheme != null) {
SchemeRegistry registry = httpClient.getConnectionManager().getSchemeRegistry();
//Always re-registering because of SOLR-5866
registry.unregister("https");
registry.register(httpsScheme);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment