Class AvaticaCommonsHttpClientImpl
- java.lang.Object
-
- org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl
-
- All Implemented Interfaces:
AvaticaHttpClient,HostnameVerificationConfigurable,KeyStoreConfigurable,TrustStoreConfigurable,UsernamePasswordAuthenticateable
public class AvaticaCommonsHttpClientImpl extends java.lang.Object implements AvaticaHttpClient, UsernamePasswordAuthenticateable, TrustStoreConfigurable, KeyStoreConfigurable, HostnameVerificationConfigurable
A common class to invoke HTTP requests against the Avatica server agnostic of the data being sent and received across the wire.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.calcite.avatica.remote.HostnameVerificationConfigurable
HostnameVerificationConfigurable.HostnameVerification
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.http.impl.client.BasicAuthCacheauthCacheprotected org.apache.http.config.Lookup<org.apache.http.auth.AuthSchemeProvider>authRegistryprotected org.apache.http.impl.client.CloseableHttpClientclientprotected org.apache.http.auth.UsernamePasswordCredentialscredentialsprotected org.apache.http.client.CredentialsProvidercredentialsProviderprotected org.apache.http.HttpHosthostprotected HostnameVerificationConfigurable.HostnameVerificationhostnameVerificationprotected java.lang.StringkeyPasswordprotected java.io.Filekeystoreprotected java.lang.StringkeystorePasswordprivate static org.slf4j.LoggerLOGprivate static java.lang.StringMAX_POOLED_CONNECTION_PER_ROUTE_DEFAULTprivate static java.lang.StringMAX_POOLED_CONNECTION_PER_ROUTE_KEYprivate static java.lang.StringMAX_POOLED_CONNECTIONS_DEFAULTprivate static java.lang.StringMAX_POOLED_CONNECTIONS_KEYprotected org.apache.http.impl.conn.PoolingHttpClientConnectionManagerpoolprotected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory>socketFactoryRegistryprotected java.io.Filetruststoreprotected java.lang.StringtruststorePasswordprotected java.net.URIuriprotected java.lang.ObjectuserToken
-
Constructor Summary
Constructors Constructor Description AvaticaCommonsHttpClientImpl(java.net.URL url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigureConnectionPool(org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> registry)protected voidconfigureHttpRegistry(org.apache.http.config.RegistryBuilder<org.apache.http.conn.socket.ConnectionSocketFactory> registryBuilder)protected voidconfigureHttpsRegistry(org.apache.http.config.RegistryBuilder<org.apache.http.conn.socket.ConnectionSocketFactory> registryBuilder)protected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory>configureSocketFactories()(package private) org.apache.http.client.methods.CloseableHttpResponseexecute(org.apache.http.client.methods.HttpPost post, org.apache.http.client.protocol.HttpClientContext context)(package private) javax.net.ssl.HostnameVerifiergetHostnameVerifier(HostnameVerificationConfigurable.HostnameVerification verification)Creates theHostnameVerifiergiven the providedverification.private javax.net.ssl.SSLContextgetSSLContext()private voidinitializeClient()protected voidloadKeyStore(org.apache.http.ssl.SSLContextBuilder sslContextBuilder)protected voidloadTrustStore(org.apache.http.ssl.SSLContextBuilder sslContextBuilder)byte[]send(byte[] request)Sends a serialized request to the Avatica server.voidsetHostnameVerification(HostnameVerificationConfigurable.HostnameVerification verification)Instructs theAvaticaHttpClienthow to perform hostname verification for SSL connections.voidsetKeyStore(java.io.File keystore, java.lang.String keystorepassword, java.lang.String keypassword)Sets a keystore containing the collection of client side certificates to use for HTTPS mutual authentication along with password for keystore and password for keyvoidsetTrustStore(java.io.File truststore, java.lang.String password)Sets a truststore containing the collection of trust SSL/TLS server certificates to use for HTTPS calls and the password for that truststore.voidsetUsernamePassword(AuthenticationType authType, java.lang.String username, java.lang.String password)Sets the username, password and method to be used for authentication.private static java.net.URItoURI(java.net.URL url)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
MAX_POOLED_CONNECTION_PER_ROUTE_KEY
private static final java.lang.String MAX_POOLED_CONNECTION_PER_ROUTE_KEY
- See Also:
- Constant Field Values
-
MAX_POOLED_CONNECTION_PER_ROUTE_DEFAULT
private static final java.lang.String MAX_POOLED_CONNECTION_PER_ROUTE_DEFAULT
- See Also:
- Constant Field Values
-
MAX_POOLED_CONNECTIONS_KEY
private static final java.lang.String MAX_POOLED_CONNECTIONS_KEY
- See Also:
- Constant Field Values
-
MAX_POOLED_CONNECTIONS_DEFAULT
private static final java.lang.String MAX_POOLED_CONNECTIONS_DEFAULT
- See Also:
- Constant Field Values
-
host
protected final org.apache.http.HttpHost host
-
uri
protected final java.net.URI uri
-
authCache
protected org.apache.http.impl.client.BasicAuthCache authCache
-
client
protected org.apache.http.impl.client.CloseableHttpClient client
-
socketFactoryRegistry
protected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> socketFactoryRegistry
-
pool
protected org.apache.http.impl.conn.PoolingHttpClientConnectionManager pool
-
credentials
protected org.apache.http.auth.UsernamePasswordCredentials credentials
-
credentialsProvider
protected org.apache.http.client.CredentialsProvider credentialsProvider
-
authRegistry
protected org.apache.http.config.Lookup<org.apache.http.auth.AuthSchemeProvider> authRegistry
-
userToken
protected java.lang.Object userToken
-
truststore
protected java.io.File truststore
-
keystore
protected java.io.File keystore
-
truststorePassword
protected java.lang.String truststorePassword
-
keystorePassword
protected java.lang.String keystorePassword
-
keyPassword
protected java.lang.String keyPassword
-
hostnameVerification
protected HostnameVerificationConfigurable.HostnameVerification hostnameVerification
-
-
Method Detail
-
initializeClient
private void initializeClient()
-
configureConnectionPool
protected void configureConnectionPool(org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> registry)
-
configureSocketFactories
protected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> configureSocketFactories()
-
configureHttpsRegistry
protected void configureHttpsRegistry(org.apache.http.config.RegistryBuilder<org.apache.http.conn.socket.ConnectionSocketFactory> registryBuilder)
-
getSSLContext
private javax.net.ssl.SSLContext getSSLContext() throws java.lang.Exception- Throws:
java.lang.Exception
-
loadKeyStore
protected void loadKeyStore(org.apache.http.ssl.SSLContextBuilder sslContextBuilder) throws java.lang.Exception- Throws:
java.lang.Exception
-
loadTrustStore
protected void loadTrustStore(org.apache.http.ssl.SSLContextBuilder sslContextBuilder) throws java.lang.Exception- Throws:
java.lang.Exception
-
configureHttpRegistry
protected void configureHttpRegistry(org.apache.http.config.RegistryBuilder<org.apache.http.conn.socket.ConnectionSocketFactory> registryBuilder)
-
getHostnameVerifier
javax.net.ssl.HostnameVerifier getHostnameVerifier(HostnameVerificationConfigurable.HostnameVerification verification)
Creates theHostnameVerifiergiven the providedverification.- Parameters:
verification- The intended hostname verification action.- Returns:
- A verifier for the request verification.
- Throws:
java.lang.IllegalArgumentException- if the provided verification cannot be handled.
-
send
public byte[] send(byte[] request)
Description copied from interface:AvaticaHttpClientSends a serialized request to the Avatica server.- Specified by:
sendin interfaceAvaticaHttpClient- Parameters:
request- The serialized request.- Returns:
- The serialized response.
-
execute
org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpPost post, org.apache.http.client.protocol.HttpClientContext context) throws java.io.IOException, org.apache.http.client.ClientProtocolException- Throws:
java.io.IOExceptionorg.apache.http.client.ClientProtocolException
-
setUsernamePassword
public void setUsernamePassword(AuthenticationType authType, java.lang.String username, java.lang.String password)
Description copied from interface:UsernamePasswordAuthenticateableSets the username, password and method to be used for authentication.- Specified by:
setUsernamePasswordin interfaceUsernamePasswordAuthenticateable- Parameters:
authType- Type of authenticationusername- Usernamepassword- Password
-
toURI
private static java.net.URI toURI(java.net.URL url) throws java.lang.RuntimeException- Throws:
java.lang.RuntimeException
-
setTrustStore
public void setTrustStore(java.io.File truststore, java.lang.String password)Description copied from interface:TrustStoreConfigurableSets a truststore containing the collection of trust SSL/TLS server certificates to use for HTTPS calls and the password for that truststore.- Specified by:
setTrustStorein interfaceTrustStoreConfigurable- Parameters:
truststore- The truststore on the local filesystempassword- The truststore's password
-
setKeyStore
public void setKeyStore(java.io.File keystore, java.lang.String keystorepassword, java.lang.String keypassword)Description copied from interface:KeyStoreConfigurableSets a keystore containing the collection of client side certificates to use for HTTPS mutual authentication along with password for keystore and password for key- Specified by:
setKeyStorein interfaceKeyStoreConfigurable- Parameters:
keystore- The keystore on the local filesystemkeystorepassword- The keystore's passwordkeypassword- The key's password
-
setHostnameVerification
public void setHostnameVerification(HostnameVerificationConfigurable.HostnameVerification verification)
Description copied from interface:HostnameVerificationConfigurableInstructs theAvaticaHttpClienthow to perform hostname verification for SSL connections.- Specified by:
setHostnameVerificationin interfaceHostnameVerificationConfigurable- Parameters:
verification- The mode of hostname verification
-
-