Created
March 16, 2014 01:23
-
-
Save sdavids13/9577027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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