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();
}
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");
}
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();
}
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();
}
Aggregations