Class UtilsHTTP


  • public final class UtilsHTTP
    extends java.lang.Object

    Utilities 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.String HEADER_ACCEPT_ENCODING
      Constant attribute that represents the "Accept-Encoding" header.
      static java.lang.String HEADER_USER_AGENT
      Constant attribute that represents the "User-Agent" header.
      static java.lang.String HTTP_HEADER_USER_AGENT_HTTPCLIENT
      Constant attribute that represents the Apache-HttpClient User-Agent Header.
      static java.lang.String HTTP_HEADER_USER_AGENT_JAKARTA
      Constant attribute that represents the Jakarta Commons-HttpClient User-Agent Header.
      static java.lang.String HTTP_SCHEME
      Constant attribute that represents the representation string of the scheme http.
      static java.lang.String HTTPS_SCHEME
      Constant attribute that represents the representation string of the scheme https.
      static java.lang.String OUTPUT_CONTENT_TYPE_OCSP_RESPONSE
      Constant 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 the HttpClient library.
      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 the HttpClient library.
      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 boolean isUriOfSchemeHTTP​(java.lang.String uriString, int checkMode)
      This method determines whether a given URI scheme is HTTP or HTTPS.
      static boolean isUriOfSchemeHTTP​(java.net.URI uri, int checkMode)
      This method determines whether a given URI scheme is HTTP or HTTPS.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 CommonUtilsException
        Method that makes a HTTP POST request to certain URL and obtains the response as a bytes array. The input data will be imposed as RequestEntity using the HttpClient library 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 the RequestEntity.
        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 CommonUtilsException
        Method that allows download the data from a URI using the HttpClient library.
        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 CommonUtilsException
        Method that allows download the data from a URI using the HttpClient library.
        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.