Class CommonsDataLoader
java.lang.Object
eu.europa.esig.dss.service.http.commons.CommonsDataLoader
- All Implemented Interfaces:
DataLoader,Serializable
- Direct Known Subclasses:
OCSPDataLoader,TimestampDataLoader
public class CommonsDataLoader extends Object implements DataLoader
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:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.europa.esig.dss.spi.client.http.DataLoader
DataLoader.DataAndUrl -
Field Summary
Fields Modifier and Type Field Description protected StringcontentTypeThe content type value -
Constructor Summary
Constructors Constructor Description CommonsDataLoader()The default constructor for CommonsDataLoader.CommonsDataLoader(String contentType)The constructor for CommonsDataLoader with defined content-type. -
Method Summary
Modifier and Type Method Description CommonsDataLoaderaddAuthentication(String host, int port, String scheme, String login, String password)Addz authentication credentialsprotected voidcloseQuietly(org.apache.http.client.methods.HttpRequestBase httpRequest, org.apache.http.client.methods.CloseableHttpResponse httpResponse, org.apache.http.impl.client.CloseableHttpClient client)Closes all the parameters quietlyprotected byte[]fileGet(String urlString)Gets the file content by its URLprotected byte[]ftpGet(String urlString)This method retrieves data using FTP protocol .byte[]get(String urlString)Execute a HTTP GET operation.byte[]get(String url, boolean refresh)This method is useful only with the cache handling implementation of theDataLoader.DataLoader.DataAndUrlget(List<String> urlStrings)Execute a HTTP GET operation.List<Integer>getAcceptedHttpStatus()Returns a list of accepted HTTP status numbersintgetConnectionsMaxPerRoute()Used when theHttpClientis created.intgetConnectionsMaxTotal()Used when theHttpClientis created.protected byte[]getContent(org.apache.http.HttpEntity responseEntity)Gets content of the responseStringgetContentType()HostnameVerifiergetHostnameVerifier()Gets the hostname verifierprotected org.apache.http.impl.client.CloseableHttpClientgetHttpClient(String url)Gets the HTTP clientprotected org.apache.http.impl.client.HttpClientBuildergetHttpClientBuilder(String url)Gets theHttpClientBuilderfor the urlprotected org.apache.http.protocol.HttpContextgetHttpContext(org.apache.http.HttpHost targetHost)Gets theHttpContextprotected org.apache.http.HttpHostgetHttpHost(org.apache.http.client.methods.HttpUriRequest httpRequest)Gets theHttpHostprotected org.apache.http.client.methods.HttpGetgetHttpRequest(String url)Gets the HTTP requestprotected org.apache.http.client.methods.CloseableHttpResponsegetHttpResponse(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpUriRequest httpRequest)ProcesseshttpRequestand returns theCloseableHttpResponseProxyConfiggetProxyConfig()protected KeyStoregetSSLKeyStore()Gets the SSL KeyStoreprotected KeyStoregetSSLTrustStore()Gets the SSL Trusted KeyStoreString[]getSupportedSSLCipherSuites()Gets supported SSL Cipher SuitesString[]getSupportedSSLProtocols()Gets supported SSL protocolsintgetTimeoutConnection()Used when theHttpClientis created.intgetTimeoutSocket()Used when theHttpClientis created.org.apache.http.conn.ssl.TrustStrategygetTrustStrategy()Gets the TrustStrategyprotected byte[]httpGet(String url)This method retrieves data using HTTP or HTTPS protocol and 'get' method.booleanisRedirectsEnabled()Used when theHttpClientis created.booleanisUseSystemProperties()Gets if the default system network properties shall be usedprotected byte[]ldapGet(String urlString)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[]post(String url, byte[] content)Executes a HTTP POST operationvoidpropagateAuthentication(CommonsDataLoader commonsDataLoader)This method allows to propagate the authentication information from the current object.protected byte[]readHttpResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse)Reads the HTTP responsevoidsetAcceptedHttpStatus(List<Integer> acceptedHttpStatus)This allows to set a list of accepted http status.voidsetConnectionsMaxPerRoute(int connectionsMaxPerRoute)Used when theHttpClientis created.voidsetConnectionsMaxTotal(int connectionsMaxTotal)Used when theHttpClientis created.voidsetContentType(String contentType)This allows to set the content type.voidsetHostnameVerifier(HostnameVerifier hostnameVerifier)Sets a customHostnameVerifiervoidsetKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial)Sets if the KeyStore shall be considered as a trust material (used for SSL connection)voidsetProxyConfig(ProxyConfig proxyConfig)voidsetRedirectsEnabled(boolean redirectsEnabled)Used when theHttpClientis created.voidsetRetryHandler(org.apache.http.client.HttpRequestRetryHandler retryHandler)Sets a custom retry handlervoidsetServiceUnavailableRetryStrategy(org.apache.http.client.ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy)Sets customServiceUnavailableRetryStrategyvoidsetSslKeystore(DSSDocument sslKeyStore)Sets the SSL KeyStorevoidsetSslKeystorePassword(String sslKeystorePassword)Sets the KeyStore passwordvoidsetSslKeystoreType(String sslKeystoreType)Sets the SSL KeyStore typevoidsetSslProtocol(String sslProtocol)This method sets the SSL protocol to be used ('TLSv1.2' by default)voidsetSslTruststore(DSSDocument sslTrustStore)Sets the SSL trust store NOTE: different from KeyStore!voidsetSslTruststorePassword(String 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 protocolsvoidsetTimeoutConnection(int timeoutConnection)Used when theHttpClientis created.voidsetTimeoutSocket(int timeoutSocket)Used when theHttpClientis created.voidsetTrustStrategy(org.apache.http.conn.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!
-
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
-
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.http.client.methods.HttpGet getHttpRequest(String url) throws URISyntaxExceptionGets the HTTP request- Parameters:
url-Stringrequest url- Returns:
HttpGet- Throws:
URISyntaxException- if an exception occurs
-
getHttpClientBuilder
Gets theHttpClientBuilderfor the url- Parameters:
url-Stringrequest url- Returns:
HttpClientBuilder
-
getHttpClient
Gets the HTTP client- Parameters:
url-Stringrequest url- Returns:
CloseableHttpClient
-
get
Description copied from interface:DataLoaderExecute a HTTP GET operation.- Specified by:
getin interfaceDataLoader- Parameters:
urlString- the url to access- Returns:
bytearray of obtained data or null- Throws:
DSSException- in case of DataLoader error
-
get
Description copied from interface:DataLoaderExecute a HTTP GET operation. This method is used when many URls are available to access the same resource. The operation stops after the first successful download.- Specified by:
getin interfaceDataLoader- Parameters:
urlStrings-ListofStrings representing the URLs to be used in sequential way to obtain the data.- Returns:
DataAndUrlrepresenting the array of obtained data and used url, or null- Throws:
DSSException- in case of DataLoader error
-
get
This method is useful only with the cache handling implementation of theDataLoader.- Specified by:
getin interfaceDataLoader- Parameters:
url- to accessrefresh- if true indicates that the cached data should be refreshed- Returns:
bytearray of obtained data- Throws:
DSSException- in case of DataLoader error
-
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
- Throws:
DSSException- in case of DataLoader error
-
ftpGet
This method retrieves data using FTP protocol .- Parameters:
urlString-Stringurl to retrieve data from- Returns:
- byte array
- Throws:
DSSException- in case of file download error
-
fileGet
Gets the file content by its URL- Parameters:
urlString-Stringto the file- Returns:
- byte array of the file content
-
httpGet
This method retrieves data using HTTP or HTTPS protocol and 'get' method.- Parameters:
url- to access- Returns:
bytearray of obtained data or null- Throws:
DSSException
-
closeQuietly
protected void closeQuietly(org.apache.http.client.methods.HttpRequestBase httpRequest, org.apache.http.client.methods.CloseableHttpResponse httpResponse, org.apache.http.impl.client.CloseableHttpClient client)Closes all the parameters quietly- Parameters:
httpRequest-HttpRequestBasehttpResponse-CloseableHttpResponseclient-CloseableHttpClient
-
post
Description copied from interface:DataLoaderExecutes a HTTP POST operation- Specified by:
postin interfaceDataLoader- Parameters:
url- to accesscontent- the content to post- Returns:
bytearray of obtained data
-
getHttpResponse
protected org.apache.http.client.methods.CloseableHttpResponse getHttpResponse(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpUriRequest httpRequest) throws IOExceptionProcesseshttpRequestand returns theCloseableHttpResponse- Parameters:
client-CloseableHttpClienthttpRequest-HttpUriRequest- Returns:
CloseableHttpResponse- Throws:
IOException- if an exception occurs
-
getHttpHost
protected org.apache.http.HttpHost getHttpHost(org.apache.http.client.methods.HttpUriRequest httpRequest)Gets theHttpHost- Parameters:
httpRequest-HttpUriRequest- Returns:
HttpHost
-
getHttpContext
protected org.apache.http.protocol.HttpContext getHttpContext(org.apache.http.HttpHost targetHost)Gets theHttpContext- Parameters:
targetHost-HttpHost- Returns:
HttpContext
-
readHttpResponse
protected byte[] readHttpResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws IOExceptionReads the HTTP response- Parameters:
httpResponse-CloseableHttpResponse- Returns:
- the response's content
- Throws:
IOException- if an exception occurs
-
getContent
Gets content of the response- Parameters:
responseEntity-HttpEntity- Returns:
- byte array
- Throws:
IOException- if an exception occurs
-
getTimeoutConnection
public int getTimeoutConnection()Used when theHttpClientis created.- Returns:
- the value (millis)
-
setTimeoutConnection
public void setTimeoutConnection(int timeoutConnection)Used when theHttpClientis created.- Parameters:
timeoutConnection- the value (millis)
-
getTimeoutSocket
public int getTimeoutSocket()Used when theHttpClientis created.- Returns:
- the value (millis)
-
setTimeoutSocket
public void setTimeoutSocket(int timeoutSocket)Used when theHttpClientis created.- Parameters:
timeoutSocket- the value (millis)
-
getConnectionsMaxTotal
public int getConnectionsMaxTotal()Used when theHttpClientis created.- Returns:
- maximum number of connections
-
setConnectionsMaxTotal
public void setConnectionsMaxTotal(int connectionsMaxTotal)Used when theHttpClientis created.- Parameters:
connectionsMaxTotal- maximum number of connections
-
getConnectionsMaxPerRoute
public int getConnectionsMaxPerRoute()Used when theHttpClientis created.- Returns:
- maximum number of connections per one route
-
setConnectionsMaxPerRoute
public void setConnectionsMaxPerRoute(int connectionsMaxPerRoute)Used when theHttpClientis created.- Parameters:
connectionsMaxPerRoute- maximum number of connections per one route
-
isRedirectsEnabled
public boolean isRedirectsEnabled()Used when theHttpClientis created.- Returns:
- true if http redirects are allowed
-
setRedirectsEnabled
public void setRedirectsEnabled(boolean redirectsEnabled)Used when theHttpClientis created.- 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
- Returns:
- the contentType
-
setContentType
This allows to set the content type. Example: Content-Type "application/ocsp-request"- Specified by:
setContentTypein interfaceDataLoader- Parameters:
contentType-String
-
getAcceptedHttpStatus
Returns a list of accepted HTTP status numbers- Returns:
- a list of accepted HTTP status numbers
-
setAcceptedHttpStatus
This allows to set a list of accepted http status. Example: 200 (OK)- Parameters:
acceptedHttpStatus- a list of integer which correspond to the http status code
-
getProxyConfig
- Returns:
- associated
ProxyConfig
-
setProxyConfig
- Parameters:
proxyConfig- the proxyConfig to set
-
setSslProtocol
This method sets the SSL protocol to be used ('TLSv1.2' by default)- Parameters:
sslProtocol- the ssl protocol to be used
-
setSslKeystore
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
Sets the SSL KeyStore type- Parameters:
sslKeystoreType-String
-
setSslKeystorePassword
Sets the KeyStore password- Parameters:
sslKeystorePassword-String
-
setSslTruststore
Sets the SSL trust store NOTE: different from KeyStore!- Parameters:
sslTrustStore-DSSDocument
-
setSslTruststorePassword
Sets the password for SSL truststore- Parameters:
sslTruststorePassword-String
-
setSslTruststoreType
Sets the SSL TrustStore type- Parameters:
sslTruststoreType-String
-
addAuthentication
public CommonsDataLoader addAuthentication(String host, int port, String scheme, String login, String password)Addz authentication credentials- Parameters:
host- hostport- portscheme- schemelogin- loginpassword- password- Returns:
- this for fluent addAuthentication
-
propagateAuthentication
This method allows to propagate the authentication information from the current object.- Parameters:
commonsDataLoader-CommonsDataLoaderto be initialized with authentication information
-
setRetryHandler
public void setRetryHandler(org.apache.http.client.HttpRequestRetryHandler retryHandler)Sets a custom retry handler- Parameters:
retryHandler-HttpRequestRetryHandler
-
getSupportedSSLProtocols
Gets supported SSL protocols- Returns:
- an array if
Strings
-
setSupportedSSLProtocols
Sets supported SSL protocols- Parameters:
supportedSSLProtocols- an array ifStrings
-
getSupportedSSLCipherSuites
Gets supported SSL Cipher Suites- Returns:
- an array if
Strings
-
setSupportedSSLCipherSuites
Sets supported SSL Cipher Suites- Parameters:
supportedSSLCipherSuites- an array ifStrings
-
getHostnameVerifier
Gets the hostname verifier- Returns:
HostnameVerifier
-
setHostnameVerifier
Sets a customHostnameVerifier- Parameters:
hostnameVerifier-HostnameVerifier
-
getTrustStrategy
public org.apache.http.conn.ssl.TrustStrategy getTrustStrategy()Gets the TrustStrategy- Returns:
TrustStrategy
-
setTrustStrategy
public void setTrustStrategy(org.apache.http.conn.ssl.TrustStrategy trustStrategy)Sets theTrustStrategy- Parameters:
trustStrategy-TrustStrategy
-