Package es.gob.afirma.tsl.utils
Class UtilsHTTP
- java.lang.Object
-
- es.gob.afirma.tsl.utils.UtilsHTTP
-
public final class UtilsHTTP extends java.lang.ObjectUtilities class relating to connections and HTTP/S protocol.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
- Version:
- 1.2, 18/04/2022.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHEADER_ACCEPT_ENCODINGConstant attribute that represents the "Accept-Encoding" header.static java.lang.StringHEADER_USER_AGENTConstant attribute that represents the "User-Agent" header.static java.lang.StringHTTP_HEADER_USER_AGENT_HTTPCLIENTConstant attribute that represents the Apache-HttpClient User-Agent Header.static java.lang.StringHTTP_HEADER_USER_AGENT_JAKARTAConstant attribute that represents the Jakarta Commons-HttpClient User-Agent Header.static java.lang.StringHTTP_SCHEMEConstant attribute that represents the representation string of the scheme http.static java.lang.StringHTTPS_SCHEMEConstant attribute that represents the representation string of the scheme https.static java.lang.StringOUTPUT_CONTENT_TYPE_OCSP_RESPONSEConstant attribute that represents the value of the output 'Content-type' for http request by post.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getDataFromURI(java.lang.String path, int connectionTimeout, int readTimeout)Method that allows download the data from a URI using theHttpClientlibrary.static byte[]getDataFromURI(java.lang.String uriString, int connectionTimeout, int readTimeout, java.lang.String user, java.lang.String password, java.util.Map<java.lang.String,java.lang.String> headersMap)Method that allows download the data from a URI using theHttpClientlibrary.static byte[]getResponseByHttpPostWithEntity(java.lang.String uriString, int connectionTimeout, int readTimeout, byte[] inputData, java.lang.String inputContentType, java.lang.String outputContentType, java.lang.String user, java.lang.String password)Method that makes a HTTP POST request to certain URL and obtains the response as a bytes array.static booleanisUriOfSchemeHTTP(java.lang.String uriString, int checkMode)This method determines whether a given URI scheme is HTTP or HTTPS.static booleanisUriOfSchemeHTTP(java.net.URI uri, int checkMode)This method determines whether a given URI scheme is HTTP or HTTPS.
-
-
-
Field Detail
-
HTTP_SCHEME
public static final java.lang.String HTTP_SCHEME
Constant attribute that represents the representation string of the scheme http.- See Also:
- Constant Field Values
-
HTTPS_SCHEME
public static final java.lang.String HTTPS_SCHEME
Constant attribute that represents the representation string of the scheme https.- See Also:
- Constant Field Values
-
HTTP_HEADER_USER_AGENT_HTTPCLIENT
public static final java.lang.String HTTP_HEADER_USER_AGENT_HTTPCLIENT
Constant attribute that represents the Apache-HttpClient User-Agent Header.- See Also:
- Constant Field Values
-
HTTP_HEADER_USER_AGENT_JAKARTA
public static final java.lang.String HTTP_HEADER_USER_AGENT_JAKARTA
Constant attribute that represents the Jakarta Commons-HttpClient User-Agent Header.- See Also:
- Constant Field Values
-
OUTPUT_CONTENT_TYPE_OCSP_RESPONSE
public static final java.lang.String OUTPUT_CONTENT_TYPE_OCSP_RESPONSE
Constant attribute that represents the value of the output 'Content-type' for http request by post.- See Also:
- Constant Field Values
-
HEADER_USER_AGENT
public static final java.lang.String HEADER_USER_AGENT
Constant attribute that represents the "User-Agent" header.- See Also:
- Constant Field Values
-
HEADER_ACCEPT_ENCODING
public static final java.lang.String HEADER_ACCEPT_ENCODING
Constant attribute that represents the "Accept-Encoding" header.- See Also:
- Constant Field Values
-
-
Method Detail
-
isUriOfSchemeHTTP
public static boolean isUriOfSchemeHTTP(java.lang.String uriString, int checkMode)This method determines whether a given URI scheme is HTTP or HTTPS.- Parameters:
uriString- String representation of the URI to analyze.checkMode- Int that determines the check mode operation:- 0: Check if the URI is HTTP OR HTTPS.
- 1: Check if the URI is HTTP.
- 2: Check if the URI is HTTPS.
- Returns:
- true if the scheme of the URI is HTTP or HTTPS, otherwise false.
-
isUriOfSchemeHTTP
public static boolean isUriOfSchemeHTTP(java.net.URI uri, int checkMode)This method determines whether a given URI scheme is HTTP or HTTPS.- Parameters:
uri- Representation of the URI to analyze.checkMode- Int that determines the check mode operation:- 0: Check if the URI is HTTP OR HTTPS.
- 1: Check if the URI is HTTP.
- 2: Check if the URI is HTTPS.
- Returns:
- true if the scheme of the URI is HTTP or HTTPS, otherwise false.
-
getResponseByHttpPostWithEntity
public static byte[] getResponseByHttpPostWithEntity(java.lang.String uriString, int connectionTimeout, int readTimeout, byte[] inputData, java.lang.String inputContentType, java.lang.String outputContentType, java.lang.String user, java.lang.String password) throws CommonUtilsExceptionMethod that makes a HTTP POST request to certain URL and obtains the response as a bytes array. The input data will be imposed asRequestEntityusing theHttpClientlibrary provided by Jakarta.- Parameters:
uriString- Parameter that represents the connection path to the resource.connectionTimeout- Parameter that represents the timeout for the connection.readTimeout- Parameter that represents the timeout for the data reading.inputData- Parameter that represents the data to insert inside theRequestEntity.inputContentType- Parameter that represents the content-type of the request.outputContentType- Parameter that represents the content-type of the response.user- Parameter that represents the user for authentication.password- Parameter that represents the password for authentication.- Returns:
- a bytes array that represents the content of the resource indicated in the URL.
- Throws:
CommonUtilsException- If there is some error with the input parameters or the connection.
-
getDataFromURI
public static byte[] getDataFromURI(java.lang.String uriString, int connectionTimeout, int readTimeout, java.lang.String user, java.lang.String password, java.util.Map<java.lang.String,java.lang.String> headersMap) throws CommonUtilsExceptionMethod that allows download the data from a URI using theHttpClientlibrary.- Parameters:
uriString- Parameter that represents the connection path (URI) to the resource.connectionTimeout- Parameter that represents the timeout for the connection.readTimeout- Parameter that represents the timeout for the data reading.user- Parameter that represents the user for authentication.password- Parameter that represents the password for authentication.headersMap- Parameter that represents a list of specific headers for the HTTP/S connection.- Returns:
- a byte array that represents the content of the resource obtained from the URI.
- Throws:
CommonUtilsException- In case of some error getting the resource.
-
getDataFromURI
public static byte[] getDataFromURI(java.lang.String path, int connectionTimeout, int readTimeout) throws CommonUtilsExceptionMethod that allows download the data from a URI using theHttpClientlibrary.- Parameters:
path- Parameter that represents the connection path (URI) to the resource.connectionTimeout- Parameter that represents the timeout for the connection.readTimeout- Parameter that represents the timeout for the data reading.- Returns:
- a byte array that represents the content of the resource obtained from the URI.
- Throws:
CommonUtilsException- In case of some error getting the resource.
-
-