Class CommonsDataLoader
java.lang.Object
eu.europa.esig.dss.service.http.commons.CommonsDataLoader
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
OCSPDataLoader, TimestampDataLoader
Implementation of DataLoader for any protocol.
HTTP and HTTPS: using HttpClient which is more flexible for HTTPS without
having to add the certificate to the JVM TrustStore. It takes into account a
proxy management through ProxyPreferenceManager. The authentication
is also supported.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor for CommonsDataLoader.CommonsDataLoader(String contentType) The constructor for CommonsDataLoader with defined content-type. -
Method Summary
Modifier and TypeMethodDescriptionaddAuthentication(HostConnection hostConnection, UserCredentials userCredentials) Adds authentication credentials to the existingauthenticationMapaddAuthentication(String host, int port, String scheme, String login, char[] password) Adds authentication credentials to the existingauthenticationMapprotected voidcloseQuietly(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase httpRequest, org.apache.hc.client5.http.impl.classic.CloseableHttpClient client) Closes all the parameters quietlyprotected org.apache.hc.client5.http.protocol.HttpClientContextconfigurePreemptiveAuthentication(org.apache.hc.client5.http.protocol.HttpClientContext localContext, org.apache.hc.core5.http.HttpHost httpHost) This method is used to configure preemptive authentication process forHttpClientContext, when requiredprotected eu.europa.esig.dss.model.http.ResponseEnvelopeexecuteHttpRequest(org.apache.hc.client5.http.impl.classic.CloseableHttpClient client, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest) Deprecated.since DSS 6.4.protected eu.europa.esig.dss.model.http.ResponseEnvelopeexecuteHttpRequest(org.apache.hc.client5.http.impl.classic.CloseableHttpClient client, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, boolean includeResponseDetails, boolean includeResponseBody) ProcesseshttpRequestand returns the byte array representing the response's contentprotected byte[]Gets the file content by its URLprotected byte[]This method retrieves data using FTP protocol .byte[]eu.europa.esig.dss.spi.client.http.DataLoader.DataAndUrlReturns the current instance of the authentication mapintGets the connection keep alive timeout.protected org.apache.hc.client5.http.io.HttpClientConnectionManagerGets a configuredHttpClientConnectionManagerintGets the maximum connections number per route.intGets the maximum connections number.intGets the finite connection time to live.Gets the content typeprotected org.apache.hc.client5.http.impl.auth.BasicCredentialsProviderBuilds and returns aBasicCredentialsProviderconfigured withauthenticationMapGets the hostname verifierprotected org.apache.hc.client5.http.impl.classic.CloseableHttpClientgetHttpClient(String url) Gets the HTTP clientprotected org.apache.hc.client5.http.impl.classic.HttpClientBuilderGets theHttpClientBuilderfor the urlorg.apache.hc.core5.http.io.HttpClientResponseHandler<byte[]> Returns theHttpClientResponseHandlerresponse handlerprotected org.apache.hc.core5.http.protocol.HttpContextgetHttpContext(org.apache.hc.core5.http.HttpHost httpHost) Gets theHttpContextprotected org.apache.hc.core5.http.HttpHostgetHttpHost(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest) Gets theHttpHostprotected org.apache.hc.client5.http.classic.methods.HttpGetgetHttpRequest(String url) Gets the HTTP requestGets the proxy configurationprotected org.apache.hc.client5.http.config.RequestConfigBuilds and gets aRequestConfigprotected org.apache.hc.client5.http.config.RequestConfig.BuilderGets a configuredRequestConfig.Builderprotected org.apache.hc.core5.http.io.SocketConfigGets a configuredSocketConfigprotected org.apache.hc.core5.ssl.SSLContextBuilderGets a configuredSSLContextBuildercontaining an SSL connection trust configurationprotected KeyStoreGets the SSL KeyStoreprotected KeyStoreGets the SSL Trusted KeyStoreString[]Gets supported SSL Cipher SuitesString[]Gets supported SSL protocolsGets the target preferred authentication scheme, to be called in the given orderintGets the connection timeout.intGets the connection request timeout.intGets the server response timeout.intGets the socket timeout.protected org.apache.hc.client5.http.ssl.TlsSocketStrategyGets a configuredTlsSocketStrategyorg.apache.hc.core5.ssl.TrustStrategyGets the TrustStrategyprotected byte[]This method retrieves data using HTTP or HTTPS protocol and 'get' method.Creates an LDAP Context environmentbooleanGets if redirect is enabled.booleanGets if the default system network properties shall be usedprotected byte[]This method retrieves data using LDAP protocol. - CRL from given LDAP url, e.g. ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com - ex URL from AIA ldap://xadessrv.plugtests.net/CN=LevelBCAOK,OU=Plugtests_2015-2016,O=ETSI,C=FR?byte[]eu.europa.esig.dss.model.http.ResponseEnveloperequestGet(String url) eu.europa.esig.dss.model.http.ResponseEnveloperequestGet(String url, boolean includeResponseDetails) eu.europa.esig.dss.model.http.ResponseEnveloperequestGet(String url, boolean includeResponseDetails, boolean includeResponseBody) eu.europa.esig.dss.model.http.ResponseEnveloperequestPost(String url, byte[] content) eu.europa.esig.dss.model.http.ResponseEnveloperequestPost(String url, byte[] content, boolean includeResponseDetails) eu.europa.esig.dss.model.http.ResponseEnveloperequestPost(String url, byte[] content, boolean includeResponseDetails, boolean includeResponseBody) voidsetAuthenticationMap(Map<HostConnection, UserCredentials> authenticationMap) Sets the authentication map NOTE: this method overrides the current instance ofauthenticationMapvoidsetConnectionKeepAlive(int connectionKeepAlive) Sets the connection keep alive timeout in milliseconds.voidsetConnectionsMaxPerRoute(int connectionsMaxPerRoute) Sets the maximum connections number per route.voidsetConnectionsMaxTotal(int connectionsMaxTotal) Sets the maximum connections number.voidsetConnectionTimeToLive(int connectionTimeToLive) Sets the finite connection total time to live (TTL) in milliseconds.voidsetContentType(String contentType) voidsetHostnameVerifier(HostnameVerifier hostnameVerifier) Sets a customHostnameVerifiervoidsetHttpClientResponseHandler(org.apache.hc.core5.http.io.HttpClientResponseHandler<byte[]> httpClientResponseHandler) Sets theHttpClientResponseHandler<byte[]>response handler performing a processing of an HTTP client response and returns a byte array in case of success.voidsetKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial) Sets if the KeyStore shall be considered as a trust material (used for SSL connection)voidsetLdapTrustedHostnames(Collection<String> ldapTrustedHostnames) Sets a collection of allowed host names to perform an LDAP get request.voidsetPreemptiveAuthentication(boolean preemptiveAuthentication) Sets whether the preemptive authentication should be used.voidsetProxyConfig(ProxyConfig proxyConfig) Sets the proxy configurationvoidsetRedirectsEnabled(boolean redirectsEnabled) Sets if redirect should be enabled.voidsetRetryStrategy(org.apache.hc.client5.http.HttpRequestRetryStrategy retryStrategy) Sets a custom retry strategyvoidsetSslKeystore(eu.europa.esig.dss.model.DSSDocument sslKeyStore) Sets the SSL KeyStorevoidsetSslKeystorePassword(char[] sslKeystorePassword) Sets the KeyStore password.voidsetSslKeystoreType(String sslKeystoreType) Sets the SSL KeyStore typevoidsetSslProtocol(String sslProtocol) This method sets the SSL protocol to be usedvoidsetSslTruststore(eu.europa.esig.dss.model.DSSDocument sslTrustStore) Sets the SSL trust store NOTE: different from KeyStore!voidsetSslTruststorePassword(char[] sslTruststorePassword) Sets the password for SSL truststorevoidsetSslTruststoreType(String sslTruststoreType) Sets the SSL TrustStore typevoidsetSupportedSSLCipherSuites(String[] supportedSSLCipherSuites) Sets supported SSL Cipher SuitesvoidsetSupportedSSLProtocols(String[] supportedSSLProtocols) Sets supported SSL protocolsvoidsetTargetPreferredAuthSchemes(List<String> targetPreferredAuthSchemes) Sets a list of target preferred authentication schemes, to be executed on the given order on connection establishing Default: "Bearer", "Digest", "Basic".voidsetTimeoutConnection(int timeoutConnection) Sets the connection timeout in milliseconds.voidsetTimeoutConnectionRequest(int timeoutConnectionRequest) Sets the connection request in milliseconds.voidsetTimeoutResponse(int timeoutResponse) Sets the server response timeout in milliseconds.voidsetTimeoutSocket(int timeoutSocket) Sets the socket timeout in milliseconds.voidsetTrustStrategy(org.apache.hc.core5.ssl.TrustStrategy trustStrategy) Sets theTrustStrategyvoidsetUseSystemProperties(boolean useSystemProperties) Sets if the default system network properties shall be used Default: FALSE (system properties are not used) NOTE: all other configured property may override the default behavior!toHeadersMap(org.apache.hc.core5.http.Header[] headers) Readsheadersto aMapof strings
-
Field Details
-
contentType
The content type value
-
-
Constructor Details
-
CommonsDataLoader
public CommonsDataLoader()The default constructor for CommonsDataLoader. -
CommonsDataLoader
The constructor for CommonsDataLoader with defined content-type.- Parameters:
contentType- The content type of each request
-
-
Method Details
-
getTimeoutConnection
public int getTimeoutConnection()Gets the connection timeout.- Returns:
- the value (millis)
-
setTimeoutConnection
public void setTimeoutConnection(int timeoutConnection) Sets the connection timeout in milliseconds. A negative value is interpreted as undefined (use system default).- Parameters:
timeoutConnection- the value (millis)
-
getTimeoutConnectionRequest
public int getTimeoutConnectionRequest()Gets the connection request timeout.- Returns:
- the value (millis)
-
setTimeoutConnectionRequest
public void setTimeoutConnectionRequest(int timeoutConnectionRequest) Sets the connection request in milliseconds. A negative value is interpreted as undefined (use system default).- Parameters:
timeoutConnectionRequest- the value (millis)
-
getTimeoutResponse
public int getTimeoutResponse()Gets the server response timeout.- Returns:
- the value (millis)
-
setTimeoutResponse
public void setTimeoutResponse(int timeoutResponse) Sets the server response timeout in milliseconds. A negative value is interpreted as undefined (use system default).- Parameters:
timeoutResponse- the value (millis)
-
getTimeoutSocket
public int getTimeoutSocket()Gets the socket timeout.- Returns:
- the value (millis)
-
setTimeoutSocket
public void setTimeoutSocket(int timeoutSocket) Sets the socket timeout in milliseconds. A negative value is interpreted as undefined (use system default).- Parameters:
timeoutSocket- the value (millis)
-
getConnectionKeepAlive
public int getConnectionKeepAlive()Gets the connection keep alive timeout.- Returns:
- the value (millis)
-
setConnectionKeepAlive
public void setConnectionKeepAlive(int connectionKeepAlive) Sets the connection keep alive timeout in milliseconds.- Parameters:
connectionKeepAlive- the value (millis)
-
getConnectionsMaxTotal
public int getConnectionsMaxTotal()Gets the maximum connections number.- Returns:
- the value (millis)
-
setConnectionsMaxTotal
public void setConnectionsMaxTotal(int connectionsMaxTotal) Sets the maximum connections number.- Parameters:
connectionsMaxTotal- maximum number of connections
-
getConnectionsMaxPerRoute
public int getConnectionsMaxPerRoute()Gets the maximum connections number per route.- Returns:
- maximum number of connections per one route
-
setConnectionsMaxPerRoute
public void setConnectionsMaxPerRoute(int connectionsMaxPerRoute) Sets the maximum connections number per route.- Parameters:
connectionsMaxPerRoute- maximum number of connections per one route
-
getConnectionTimeToLive
public int getConnectionTimeToLive()Gets the finite connection time to live.- Returns:
- connection time to live (millis)
-
setConnectionTimeToLive
public void setConnectionTimeToLive(int connectionTimeToLive) Sets the finite connection total time to live (TTL) in milliseconds.- Parameters:
connectionTimeToLive- the finite connection time to live (millis)
-
isRedirectsEnabled
public boolean isRedirectsEnabled()Gets if redirect is enabled.- Returns:
- true if http redirects are allowed
-
setRedirectsEnabled
public void setRedirectsEnabled(boolean redirectsEnabled) Sets if redirect should be enabled.- Parameters:
redirectsEnabled- true if http redirects are allowed
-
isUseSystemProperties
public boolean isUseSystemProperties()Gets if the default system network properties shall be used- Returns:
- TRUE if the default system network properties shall be used, FALSE otherwise
-
setUseSystemProperties
public void setUseSystemProperties(boolean useSystemProperties) Sets if the default system network properties shall be used Default: FALSE (system properties are not used) NOTE: all other configured property may override the default behavior!- Parameters:
useSystemProperties- if the default system network properties shall be used
-
getContentType
-
setContentType
-
getProxyConfig
-
setProxyConfig
Sets the proxy configuration- Parameters:
proxyConfig- the proxyConfig to set
-
setSslProtocol
This method sets the SSL protocol to be used- Parameters:
sslProtocol- the ssl protocol to be used
-
setSslKeystore
public void setSslKeystore(eu.europa.esig.dss.model.DSSDocument sslKeyStore) Sets the SSL KeyStore- Parameters:
sslKeyStore-DSSDocument
-
setKeyStoreAsTrustMaterial
public void setKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial) Sets if the KeyStore shall be considered as a trust material (used for SSL connection)- Parameters:
loadKeyStoreAsTrustMaterial- if the KeyStore shall be considered as a trust material
-
setSslKeystoreType
-
setSslKeystorePassword
public void setSslKeystorePassword(char[] sslKeystorePassword) Sets the KeyStore password. Please note that the password shall be the same for the keystore and the extraction of a corresponding key.- Parameters:
sslKeystorePassword- char array representing the password
-
setSslTruststore
public void setSslTruststore(eu.europa.esig.dss.model.DSSDocument sslTrustStore) Sets the SSL trust store NOTE: different from KeyStore!- Parameters:
sslTrustStore-DSSDocument
-
setSslTruststorePassword
public void setSslTruststorePassword(char[] sslTruststorePassword) Sets the password for SSL truststore- Parameters:
sslTruststorePassword- char array representing a password string
-
setSslTruststoreType
-
getAuthenticationMap
Returns the current instance of the authentication map- Returns:
- a map between
HostConnectionandUserCredentials
-
setAuthenticationMap
Sets the authentication map NOTE: this method overrides the current instance ofauthenticationMap- Parameters:
authenticationMap- a map betweenHostConnectionandUserCredentials
-
addAuthentication
public CommonsDataLoader addAuthentication(HostConnection hostConnection, UserCredentials userCredentials) Adds authentication credentials to the existingauthenticationMap- Parameters:
hostConnection- host connection detailsuserCredentials- user login credentials- Returns:
- this (for fluent addAuthentication)
-
addAuthentication
public CommonsDataLoader addAuthentication(String host, int port, String scheme, String login, char[] password) Adds authentication credentials to the existingauthenticationMap- Parameters:
host- hostport- portscheme- schemelogin- loginpassword- password- Returns:
- this (for fluent addAuthentication)
-
getTargetPreferredAuthSchemes
-
setTargetPreferredAuthSchemes
-
setPreemptiveAuthentication
public void setPreemptiveAuthentication(boolean preemptiveAuthentication) Sets whether the preemptive authentication should be used. When set to TRUE, the client sends authentication details (i.e. user credentials) within the initial request to the remote host, instead of sending the credentials only after a request from the host. Please note that the preemptive authentication should not be used over an insecure connection. Default : FALSE (preemptive authentication is not used)- Parameters:
preemptiveAuthentication- whether the preemptive authentication should be used
-
setRetryStrategy
public void setRetryStrategy(org.apache.hc.client5.http.HttpRequestRetryStrategy retryStrategy) Sets a custom retry strategy- Parameters:
retryStrategy-HttpRequestRetryStrategy
-
getSupportedSSLProtocols
-
setSupportedSSLProtocols
-
getSupportedSSLCipherSuites
-
setSupportedSSLCipherSuites
-
getHostnameVerifier
-
setHostnameVerifier
Sets a customHostnameVerifier- Parameters:
hostnameVerifier-HostnameVerifier
-
getTrustStrategy
public org.apache.hc.core5.ssl.TrustStrategy getTrustStrategy()Gets the TrustStrategy- Returns:
TrustStrategy
-
setTrustStrategy
public void setTrustStrategy(org.apache.hc.core5.ssl.TrustStrategy trustStrategy) Sets theTrustStrategy- Parameters:
trustStrategy-TrustStrategy
-
getHttpClientResponseHandler
public org.apache.hc.core5.http.io.HttpClientResponseHandler<byte[]> getHttpClientResponseHandler()Returns theHttpClientResponseHandlerresponse handler- Returns:
HttpClientResponseHandler
-
setHttpClientResponseHandler
public void setHttpClientResponseHandler(org.apache.hc.core5.http.io.HttpClientResponseHandler<byte[]> httpClientResponseHandler) Sets theHttpClientResponseHandler<byte[]>response handler performing a processing of an HTTP client response and returns a byte array in case of success.- Parameters:
httpClientResponseHandler-HttpClientResponseHandler
-
setLdapTrustedHostnames
Sets a collection of allowed host names to perform an LDAP get request. The name of the host shall be defined in the complete form corresponding to the full domain name extracted from an extracted LDAP URL. E.g. "ldap.infonotary.com" for LDAP URL "ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com". NOTE: when not defined, all LDAP URLs will be accepted.- Parameters:
ldapTrustedHostnames- a collection of allowed host nameStrings
-
get
-
get
-
ldapGet
This method retrieves data using LDAP protocol. - CRL from given LDAP url, e.g. ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com - ex URL from AIA ldap://xadessrv.plugtests.net/CN=LevelBCAOK,OU=Plugtests_2015-2016,O=ETSI,C=FR?cACertificate;binary- Parameters:
urlString-String- Returns:
- byte array
-
initLdapContextEnvironment
-
ftpGet
-
fileGet
-
httpGet
This method retrieves data using HTTP or HTTPS protocol and 'get' method.- Parameters:
url- to access- Returns:
bytearray of obtained data or null
-
requestGet
-
requestGet
public eu.europa.esig.dss.model.http.ResponseEnvelope requestGet(String url, boolean includeResponseDetails) -
requestGet
public eu.europa.esig.dss.model.http.ResponseEnvelope requestGet(String url, boolean includeResponseDetails, boolean includeResponseBody) -
post
-
requestPost
-
requestPost
public eu.europa.esig.dss.model.http.ResponseEnvelope requestPost(String url, byte[] content, boolean includeResponseDetails) -
requestPost
public eu.europa.esig.dss.model.http.ResponseEnvelope requestPost(String url, byte[] content, boolean includeResponseDetails, boolean includeResponseBody) -
executeHttpRequest
@Deprecated protected eu.europa.esig.dss.model.http.ResponseEnvelope executeHttpRequest(org.apache.hc.client5.http.impl.classic.CloseableHttpClient client, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest) throws IOException Deprecated.since DSS 6.4. Please use#executeHttpRequest(client, httpRequest, false)method instead.ProcesseshttpRequestand returns the byte array representing the response's content- Parameters:
client-CloseableHttpClienthttpRequest-HttpUriRequest- Returns:
- byte array representing the response's content
- Throws:
IOException- if an exception occurs
-
executeHttpRequest
protected eu.europa.esig.dss.model.http.ResponseEnvelope executeHttpRequest(org.apache.hc.client5.http.impl.classic.CloseableHttpClient client, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, boolean includeResponseDetails, boolean includeResponseBody) throws IOException ProcesseshttpRequestand returns the byte array representing the response's content- Parameters:
client-CloseableHttpClienthttpRequest-HttpUriRequestincludeResponseDetails- whether the response details are to be includedincludeResponseBody- whether the response message body is to be included in the result- Returns:
- byte array representing the response's content
- Throws:
IOException- if an exception occurs
-
toHeadersMap
-
getHttpHost
protected org.apache.hc.core5.http.HttpHost getHttpHost(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest) Gets theHttpHost- Parameters:
httpRequest-HttpUriRequest- Returns:
HttpHost
-
getHttpContext
protected org.apache.hc.core5.http.protocol.HttpContext getHttpContext(org.apache.hc.core5.http.HttpHost httpHost) Gets theHttpContext- Parameters:
httpHost-HttpHost- Returns:
HttpContext
-
configurePreemptiveAuthentication
protected org.apache.hc.client5.http.protocol.HttpClientContext configurePreemptiveAuthentication(org.apache.hc.client5.http.protocol.HttpClientContext localContext, org.apache.hc.core5.http.HttpHost httpHost) This method is used to configure preemptive authentication process forHttpClientContext, when required- Parameters:
localContext-HttpClientContexthttpHost-HttpHost- Returns:
HttpClientContext
-
closeQuietly
protected void closeQuietly(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase httpRequest, org.apache.hc.client5.http.impl.classic.CloseableHttpClient client) Closes all the parameters quietly- Parameters:
httpRequest-HttpUriRequestBaseclient-CloseableHttpClient
-
getConnectionManager
protected org.apache.hc.client5.http.io.HttpClientConnectionManager getConnectionManager()Gets a configuredHttpClientConnectionManager- Returns:
HttpClientConnectionManager
-
getSocketConfig
protected org.apache.hc.core5.http.io.SocketConfig getSocketConfig()Gets a configuredSocketConfig- Returns:
SocketConfig
-
getSSLContextBuilder
protected org.apache.hc.core5.ssl.SSLContextBuilder getSSLContextBuilder()Gets a configuredSSLContextBuildercontaining an SSL connection trust configuration- Returns:
SSLContextBuilder
-
getTlsSocketStrategy
protected org.apache.hc.client5.http.ssl.TlsSocketStrategy getTlsSocketStrategy()Gets a configuredTlsSocketStrategy- Returns:
TlsSocketStrategy
-
getSSLKeyStore
Gets the SSL KeyStore- Returns:
KeyStore- Throws:
IOException- if IOException occursGeneralSecurityException- if GeneralSecurityException occurs
-
getSSLTrustStore
Gets the SSL Trusted KeyStore- Returns:
KeyStore- Throws:
IOException- if IOException occursGeneralSecurityException- if GeneralSecurityException occurs
-
getHttpRequest
protected org.apache.hc.client5.http.classic.methods.HttpGet getHttpRequest(String url) throws URISyntaxException Gets the HTTP request- Parameters:
url-Stringrequest url- Returns:
HttpGet- Throws:
URISyntaxException- if an exception occurs
-
getHttpClientBuilder
-
getHttpClient
-
getRequestConfigBuilder
protected org.apache.hc.client5.http.config.RequestConfig.Builder getRequestConfigBuilder()Gets a configuredRequestConfig.Builder- Returns:
RequestConfig.Builder
-
getRequestConfig
protected org.apache.hc.client5.http.config.RequestConfig getRequestConfig()Builds and gets aRequestConfig- Returns:
RequestConfig
-
getCredentialsProvider
protected org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider getCredentialsProvider()Builds and returns aBasicCredentialsProviderconfigured withauthenticationMap- Returns:
BasicCredentialsProvider
-