use of org.finra.herd.dao.exception.CredStashGetCredentialFailedException in project herd by FINRAOS.
the class JestClientFactory method getJestClient.
/**
* Builds and returns a JEST client.
*
* @return the configured JEST client
*/
public JestClient getJestClient() {
// Retrieve the configuration values used for setting up an Elasticsearch JEST client.
final String hostname = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_HOSTNAME);
final int port = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_PORT, Integer.class);
final String scheme = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_SCHEME);
final String serverUri = String.format("%s://%s:%d", scheme, hostname, port);
final int connectionTimeout = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_CONNECTION_TIMEOUT, Integer.class);
final int readTimeout = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_READ_TIMEOUT, Integer.class);
LOGGER.info("Elasticsearch REST Client Settings: scheme={}, hostname={}, port={}, serverUri={}", scheme, hostname, port, serverUri);
io.searchbox.client.JestClientFactory jestClientFactory = new io.searchbox.client.JestClientFactory();
if (StringUtils.equalsIgnoreCase(scheme, "https")) {
final String userName = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_USERNAME);
final String credentialName = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_REST_CLIENT_USERCREDENTIALNAME);
final String credstashEncryptionContext = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_ENCRYPTION_CONTEXT);
String password;
try {
password = credStashHelper.getCredentialFromCredStash(credstashEncryptionContext, credentialName);
} catch (CredStashGetCredentialFailedException e) {
throw new IllegalStateException(e);
}
SSLConnectionSocketFactory sslSocketFactory;
try {
sslSocketFactory = new SSLConnectionSocketFactory(SSLContext.getDefault(), NoopHostnameVerifier.INSTANCE);
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
jestClientFactory.setHttpClientConfig(new HttpClientConfig.Builder(serverUri).connTimeout(connectionTimeout).readTimeout(readTimeout).defaultCredentials(userName, password).sslSocketFactory(sslSocketFactory).multiThreaded(true).build());
} else {
jestClientFactory.setHttpClientConfig(new HttpClientConfig.Builder(serverUri).connTimeout(connectionTimeout).readTimeout(readTimeout).multiThreaded(true).build());
}
return jestClientFactory.getObject();
}
Aggregations