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 String
contentType
-
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 CommonsDataLoader
addAuthentication(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.DataAndUrl
get(List<String> urlStrings)
Execute a HTTP GET operation.List<Integer>
getAcceptedHttpStatus()
int
getConnectionsMaxPerRoute()
Used when theHttpClient
is created.int
getConnectionsMaxTotal()
Used when theHttpClient
is created.protected byte[]
getContent(org.apache.http.HttpEntity responseEntity)
String
getContentType()
HostnameVerifier
getHostnameVerifier()
protected org.apache.http.impl.client.CloseableHttpClient
getHttpClient(String url)
protected org.apache.http.impl.client.HttpClientBuilder
getHttpClientBuilder()
protected org.apache.http.client.methods.CloseableHttpResponse
getHttpResponse(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpUriRequest httpRequest)
ProxyConfig
getProxyConfig()
protected KeyStore
getSSLKeyStore()
protected KeyStore
getSSLTrustStore()
String[]
getSupportedSSLCipherSuites()
String[]
getSupportedSSLProtocols()
int
getTimeoutConnection()
Used when theHttpClient
is created.int
getTimeoutSocket()
Used when theHttpClient
is created.org.apache.http.conn.ssl.TrustStrategy
getTrustStrategy()
protected byte[]
httpGet(String url)
This method retrieves data using HTTP or HTTPS protocol and 'get' method.boolean
isRedirectsEnabled()
Used when theHttpClient
is created.protected byte[]
ldapGet(String urlString)
This method retrieves data using LDAP protocol.byte[]
post(String url, byte[] content)
Executes a HTTP POST operationvoid
propagateAuthentication(CommonsDataLoader commonsDataLoader)
This method allows to propagate the authentication information from the current object.protected byte[]
readHttpResponse(org.apache.http.client.methods.CloseableHttpResponse httpResponse)
void
setAcceptedHttpStatus(List<Integer> acceptedHttpStatus)
This allows to set a list of accepted http status.void
setConnectionsMaxPerRoute(int connectionsMaxPerRoute)
Used when theHttpClient
is created.void
setConnectionsMaxTotal(int connectionsMaxTotal)
Used when theHttpClient
is created.void
setContentType(String contentType)
This allows to set the content type.void
setHostnameVerifier(HostnameVerifier hostnameVerifier)
void
setKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial)
void
setProxyConfig(ProxyConfig proxyConfig)
void
setRedirectsEnabled(boolean redirectsEnabled)
Used when theHttpClient
is created.void
setRetryHandler(org.apache.http.client.HttpRequestRetryHandler retryHandler)
void
setServiceUnavailableRetryStrategy(org.apache.http.client.ServiceUnavailableRetryStrategy serviceUnavailableRetryStrategy)
void
setSslKeystore(DSSDocument sslKeyStore)
void
setSslKeystorePassword(String sslKeystorePassword)
void
setSslKeystoreType(String sslKeystoreType)
void
setSslProtocol(String sslProtocol)
This method sets the SSL protocol to be used ('TLSv1.2' by default)void
setSslTruststore(DSSDocument sslTrustStore)
void
setSslTruststorePassword(String sslTruststorePassword)
void
setSslTruststoreType(String sslTruststoreType)
void
setSupportedSSLCipherSuites(String[] supportedSSLCipherSuites)
void
setSupportedSSLProtocols(String[] supportedSSLProtocols)
void
setTimeoutConnection(int timeoutConnection)
Used when theHttpClient
is created.void
setTimeoutSocket(int timeoutSocket)
Used when theHttpClient
is created.void
setTrustStrategy(org.apache.http.conn.ssl.TrustStrategy trustStrategy)
-
Field Details
-
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
- Throws:
IOException
GeneralSecurityException
-
getSSLTrustStore
- Throws:
IOException
GeneralSecurityException
-
getHttpClientBuilder
protected org.apache.http.impl.client.HttpClientBuilder getHttpClientBuilder() -
getHttpClient
-
get
Description copied from interface:DataLoader
Execute a HTTP GET operation.- Specified by:
get
in interfaceDataLoader
- Parameters:
urlString
- the url to access- Returns:
byte
array of obtained data or null- Throws:
DSSException
- in case of DataLoader error
-
get
Description copied from interface:DataLoader
Execute 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:
get
in interfaceDataLoader
- Parameters:
urlStrings
-List
ofString
s representing the URLs to be used in sequential way to obtain the data.- Returns:
DataAndUrl
representing 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:
get
in interfaceDataLoader
- Parameters:
url
- to accessrefresh
- if true indicates that the cached data should be refreshed- Returns:
byte
array 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
-- Returns:
- byte array
- Throws:
DSSException
- in case of DataLoader error
-
ftpGet
This method retrieves data using FTP protocol .- Parameters:
urlString
-String
url to retrieve data from- Returns:
- byte array
- Throws:
DSSException
- in case of file download error
-
fileGet
- Throws:
DSSException
-
httpGet
This method retrieves data using HTTP or HTTPS protocol and 'get' method.- Parameters:
url
- to access- Returns:
byte
array of obtained data or null- Throws:
DSSException
-
post
Description copied from interface:DataLoader
Executes a HTTP POST operation- Specified by:
post
in interfaceDataLoader
- Parameters:
url
- to accesscontent
- the content to post- Returns:
byte
array 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
- Throws:
IOException
-
getTimeoutConnection
public int getTimeoutConnection()Used when theHttpClient
is created.- Returns:
- the value (millis)
-
setTimeoutConnection
public void setTimeoutConnection(int timeoutConnection)Used when theHttpClient
is created.- Parameters:
timeoutConnection
- the value (millis)
-
getTimeoutSocket
public int getTimeoutSocket()Used when theHttpClient
is created.- Returns:
- the value (millis)
-
setTimeoutSocket
public void setTimeoutSocket(int timeoutSocket)Used when theHttpClient
is created.- Parameters:
timeoutSocket
- the value (millis)
-
getConnectionsMaxTotal
public int getConnectionsMaxTotal()Used when theHttpClient
is created.- Returns:
- maximum number of connections
-
setConnectionsMaxTotal
public void setConnectionsMaxTotal(int connectionsMaxTotal)Used when theHttpClient
is created.- Parameters:
connectionsMaxTotal
- maximum number of connections
-
getConnectionsMaxPerRoute
public int getConnectionsMaxPerRoute()Used when theHttpClient
is created.- Returns:
- maximum number of connections per one route
-
setConnectionsMaxPerRoute
public void setConnectionsMaxPerRoute(int connectionsMaxPerRoute)Used when theHttpClient
is created.- Parameters:
connectionsMaxPerRoute
- maximum number of connections per one route
-
isRedirectsEnabled
public boolean isRedirectsEnabled()Used when theHttpClient
is created.- Returns:
- true if http redirects are allowed
-
setRedirectsEnabled
public void setRedirectsEnabled(boolean redirectsEnabled)Used when theHttpClient
is created.- Parameters:
redirectsEnabled
- true if http redirects are allowed
-
getContentType
- Returns:
- the contentType
-
setContentType
This allows to set the content type. Example: Content-Type "application/ocsp-request"- Specified by:
setContentType
in interfaceDataLoader
- Parameters:
contentType
-
-
getAcceptedHttpStatus
-
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
-
setKeyStoreAsTrustMaterial
public void setKeyStoreAsTrustMaterial(boolean loadKeyStoreAsTrustMaterial) -
setSslKeystoreType
-
setSslKeystorePassword
-
setSslTruststore
-
setSslTruststorePassword
-
setSslTruststoreType
-
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
This method allows to propagate the authentication information from the current object.- Parameters:
commonsDataLoader
-CommonsDataLoader
to 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
-
setSupportedSSLProtocols
-
getSupportedSSLCipherSuites
-
setSupportedSSLCipherSuites
-
getHostnameVerifier
-
setHostnameVerifier
-
getTrustStrategy
public org.apache.http.conn.ssl.TrustStrategy getTrustStrategy() -
setTrustStrategy
public void setTrustStrategy(org.apache.http.conn.ssl.TrustStrategy trustStrategy)
-