Class ConfigHttpService

    • Field Detail

      • log

        protected transient org.apache.logging.log4j.Logger log
    • Constructor Detail

      • ConfigHttpService

        public ConfigHttpService()
    • Method Detail

      • init

        @PostConstruct
        public void init()
      • getOpenidConfigurationUrl

        public static String getOpenidConfigurationUrl()
      • getHttpsClient

        public org.apache.http.impl.client.CloseableHttpClient getHttpsClient()
      • getHttpsClient

        public org.apache.http.impl.client.CloseableHttpClient getHttpsClient​(org.apache.http.client.config.RequestConfig requestConfig)
      • getHttpsClient

        public org.apache.http.impl.client.CloseableHttpClient getHttpsClient​(org.apache.http.conn.routing.HttpRoutePlanner routerPlanner)
      • getHttpsClient

        public org.apache.http.impl.client.CloseableHttpClient getHttpsClient​(org.apache.http.client.config.RequestConfig requestConfig,
                                                                              org.apache.http.conn.routing.HttpRoutePlanner routerPlanner)
      • createHttpsClientWithTlsPolicy

        public org.apache.http.impl.client.CloseableHttpClient createHttpsClientWithTlsPolicy​(String[] enabledProtocols,
                                                                                              String[] allowedCipherSuites)
                                                                                       throws NoSuchAlgorithmException,
                                                                                              KeyManagementException
        Create a CloseableHttpClient configured with an optional TLS protocol and cipher-suite policy. If `enabledProtocols` is null or empty, the returned client uses the JVM/default TLS configuration.
        Parameters:
        enabledProtocols - the TLS protocols to enable (e.g., {"TLSv1.2","TLSv1.3"}); when null or empty, default protocols are used
        allowedCipherSuites - the cipher suites to enable, or null to use the default cipher suite list
        Returns:
        a CloseableHttpClient configured with the specified TLS protocols and cipher suites (or a default TLS configuration when `enabledProtocols` is null/empty)
        Throws:
        NoSuchAlgorithmException - if the requested SSL algorithm is not available when building the SSLContext
        KeyManagementException - if there is an issue initializing the SSLContext's key management
      • getHttpsClient

        public org.apache.http.impl.client.CloseableHttpClient getHttpsClient​(String trustStorePath,
                                                                              String trustStorePassword,
                                                                              String keyStorePath,
                                                                              String keyStorePassword)
                                                                       throws KeyManagementException,
                                                                              NoSuchAlgorithmException,
                                                                              KeyStoreException,
                                                                              CertificateException,
                                                                              IOException,
                                                                              UnrecoverableKeyException
        Builds an HTTPS CloseableHttpClient configured to use the provided trust store and key store. The returned client uses an SSLContext initialized from the specified trust store and key store, and is configured with the service's connection manager and a standard cookie specification.
        Parameters:
        trustStorePath - filesystem path to the trust store file (e.g., JKS/PKCS12)
        trustStorePassword - password for the trust store
        keyStorePath - filesystem path to the key store containing client certificate/private key
        keyStorePassword - password for the key store (and key material)
        Returns:
        a CloseableHttpClient that uses the loaded SSL context
        Throws:
        KeyManagementException - if the SSLContext cannot be initialized
        NoSuchAlgorithmException - if a required cryptographic algorithm is not available
        KeyStoreException - if the key store cannot be loaded or accessed
        CertificateException - if any certificate cannot be parsed or validated
        IOException - if an I/O error occurs reading the store files
        UnrecoverableKeyException - if a key in the key store cannot be recovered (e.g., wrong password)
      • executePost

        public io.jans.model.net.HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient,
                                                                 String uri,
                                                                 String authCode,
                                                                 Map<String,​String> headers,
                                                                 String postData,
                                                                 org.apache.http.entity.ContentType contentType,
                                                                 String authType)
        Execute an HTTP POST to the given URI and return the request/response pair.
        Parameters:
        httpClient - the HttpClient used to execute the request
        uri - the target URI for the POST request
        authCode - an authorization token to include; if blank, no Authorization header is added
        headers - additional headers to include in the request; may be null
        postData - the request body as a string; may be null
        contentType - the content type for the request body; if null, defaults to application/json
        authType - the authentication scheme prefix (for example "Bearer ") to prepend to authCode
        Returns:
        an HttpServiceResponse containing the executed HttpPost and HttpResponse, or null if execution failed
      • executePost

        public io.jans.model.net.HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient,
                                                                 String uri,
                                                                 String authCode,
                                                                 Map<String,​String> headers,
                                                                 String postData)
        Execute an HTTP POST to the specified URI using the provided HttpClient and payload.
        Parameters:
        httpClient - the HttpClient used to execute the request
        uri - the target request URI
        authCode - an optional authorization value; if non-null an Authorization header is set
        headers - additional request headers to include (may be null)
        postData - the request body to send (may be null)
        Returns:
        an HttpServiceResponse wrapping the executed HttpPost and HttpResponse, or `null` if execution failed
      • executePost

        public io.jans.model.net.HttpServiceResponse executePost​(org.apache.http.client.HttpClient httpClient,
                                                                 String uri,
                                                                 String authCode,
                                                                 String postData,
                                                                 org.apache.http.entity.ContentType contentType)
        Execute an HTTP POST request using the provided HTTP client.
        Parameters:
        httpClient - the HttpClient to execute the request
        uri - the target URI for the POST request
        authCode - optional authorization token value; when provided it will be set on the `Authorization` header
        postData - the request body to send
        contentType - the content type of the request body; if `null`, `application/json` is used
        Returns:
        an HttpServiceResponse containing the executed HttpPost and the HttpResponse, or `null` if the request failed
      • executePost

        public io.jans.model.net.HttpServiceResponse executePost​(String uri,
                                                                 String authCode,
                                                                 String postData,
                                                                 org.apache.http.entity.ContentType contentType,
                                                                 String authType)
        Sends an HTTP POST to the given URI using the service's default HTTPS client.
        Parameters:
        uri - the target request URI
        authCode - optional authorization credentials (token or credential string) to include in the Authorization header
        postData - the request body to send
        contentType - the content type of the request body
        authType - the scheme or prefix to use for the Authorization header (for example "Bearer ")
        Returns:
        an HttpServiceResponse containing the executed request and response, or null if the request failed
      • encodeBase64

        public String encodeBase64​(String value)
      • encodeUrl

        public String encodeUrl​(String value)
        URL-encodes the given string using UTF-8 encoding.
        Parameters:
        value - the string to URL-encode
        Returns:
        the URL-encoded form of the input string
      • executeGet

        public io.jans.model.net.HttpServiceResponse executeGet​(org.apache.http.client.HttpClient httpClient,
                                                                String requestUri,
                                                                Map<String,​String> headers,
                                                                Map<String,​String> parameters)
        Executes an HTTP GET against the given URI with optional headers and query parameters and returns the request/response pair. The method appends URL-encoded query parameters to the requestUri when provided, applies any supplied headers, and executes the request using the given HttpClient.
        Parameters:
        requestUri - the target URI (may be appended with URL-encoded query parameters)
        headers - optional HTTP headers to include on the request (may be null)
        parameters - optional query parameters to append to the URI; entries with blank values are ignored (may be null)
        Returns:
        a HttpServiceResponse containing the executed HttpGet and the HttpResponse, or `null` if the request failed due to an I/O error
      • executeGet

        public io.jans.model.net.HttpServiceResponse executeGet​(String requestUri,
                                                                Map<String,​String> headers)
      • executeGet

        public io.jans.model.net.HttpServiceResponse executeGet​(org.apache.http.client.HttpClient httpClient,
                                                                String requestUri)
      • executeDelete

        public io.jans.model.net.HttpServiceResponse executeDelete​(String requestUri,
                                                                   Map<String,​String> headers,
                                                                   Map<String,​String> data)
        Execute an HTTP DELETE request to the given URI using the service's default HTTPS client.
        Parameters:
        requestUri - the target URI for the DELETE request
        headers - optional HTTP headers to include
        data - optional query parameters to append to the URI
        Returns:
        the HttpServiceResponse containing the executed request and response, or null if the request failed
      • executeDelete

        public io.jans.model.net.HttpServiceResponse executeDelete​(org.apache.http.client.HttpClient httpClient,
                                                                   String requestUri,
                                                                   Map<String,​String> headers,
                                                                   Map<String,​String> parameters)
        Execute an HTTP DELETE to the specified URI, applying provided headers and URL-encoded query parameters. Query parameters with blank values are skipped; keys and values are URL-encoded using UTF-8 before being appended to the URI.
        Parameters:
        requestUri - the target URI (query string will be appended if parameters are provided)
        headers - map of header names to values to set on the request; may be null
        parameters - map of query parameter names to values to append to the URI; may be null
        Returns:
        an HttpServiceResponse containing the executed HttpDelete and the HttpResponse, or `null` if execution failed
      • getResponseContent

        public byte[] getResponseContent​(org.apache.http.HttpResponse httpResponse)
                                  throws IOException
        Throws:
        IOException
      • consume

        public void consume​(org.apache.http.HttpResponse httpResponse)
                     throws IOException
        Throws:
        IOException
      • convertEntityToString

        public String convertEntityToString​(byte[] responseBytes)
      • convertEntityToString

        public String convertEntityToString​(byte[] responseBytes,
                                            Charset charset)
      • isResponseStastusCodeOk

        public boolean isResponseStastusCodeOk​(org.apache.http.HttpResponse httpResponse)
      • isResponseStatusCodeOk

        public boolean isResponseStatusCodeOk​(org.apache.http.HttpResponse httpResponse)
      • isContentTypeXml

        public boolean isContentTypeXml​(org.apache.http.HttpResponse httpResponse)
      • constructServerUrl

        public String constructServerUrl​(jakarta.servlet.http.HttpServletRequest request)
      • buildDefaultRoutePlanner

        public org.apache.http.conn.routing.HttpRoutePlanner buildDefaultRoutePlanner​(String hostname,
                                                                                      int port,
                                                                                      String scheme)
      • buildDefaultRoutePlanner

        public org.apache.http.conn.routing.HttpRoutePlanner buildDefaultRoutePlanner​(String proxy)
      • getResponseJsonNode

        public com.fasterxml.jackson.databind.JsonNode getResponseJsonNode​(io.jans.model.net.HttpServiceResponse serviceResponse)
                                                                    throws com.fasterxml.jackson.core.JsonProcessingException
        Parse the JSON body of an HttpServiceResponse and return its "response" node. If the provided serviceResponse is null or does not contain a parsable JSON body, this method returns null.
        Parameters:
        serviceResponse - the HttpServiceResponse whose entity will be parsed
        Returns:
        the JsonNode corresponding to the top-level "response" field, or null if unavailable
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - if the response body cannot be parsed as JSON
      • getResponseEntityString

        public String getResponseEntityString​(io.jans.model.net.HttpServiceResponse serviceResponse)
        Extracts the HTTP response body as UTF-8 text and enforces an OK (200) response status.
        Parameters:
        serviceResponse - the HttpServiceResponse wrapper containing the HttpResponse to read; may be null
        Returns:
        the response body decoded as UTF-8, or null if serviceResponse, the contained HttpResponse, or its entity is null
        Throws:
        jakarta.ws.rs.WebApplicationException - if the HttpResponse status code is not 200; the exception message is formatted as ":"
      • getResponseJsonNode

        public com.fasterxml.jackson.databind.JsonNode getResponseJsonNode​(String jsonSring,
                                                                           String nodeName)
                                                                    throws com.fasterxml.jackson.core.JsonProcessingException
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
      • getResponseStatus

        public jakarta.ws.rs.core.Response.Status getResponseStatus​(io.jans.model.net.HttpServiceResponse serviceResponse)
        Map an HttpServiceResponse's HTTP status code to a JAX-RS Status.
        Parameters:
        serviceResponse - the HttpServiceResponse whose HTTP response status will be mapped; may be null
        Returns:
        the `Status` corresponding to the response's HTTP status code, or `Status.INTERNAL_SERVER_ERROR` if the response is missing or the code cannot be mapped
      • readEntity

        public StringBuilder readEntity​(org.apache.http.HttpEntity httpEntity)
                                 throws IOException
        Read and return the UTF-8 text content of the given HttpEntity as a StringBuilder.
        Parameters:
        httpEntity - the HTTP entity whose content will be read; may be null
        Returns:
        a StringBuilder containing the entity content (empty if the entity is null or has no content)
        Throws:
        IOException - if an I/O error occurs while reading the entity content
      • getContent

        public String getContent​(org.apache.http.HttpEntity httpEntity)
        Read and return the UTF-8 string content of the provided HttpEntity.
        Parameters:
        httpEntity - the HttpEntity to read; if null, the method returns null
        Returns:
        the entity content decoded as a UTF-8 string, or null if httpEntity is null
        Throws:
        jakarta.ws.rs.WebApplicationException - if an I/O error occurs while reading the entity