Class ConfigHttpService

java.lang.Object
io.jans.service.net.BaseHttpService
io.jans.configapi.core.service.ConfigHttpService
All Implemented Interfaces:
Serializable

@ApplicationScoped public class ConfigHttpService extends io.jans.service.net.BaseHttpService implements Serializable
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.logging.log4j.Logger
     

    Fields inherited from class io.jans.service.net.BaseHttpService

    base64, connectionManager, HTTPCLIENT_MAX_PER_ROUTE, HTTPCLIENT_MAX_TOTAL, HTTPCLIENT_VALIDATE_AFTER_INACTIVITY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.http.impl.client.CloseableHttpClient
    createHttpsClientWithTlsPolicy(String[] enabledProtocols, String[] allowedCipherSuites)
    Create a CloseableHttpClient configured with an optional TLS protocol and cipher-suite policy.
    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.
    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.
    io.jans.model.net.HttpServiceResponse
    executeGet(String requestUri, Map<String,String> headers)
     
    io.jans.model.net.HttpServiceResponse
    executeGet(String requestUri, Map<String,String> headers, Map<String,String> data)
     
    io.jans.model.net.HttpServiceResponse
    executeGet(org.apache.http.client.HttpClient httpClient, String requestUri)
     
    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.
    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.
    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.
    getContent(org.apache.http.HttpEntity httpEntity)
    Read and return the UTF-8 string content of the provided HttpEntity.
    static String
     
    getResponseEntityString(io.jans.model.net.HttpServiceResponse serviceResponse)
    Extracts the HTTP response body as UTF-8 text and enforces an OK (200) response status.
    com.fasterxml.jackson.databind.JsonNode
    getResponseJsonNode(io.jans.model.net.HttpServiceResponse serviceResponse)
    Parse the JSON body of an HttpServiceResponse and return its "response" node.
    com.fasterxml.jackson.databind.JsonNode
    getResponseJsonNode(String jsonSring, String nodeName)
     
    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.
    readEntity(org.apache.http.HttpEntity httpEntity)
    Read and return the UTF-8 text content of the given HttpEntity as a StringBuilder.

    Methods inherited from class io.jans.service.net.BaseHttpService

    buildDefaultRoutePlanner, buildDefaultRoutePlanner, constructServerUrl, consume, convertEntityToString, convertEntityToString, convertEntityToString, decodeBase64, encodeBase64, encodeUrl, executeGet, executePost, executePost, executePost, getApplicationConnectionProperties, getHttpsClient, getHttpsClient, getHttpsClient, getHttpsClient, getHttpsClient, getHttpsClient, getHttpsClientTrustAll, getResponseContent, init, isContentTypeXml, isResponseStastusCodeOk, isResponseStatusCodeOk

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

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

    • ConfigHttpService

      public ConfigHttpService()
  • Method Details

    • getOpenidConfigurationUrl

      public static String getOpenidConfigurationUrl()
    • 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
    • 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.
      Overrides:
      executePost in class io.jans.service.net.BaseHttpService
      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(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
    • 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, Map<String,String> data)
    • 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)
      Overrides:
      executeGet in class io.jans.service.net.BaseHttpService
    • 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
    • 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