Java Code Examples for org.apache.solr.client.solrj.impl.HttpClientUtil#setConfigurer()

The following examples show how to use org.apache.solr.client.solrj.impl.HttpClientUtil#setConfigurer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrSecurity.java    From storm-solr with Apache License 2.0 5 votes vote down vote up
public void setConfigigurer() {
  if (solrJaasFile != null && !solrJaasFile.isEmpty()) {
    System.setProperty("java.security.auth.login.config", solrJaasFile);
    if (solrJaasAppName != null) {
      System.setProperty("solr.kerberos.jaas.appname", solrJaasAppName);
    }
    HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer());
  }
}
 
Example 2
Source File: FusionKrb5HttpClientConfigurer.java    From storm-solr with Apache License 2.0 5 votes vote down vote up
public static synchronized CloseableHttpClient createClient(String fusionPrincipal) {
  if (logger.isDebugEnabled()) {
    System.setProperty("sun.security.krb5.debug", "true");
  }
  if (fusionPrincipal == null) {
    logger.error("fusion.user (principal) must be set in order to use kerberos!");
  }
  HttpClientUtil.setConfigurer(new FusionKrb5HttpClientConfigurer(fusionPrincipal));
  CloseableHttpClient httpClient = HttpClientUtil.createClient(null);
  HttpClientUtil.setMaxConnections(httpClient, 500);
  HttpClientUtil.setMaxConnectionsPerHost(httpClient, 100);
  return httpClient;
}
 
Example 3
Source File: SolrProcessor.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Create a SolrClient based on the type of Solr specified.
 *
 * @param context
 *          The context
 * @return an HttpSolrClient or CloudSolrClient
 */
protected SolrClient createSolrClient(final ProcessContext context, final String solrLocation) {
    final Integer socketTimeout = context.getProperty(SOLR_SOCKET_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
    final Integer connectionTimeout = context.getProperty(SOLR_CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
    final Integer maxConnections = context.getProperty(SOLR_MAX_CONNECTIONS).asInteger();
    final Integer maxConnectionsPerHost = context.getProperty(SOLR_MAX_CONNECTIONS_PER_HOST).asInteger();
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    final String jaasClientAppName = context.getProperty(JAAS_CLIENT_APP_NAME).getValue();

    final ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(HttpClientUtil.PROP_SO_TIMEOUT, socketTimeout);
    params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, connectionTimeout);
    params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, maxConnections);
    params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, maxConnectionsPerHost);

    // has to happen before the client is created below so that correct configurer would be set if neeeded
    if (!StringUtils.isEmpty(jaasClientAppName)) {
        System.setProperty("solr.kerberos.jaas.appname", jaasClientAppName);
        HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer());
    }

    final HttpClient httpClient = HttpClientUtil.createClient(params);

    if (sslContextService != null) {
        final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.REQUIRED);
        final SSLSocketFactory sslSocketFactory = new SSLSocketFactory(sslContext);
        final Scheme httpsScheme = new Scheme("https", 443, sslSocketFactory);
        httpClient.getConnectionManager().getSchemeRegistry().register(httpsScheme);
    }

    if (SOLR_TYPE_STANDARD.equals(context.getProperty(SOLR_TYPE).getValue())) {
        return new HttpSolrClient(solrLocation, httpClient);
    } else {
        final String collection = context.getProperty(COLLECTION).evaluateAttributeExpressions().getValue();
        final Integer zkClientTimeout = context.getProperty(ZK_CLIENT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
        final Integer zkConnectionTimeout = context.getProperty(ZK_CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();

        CloudSolrClient cloudSolrClient = new CloudSolrClient(solrLocation, httpClient);
        cloudSolrClient.setDefaultCollection(collection);
        cloudSolrClient.setZkClientTimeout(zkClientTimeout);
        cloudSolrClient.setZkConnectTimeout(zkConnectionTimeout);
        return cloudSolrClient;
    }
}
 
Example 4
Source File: SolrTarget06.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private void addSecurityProperties() {
  HttpClientUtil.setConfigurer(new SdcKrb5HttpClientConfigurer());
}
 
Example 5
Source File: SolrTarget04.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private void addSecurityProperties() {
  HttpClientUtil.setConfigurer(new SdcKrb5HttpClientConfigurer());
}