Search in sources :

Example 1 with HttpClientConfig

use of io.searchbox.client.config.HttpClientConfig in project spring-boot by spring-projects.

the class JestAutoConfiguration method createHttpClientConfig.

protected HttpClientConfig createHttpClientConfig() {
    HttpClientConfig.Builder builder = new HttpClientConfig.Builder(this.properties.getUris());
    if (StringUtils.hasText(this.properties.getUsername())) {
        builder.defaultCredentials(this.properties.getUsername(), this.properties.getPassword());
    }
    String proxyHost = this.properties.getProxy().getHost();
    if (StringUtils.hasText(proxyHost)) {
        Integer proxyPort = this.properties.getProxy().getPort();
        Assert.notNull(proxyPort, "Proxy port must not be null");
        builder.proxy(new HttpHost(proxyHost, proxyPort));
    }
    Gson gson = this.gsonProvider.getIfUnique();
    if (gson != null) {
        builder.gson(gson);
    }
    builder.multiThreaded(this.properties.isMultiThreaded());
    builder.connTimeout(this.properties.getConnectionTimeout()).readTimeout(this.properties.getReadTimeout());
    customize(builder);
    return builder.build();
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) HttpHost(org.apache.http.HttpHost) Gson(com.google.gson.Gson)

Example 2 with HttpClientConfig

use of io.searchbox.client.config.HttpClientConfig in project opennms by OpenNMS.

the class ClientRecoveryTest method test.

@Test
public void test() {
    LOG.debug("***************** start of test ClientRecoveryTest");
    try {
        IndexNameFunction indexNameFunction = new IndexNameFunction();
        String rootIndexName = EventToIndex.INDEX_NAMES.get(EventToIndex.Indices.ALARMS);
        String indexName = indexNameFunction.apply(rootIndexName, new Date());
        // Get Jest client
        HttpClientConfig clientConfig = new HttpClientConfig.Builder("http://localhost:9200").multiThreaded(true).build();
        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(clientConfig);
        JestClient jestClient = factory.getObject();
        try {
            String query = "{\n" + "\n       \"query\": {" + "\n         \"match\": {" + "\n         \"alarmid\": \"1359\"" + "\n          }" + "\n        }" + "\n     }";
            Search search = new Search.Builder(query).addIndex(indexName).build();
            SearchResult sresult = jestClient.execute(search);
            LOG.debug("received search result: " + sresult.getJsonString() + "\n   response code:" + sresult.getResponseCode() + "\n   error message: " + sresult.getErrorMessage());
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            // shutdown client
            jestClient.shutdownClient();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    LOG.debug("***************** end of test ClientRecoveryTest");
}
Also used : IndexNameFunction(org.opennms.plugins.elasticsearch.rest.IndexNameFunction) HttpClientConfig(io.searchbox.client.config.HttpClientConfig) Search(io.searchbox.core.Search) SearchResult(io.searchbox.core.SearchResult) JestClient(io.searchbox.client.JestClient) JestClientFactory(io.searchbox.client.JestClientFactory) Date(java.util.Date) Test(org.junit.Test)

Example 3 with HttpClientConfig

use of io.searchbox.client.config.HttpClientConfig in project xwiki-platform by xwiki.

the class DefaultJestClientManager method initialize.

@Override
public void initialize() throws InitializationException {
    String pingURL = this.configuration.getPingInstanceURL();
    HttpClientConfig clientConfig = new HttpClientConfig.Builder(pingURL).multiThreaded(true).build();
    JestClientFactory factory = new XWikiJestClientFactory(this.configuration);
    factory.setHttpClientConfig(clientConfig);
    this.client = factory.getObject();
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) JestClientFactory(io.searchbox.client.JestClientFactory)

Example 4 with HttpClientConfig

use of io.searchbox.client.config.HttpClientConfig in project jmxtrans by jmxtrans.

the class ElasticWriter method createJestClient.

private JestClient createJestClient(String connectionUrl, String username, String password) {
    log.info("Create a jest elastic search client for connection url [{}]", connectionUrl);
    JestClientFactory factory = new JestClientFactory();
    HttpClientConfig httpClientConfig;
    if (username != null) {
        log.info("Using HTTP Basic Authentication");
        httpClientConfig = new HttpClientConfig.Builder(connectionUrl).defaultCredentials(username, password).multiThreaded(true).build();
    } else {
        httpClientConfig = new HttpClientConfig.Builder(connectionUrl).multiThreaded(true).build();
    }
    factory.setHttpClientConfig(httpClientConfig);
    return factory.getObject();
}
Also used : HttpClientConfig(io.searchbox.client.config.HttpClientConfig) JestClientFactory(io.searchbox.client.JestClientFactory)

Aggregations

HttpClientConfig (io.searchbox.client.config.HttpClientConfig)4 JestClientFactory (io.searchbox.client.JestClientFactory)3 Gson (com.google.gson.Gson)1 JestClient (io.searchbox.client.JestClient)1 Search (io.searchbox.core.Search)1 SearchResult (io.searchbox.core.SearchResult)1 Date (java.util.Date)1 HttpHost (org.apache.http.HttpHost)1 Test (org.junit.Test)1 IndexNameFunction (org.opennms.plugins.elasticsearch.rest.IndexNameFunction)1