Package io.jans.configapi.core.service
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
FieldsFields inherited from class io.jans.service.net.BaseHttpService
base64, connectionManager, HTTPCLIENT_MAX_PER_ROUTE, HTTPCLIENT_MAX_TOTAL, HTTPCLIENT_VALIDATE_AFTER_INACTIVITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.http.impl.client.CloseableHttpClientcreateHttpsClientWithTlsPolicy(String[] enabledProtocols, String[] allowedCipherSuites) Create a CloseableHttpClient configured with an optional TLS protocol and cipher-suite policy.io.jans.model.net.HttpServiceResponseExecute an HTTP DELETE request to the given URI using the service's default HTTPS client.io.jans.model.net.HttpServiceResponseexecuteDelete(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.HttpServiceResponseexecuteGet(String requestUri, Map<String, String> headers) io.jans.model.net.HttpServiceResponseio.jans.model.net.HttpServiceResponseexecuteGet(org.apache.http.client.HttpClient httpClient, String requestUri) io.jans.model.net.HttpServiceResponseexecuteGet(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.HttpServiceResponseexecutePost(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.HttpServiceResponseexecutePost(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 StringgetResponseEntityString(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.JsonNodegetResponseJsonNode(io.jans.model.net.HttpServiceResponse serviceResponse) Parse the JSON body of an HttpServiceResponse and return its "response" node.com.fasterxml.jackson.databind.JsonNodegetResponseJsonNode(String jsonSring, String nodeName) jakarta.ws.rs.core.Response.StatusgetResponseStatus(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
-
Field Details
-
log
protected transient org.apache.logging.log4j.Logger log
-
-
Constructor Details
-
ConfigHttpService
public ConfigHttpService()
-
-
Method Details
-
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 usedallowedCipherSuites- 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 SSLContextKeyManagementException- 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:
executePostin classio.jans.service.net.BaseHttpService- Parameters:
httpClient- the HttpClient used to execute the requesturi- the target URI for the POST requestauthCode- an authorization token to include; if blank, no Authorization header is addedheaders- additional headers to include in the request; may be nullpostData- the request body as a string; may be nullcontentType- the content type for the request body; if null, defaults to application/jsonauthType- the authentication scheme prefix (for example "Bearer ") to prepend toauthCode- Returns:
- an HttpServiceResponse containing the executed HttpPost and
HttpResponse, or
nullif 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 URIauthCode- optional authorization credentials (token or credential string) to include in the Authorization headerpostData- the request body to sendcontentType- the content type of the request bodyauthType- the scheme or prefix to use for the Authorization header (for example "Bearer ")- Returns:
- an HttpServiceResponse containing the executed request and response,
or
nullif 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
-
executeGet
-
executeGet
public io.jans.model.net.HttpServiceResponse executeGet(org.apache.http.client.HttpClient httpClient, String requestUri) - Overrides:
executeGetin classio.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 requestheaders- optional HTTP headers to includedata- optional query parameters to append to the URI- Returns:
- the HttpServiceResponse containing the executed request and response,
or
nullif 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 nullparameters- 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
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
nullifserviceResponse, 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
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
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
httpEntityis null - Throws:
jakarta.ws.rs.WebApplicationException- if an I/O error occurs while reading the entity
-