Example usage for org.apache.solr.client.solrj.impl HttpSolrClient getHttpClient

List of usage examples for org.apache.solr.client.solrj.impl HttpSolrClient getHttpClient

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl HttpSolrClient getHttpClient.

Prototype

public HttpClient getHttpClient() 

Source Link

Document

Return the HttpClient this instance uses.

Usage

From source file:com.frank.search.solr.server.support.HttpSolrClientFactory.java

License:Apache License

private void appendAuthentication(Credentials credentials, String authPolicy, SolrClient solrClient) {
    if (isHttpSolrClient(solrClient)) {
        HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient;

        if (credentials != null && StringUtils.isNotBlank(authPolicy)
                && assertHttpClientInstance(httpSolrClient.getHttpClient())) {
            AbstractHttpClient httpClient = (AbstractHttpClient) httpSolrClient.getHttpClient();
            httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), credentials);
            httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(authPolicy));
        }/*from  w w w. jav  a  2s  . c o m*/
    }
}

From source file:org.codice.solr.factory.impl.HttpSolrClientFactory.java

License:Open Source License

private static void createSolrCore(String url, String coreName, String configFileName, HttpClient httpClient)
        throws IOException, SolrServerException {
    HttpSolrClient client;
    if (httpClient != null) {
        client = new HttpSolrClient(url, httpClient);
    } else {//from w w w.  j  a va 2  s .  c o  m
        client = new HttpSolrClient(url);
    }

    HttpResponse ping = client.getHttpClient().execute(new HttpHead(url));
    if (ping != null && ping.getStatusLine().getStatusCode() == 200) {
        ConfigurationFileProxy configProxy = new ConfigurationFileProxy(ConfigurationStore.getInstance());
        configProxy.writeSolrConfiguration(coreName);
        if (!solrCoreExists(client, coreName)) {
            LOGGER.debug("Creating Solr core {}", coreName);

            String configFile = StringUtils.defaultIfBlank(configFileName, DEFAULT_SOLRCONFIG_XML);

            String solrDir;
            if (System.getProperty("solr.data.dir") != null) {
                solrDir = System.getProperty("solr.data.dir");
            } else {
                solrDir = Paths.get(System.getProperty("karaf.home"), "data", "solr").toString();
            }

            String instanceDir = Paths.get(solrDir, coreName).toString();

            String dataDir = Paths.get(instanceDir, "data").toString();

            CoreAdminRequest.createCore(coreName, instanceDir, client, configFile, DEFAULT_SCHEMA_XML, dataDir,
                    dataDir);
        } else {
            LOGGER.debug("Solr core ({}) already exists - reloading it", coreName);
            CoreAdminRequest.reloadCore(coreName, client);
        }
    } else {
        LOGGER.debug("Unable to ping Solr core {}", coreName);
        throw new SolrServerException("Unable to ping Solr core");
    }
}

From source file:org.springframework.data.solr.server.support.HttpSolrClientFactory.java

License:Apache License

private void appendAuthentication(Credentials credentials, String authPolicy, SolrClient solrClient) {

    if (isHttpSolrClient(solrClient)) {

        HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient;

        if (credentials != null && StringUtils.isNotBlank(authPolicy)
                && assertHttpClientInstance(httpSolrClient.getHttpClient())) {

            HttpClient httpClient = httpSolrClient.getHttpClient();

            DirectFieldAccessor df = new DirectFieldAccessor(httpClient);
            CredentialsProvider provider = (CredentialsProvider) df.getPropertyValue("credentialsProvider");

            provider.setCredentials(new AuthScope(AuthScope.ANY), credentials);
        }/*w  w w.  j  a va  2s.c om*/
    }
}

From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java

License:Apache License

/**
 * @see DATASOLR-189/* w  w  w. j  ava 2  s  .c o m*/
 */
@Test
public void cloningHttpSolrClientShouldCopyHttpParamsCorrectly() {

    HttpParams params = new BasicHttpParams();
    params.setParameter("foo", "bar");
    DefaultHttpClient client = new DefaultHttpClient(params);

    HttpSolrClient solrClient = new HttpSolrClient(BASE_URL, client);
    HttpSolrClient cloned = SolrClientUtils.clone(solrClient);

    Assert.assertThat(cloned.getHttpClient().getParams(), IsEqual.equalTo(params));
}

From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java

License:Apache License

/**
 * @see DATASOLR-189/* w ww.j  a va 2  s  .c  o  m*/
 */
@Test
public void cloningHttpSolrClientShouldCopyCredentialsProviderCorrectly() {

    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("foo", "bar"));

    DefaultHttpClient client = new DefaultHttpClient();
    client.setCredentialsProvider(credentialsProvider);

    HttpSolrClient solrClient = new HttpSolrClient(BASE_URL, client);
    HttpSolrClient cloned = SolrClientUtils.clone(solrClient);

    Assert.assertThat(((AbstractHttpClient) cloned.getHttpClient()).getCredentialsProvider(),
            IsEqual.<CredentialsProvider>equalTo(credentialsProvider));
}

From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java

License:Apache License

/**
 * @see DATASOLR-227//from  ww  w  .j a  v  a  2s  .c o  m
 */
@Test
public void cloningHttpSolrClientShouldCopyConnectionManager() {

    ClientConnectionManager conncetionManager = new SingleClientConnManager();

    DefaultHttpClient client = new DefaultHttpClient(conncetionManager);

    HttpSolrClient solrClient = new HttpSolrClient(BASE_URL, client);
    HttpSolrClient cloned = SolrClientUtils.clone(solrClient);

    Assert.assertThat(((AbstractHttpClient) cloned.getHttpClient()).getConnectionManager(),
            IsEqual.<ClientConnectionManager>equalTo(conncetionManager));
}