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 StringcontentType
-
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)protected byte[]fileGet(String urlString)protected 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()intgetConnectionsMaxPerRoute()Used when theHttpClientis created.intgetConnectionsMaxTotal()Used when theHttpClientis created.protected byte[]getContent(org.apache.http.HttpEntity responseEntity)StringgetContentType()HostnameVerifiergetHostnameVerifier()protected org.apache.http.impl.client.CloseableHttpClientgetHttpClient(String url)protected org.apache.http.impl.client.HttpClientBuildergetHttpClientBuilder()protected org.apache.http.client.methods.CloseableHttpResponsegetHttpResponse(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpUriRequest httpRequest)ProxyConfiggetProxyConfig()protected KeyStoregetSSLKeyStore()protected KeyStoregetSSLTrustStore()String[]getSupportedSSLCipherSuites()String[]getSupportedSSLProtocols()intgetTimeoutConnection()Used when theHttpClientis created.intgetTimeoutSocket()Used when theHttpClientis created.org.apache.http.conn.ssl.TrustStrategygetTrustStrategy()protected byte[]httpGet(String url)This method retrieves data using HTTP or HTTPS protocol and 'get' method.booleanisRedirectsEnabled()Used when theHttpClientis created.protected byte[]ldapGet(String urlString)This method retrieves data using LDAP protocol.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)voidsetAcceptedHttpStatus(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)voidsetKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial)voidsetProxyConfig(ProxyConfig proxyConfig)voidsetRedirectsEnabled(boolean redirectsEnabled)Used when theHttpClientis created.voidsetRetryHandler(org.apache.http.client.HttpRequestRetryHandler retryHandler)voidsetServiceUnavailableRetryStrategy(org.apache.http.client.ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy)voidsetSslKeystorePassword(String sslKeystorePassword)voidsetSslKeystorePath(String sslKeystorePath)voidsetSslKeystoreType(String sslKeystoreType)voidsetSslProtocol(String sslProtocol)This method sets the SSL protocol to be used ('TLSv1.2' by default)voidsetSslTruststorePassword(String sslTruststorePassword)voidsetSslTruststorePath(String sslTruststorePath)voidsetSslTruststoreType(String sslTruststoreType)voidsetSupportedSSLCipherSuites(String[] supportedSSLCipherSuites)voidsetSupportedSSLProtocols(String[] supportedSSLProtocols)voidsetTimeoutConnection(int timeoutConnection)Used when theHttpClientis created.voidsetTimeoutSocket(int timeoutSocket)Used when theHttpClientis created.voidsetTrustStrategy(org.apache.http.conn.ssl.TrustStrategy trustStrategy)
-
-
-
Field Detail
-
contentType
protected String contentType
-
-
Constructor Detail
-
CommonsDataLoader
public CommonsDataLoader()
The default constructor for CommonsDataLoader.
-
CommonsDataLoader
public CommonsDataLoader(String contentType)
The constructor for CommonsDataLoader with defined content-type.- Parameters:
contentType- The content type of each request
-
-
Method Detail
-
getSSLKeyStore
protected KeyStore getSSLKeyStore() throws IOException, GeneralSecurityException
- Throws:
IOExceptionGeneralSecurityException
-
getSSLTrustStore
protected KeyStore getSSLTrustStore() throws IOException, GeneralSecurityException
- Throws:
IOExceptionGeneralSecurityException
-
getHttpClientBuilder
protected org.apache.http.impl.client.HttpClientBuilder getHttpClientBuilder()
-
getHttpClient
protected org.apache.http.impl.client.CloseableHttpClient getHttpClient(String url)
-
get
public byte[] get(String urlString)
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
-
get
public DataLoader.DataAndUrl get(List<String> urlStrings)
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
-
get
public byte[] get(String url, boolean refresh)
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
-
ldapGet
protected 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?cACertificate;binary- Parameters:
urlString-- Returns:
-
ftpGet
protected byte[] ftpGet(String urlString)
This method retrieves data using FTP protocol .- Parameters:
urlString-- Returns:
-
fileGet
protected byte[] fileGet(String urlString)
-
httpGet
protected byte[] httpGet(String url)
This method retrieves data using HTTP or HTTPS protocol and 'get' method.- Parameters:
url- to access- Returns:
bytearray of obtained data or null
-
post
public byte[] post(String url, byte[] content)
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 IOException- Throws:
IOException
-
readHttpResponse
protected byte[] readHttpResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse) throws IOException- Throws:
IOException
-
getContent
protected byte[] getContent(org.apache.http.HttpEntity responseEntity) throws IOException- Throws:
IOException
-
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
-
getContentType
public String getContentType()
- Returns:
- the contentType
-
setContentType
public void setContentType(String contentType)
This allows to set the content type. Example: Content-Type "application/ocsp-request"- Specified by:
setContentTypein interfaceDataLoader- Parameters:
contentType-
-
setAcceptedHttpStatus
public void setAcceptedHttpStatus(List<Integer> acceptedHttpStatus)
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
public ProxyConfig getProxyConfig()
- Returns:
- associated
ProxyConfig
-
setProxyConfig
public void setProxyConfig(ProxyConfig proxyConfig)
- Parameters:
proxyConfig- the proxyConfig to set
-
setSslProtocol
public void setSslProtocol(String sslProtocol)
This method sets the SSL protocol to be used ('TLSv1.2' by default)- Parameters:
sslProtocol- the ssl protocol to be used
-
setSslKeystorePath
public void setSslKeystorePath(String sslKeystorePath)
-
setKeyStoreAsTrustMaterial
public void setKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial)
-
setSslKeystoreType
public void setSslKeystoreType(String sslKeystoreType)
-
setSslKeystorePassword
public void setSslKeystorePassword(String sslKeystorePassword)
-
setSslTruststorePath
public void setSslTruststorePath(String sslTruststorePath)
-
setSslTruststorePassword
public void setSslTruststorePassword(String sslTruststorePassword)
-
setSslTruststoreType
public void setSslTruststoreType(String sslTruststoreType)
-
addAuthentication
public CommonsDataLoader addAuthentication(String host, int port, String scheme, String login, String password)
- Parameters:
host- hostport- portscheme- schemelogin- loginpassword- password- Returns:
- this for fluent addAuthentication
-
propagateAuthentication
public void propagateAuthentication(CommonsDataLoader commonsDataLoader)
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)
-
setServiceUnavailableRetryStrategy
public void setServiceUnavailableRetryStrategy(org.apache.http.client.ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy)
-
getSupportedSSLProtocols
public String[] getSupportedSSLProtocols()
-
setSupportedSSLProtocols
public void setSupportedSSLProtocols(String[] supportedSSLProtocols)
-
getSupportedSSLCipherSuites
public String[] getSupportedSSLCipherSuites()
-
setSupportedSSLCipherSuites
public void setSupportedSSLCipherSuites(String[] supportedSSLCipherSuites)
-
getHostnameVerifier
public HostnameVerifier getHostnameVerifier()
-
setHostnameVerifier
public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
-
getTrustStrategy
public org.apache.http.conn.ssl.TrustStrategy getTrustStrategy()
-
setTrustStrategy
public void setTrustStrategy(org.apache.http.conn.ssl.TrustStrategy trustStrategy)
-
-