Class ElasticsearchHttpClientFactory
java.lang.Object
org.alfresco.repo.search.impl.elasticsearch.client.ElasticsearchHttpClientFactory
Singleton factory for Elasticsearch Http Client. This class is providing an Elastic RestHighLevelClient instance, that maintains a pool of RestLowLevelClient instances.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.hc.client5.http.config.RequestConfigBuilds and caches the RequestConfig with the configured response timeout.protected ExceptionHook for subclasses to release any additional client resources (for example an AWS HTTP client) during shutdown.voiddestroy()protected Stringprotected org.opensearch.client.opensearch.OpenSearchClientprotected intprotected org.apache.hc.client5.http.auth.CredentialsProviderBuild CredentialsProvider instance with user and password values from properties fileorg.opensearch.client.opensearch.OpenSearchClientSingleton method returning the Elasticsearch client.protected org.opensearch.client.opensearch.OpenSearchClientgetElasticsearchClient(String protocol, int port) Creates an Elasticsearch client applying parameters from properties fileGets Elasticsearch server URLprotected StringgetHost()protected org.apache.hc.client5.http.impl.async.HttpAsyncClientBuildergetHttpAsyncClientBuilder(org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder httpClientBuilder) Apply pooling options, credentials and SSL settings to Elasticsearch clientprotected org.alfresco.encryption.KeyResourceLoaderprotected intprotected intprotected intgetPort()protected Stringprotected intprotected Stringprotected intprotected SSLContextBuild SSLContext instance with truststore that must include Elasticsearch server public certificate in order to be trusted for this https connection.protected org.alfresco.encryption.ssl.SSLEncryptionParametersprotected org.alfresco.encryption.AlfrescoKeyStoreprotected intprotected StringgetUser()voidinit()Initialize SSL Truststore for https connections using "encryption.ssl.truststore.*" propertiesprotected booleanprotected booleanisSecure()voidsetArchiveIndexName(String archiveIndexName) voidsetBaseUrl(String baseUrl) protected voidsetClient(org.opensearch.client.opensearch.OpenSearchClient client) voidsetConnectionTimeout(int connectionTimeout) voidvoidsetHostNameVerification(boolean hostNameVerification) voidsetIndexName(String indexName) voidsetKeyResourceLoader(org.alfresco.encryption.KeyResourceLoader keyResourceLoader) voidsetMaxHostConnections(int maxHostConnections) voidsetMaxTotalConnections(int maxTotalConnections) voidsetPassword(String password) voidsetPort(int port) voidsetResponseTimeout(int responseTimeout) voidsetSecureComms(String secureComms) voidsetSocketTimeout(int socketTimeout) voidsetSslEncryptionParameters(org.alfresco.encryption.ssl.SSLEncryptionParameters sslEncryptionParameters) voidsetThreadCount(int threadCount) protected voidsetTransport(org.opensearch.client.transport.OpenSearchTransport transport) Allows subclasses that build their own transport (for example an AWS-signed transport) to register it so that it is closed during shutdown.void
-
Field Details
-
TLS
- See Also:
-
TLS_V_1_2
- See Also:
-
TLS_V_1_3
- See Also:
-
SECURE_COMMS_HTTPS
- See Also:
-
-
Constructor Details
-
ElasticsearchHttpClientFactory
public ElasticsearchHttpClientFactory()
-
-
Method Details
-
init
public void init()Initialize SSL Truststore for https connections using "encryption.ssl.truststore.*" properties -
getSecureComms
-
getHost
-
getBaseUrl
-
getPort
protected int getPort() -
getSslEncryptionParameters
protected org.alfresco.encryption.ssl.SSLEncryptionParameters getSslEncryptionParameters() -
getKeyResourceLoader
protected org.alfresco.encryption.KeyResourceLoader getKeyResourceLoader() -
getSslTrustStore
protected org.alfresco.encryption.AlfrescoKeyStore getSslTrustStore() -
isHostNameVerification
protected boolean isHostNameVerification() -
getUser
-
getMaxTotalConnections
protected int getMaxTotalConnections() -
getMaxHostConnections
protected int getMaxHostConnections() -
getThreadCount
protected int getThreadCount() -
getConnectionTimeout
protected int getConnectionTimeout() -
getSocketTimeout
protected int getSocketTimeout() -
getResponseTimeout
protected int getResponseTimeout() -
getClient
protected org.opensearch.client.opensearch.OpenSearchClient getClient() -
destroy
public void destroy() -
getElasticsearchClient
public org.opensearch.client.opensearch.OpenSearchClient getElasticsearchClient()Singleton method returning the Elasticsearch client. The client is only built if it's not already created.- Returns:
- Elasticsearch client
-
getElasticsearchServerUrl
Gets Elasticsearch server URL- Returns:
- Elasticsearch server URL
-
getElasticsearchClient
protected org.opensearch.client.opensearch.OpenSearchClient getElasticsearchClient(String protocol, int port) Creates an Elasticsearch client applying parameters from properties file- Parameters:
protocol- Http protocol: http or httpsport- Port number- Returns:
- Elasticsearch client ready to be used
-
isSecure
protected boolean isSecure()- Returns:
truewhen the configuredsecureCommsvalue indicates an HTTPS endpoint. Subclasses may broaden this (for example, an mTLS-aware enterprise factory).
-
getProtocol
- Returns:
- the wire protocol ("https" or "http") derived from
isSecure().
-
closeAdditionalResources
Hook for subclasses to release any additional client resources (for example an AWS HTTP client) during shutdown.- Returns:
- an exception thrown while closing, or
nullif nothing failed.
-
setTransport
protected void setTransport(org.opensearch.client.transport.OpenSearchTransport transport) Allows subclasses that build their own transport (for example an AWS-signed transport) to register it so that it is closed during shutdown.- Parameters:
transport- the transport to be managed by this factory
-
buildRequestConfig
protected org.apache.hc.client5.http.config.RequestConfig buildRequestConfig()Builds and caches the RequestConfig with the configured response timeout. -
getHttpAsyncClientBuilder
protected org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder getHttpAsyncClientBuilder(org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder httpClientBuilder) Apply pooling options, credentials and SSL settings to Elasticsearch client- Parameters:
httpClientBuilder- Existing HttpClientBuilder instance- Returns:
- httpClientBuilder including required settings
-
getCredentialsProvider
protected org.apache.hc.client5.http.auth.CredentialsProvider getCredentialsProvider()Build CredentialsProvider instance with user and password values from properties file- Returns:
- CredentialsProvider instance
-
getSSLContext
Build SSLContext instance with truststore that must include Elasticsearch server public certificate in order to be trusted for this https connection.- Returns:
- SSLContext instance
-
setHost
-
setBaseUrl
-
setPort
public void setPort(int port) -
setSecureComms
-
setUser
-
setPassword
-
setMaxTotalConnections
public void setMaxTotalConnections(int maxTotalConnections) -
setMaxHostConnections
public void setMaxHostConnections(int maxHostConnections) -
setConnectionTimeout
public void setConnectionTimeout(int connectionTimeout) -
setSocketTimeout
public void setSocketTimeout(int socketTimeout) -
setResponseTimeout
public void setResponseTimeout(int responseTimeout) -
setClient
protected void setClient(org.opensearch.client.opensearch.OpenSearchClient client) -
setSslEncryptionParameters
public void setSslEncryptionParameters(org.alfresco.encryption.ssl.SSLEncryptionParameters sslEncryptionParameters) -
setKeyResourceLoader
public void setKeyResourceLoader(org.alfresco.encryption.KeyResourceLoader keyResourceLoader) -
setHostNameVerification
public void setHostNameVerification(boolean hostNameVerification) -
setIndexName
-
setArchiveIndexName
-
getArchiveIndexName
-
getIndexName
-
setThreadCount
public void setThreadCount(int threadCount)
-