use of io.openk9.search.client.api.RestHighLevelClientProvider in project openk9 by smclab.
the class ElasticSearchActivator method activate.
@Activate
public void activate(BundleContext bundleContext) throws IOException {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(_elasticSearchConfiguration.getUsername(), _elasticSearchConfiguration.getPassword()));
RestClientBuilder builder = RestClient.builder(Arrays.stream(_elasticSearchConfiguration.hosts()).map(e -> e.split(":")).map(e -> new HttpHost(e[0], Integer.parseInt(e[1]))).toArray(HttpHost[]::new));
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
RestHighLevelClientProvider restHighLevelClientProvider = new RestHighLevelClientProviderImpl(restHighLevelClient);
ServiceRegistration<RestHighLevelClientProvider> serviceRegistration = bundleContext.registerService(RestHighLevelClientProvider.class, restHighLevelClientProvider, null);
_registrationList.add(AutoCloseables.mergeAutoCloseableToSafe(serviceRegistration::unregister, restHighLevelClient));
}
Aggregations