Package com.bisnode.opa.client.rest
Class OpaRestClient
- java.lang.Object
-
- com.bisnode.opa.client.rest.OpaRestClient
-
public class OpaRestClient extends java.lang.ObjectClass wrapping Java's HttpClient in OPA and JSON requests
-
-
Constructor Summary
Constructors Constructor Description OpaRestClient(OpaConfiguration opaConfiguration, java.net.http.HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.http.HttpRequest.BuildergetBasicRequestBuilder(java.lang.String endpoint)CreateHttpRequest.Builderwith configured url using provided endpoint<T> com.bisnode.opa.client.rest.JsonBodyHandler<T>getJsonBodyHandler(com.fasterxml.jackson.databind.JavaType responseType)GetsJsonBodyHandlerthat will deserialize JSON to desired class typejava.net.http.HttpRequest.BodyPublishergetJsonBodyPublisher(java.lang.Object body)GetsHttpRequest.BodyPublisherthat is capable of serializing to JSON<T> java.net.http.HttpResponse<T>sendRequest(java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> bodyHandler)Sends provided request and returns response mapped usingHttpResponse.BodyHandler
-
-
-
Constructor Detail
-
OpaRestClient
public OpaRestClient(OpaConfiguration opaConfiguration, java.net.http.HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
-
Method Detail
-
getBasicRequestBuilder
public java.net.http.HttpRequest.Builder getBasicRequestBuilder(java.lang.String endpoint)
CreateHttpRequest.Builderwith configured url using provided endpoint- Parameters:
endpoint- desired opa endpoint- Throws:
OpaClientException- if URL or endpoint is invalid
-
getJsonBodyPublisher
public java.net.http.HttpRequest.BodyPublisher getJsonBodyPublisher(java.lang.Object body) throws com.fasterxml.jackson.core.JsonProcessingExceptionGetsHttpRequest.BodyPublisherthat is capable of serializing to JSON- Parameters:
body- object to be serialized- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getJsonBodyHandler
public <T> com.bisnode.opa.client.rest.JsonBodyHandler<T> getJsonBodyHandler(com.fasterxml.jackson.databind.JavaType responseType)
GetsJsonBodyHandlerthat will deserialize JSON to desired class type- Type Parameters:
T- desired response type- Parameters:
responseType- desired response type
-
sendRequest
public <T> java.net.http.HttpResponse<T> sendRequest(java.net.http.HttpRequest request, java.net.http.HttpResponse.BodyHandler<T> bodyHandler) throws java.io.IOException, java.lang.InterruptedExceptionSends provided request and returns response mapped usingHttpResponse.BodyHandler- Type Parameters:
T- Type of returned body- Parameters:
request- request to be sentbodyHandler- handler that indicates how to transform incoming body- Returns:
- response from HttpRequest
- Throws:
java.io.IOException- is propagated fromHttpClientjava.lang.InterruptedException- is propagated fromHttpClient
-
-