Package co.arago.hiro.client.connection
Class AbstractAPIHandler
- java.lang.Object
-
- co.arago.util.validation.RequiredFieldChecks
-
- co.arago.hiro.client.connection.AbstractAPIHandler
-
- Direct Known Subclasses:
AbstractClientAPIHandler,AuthenticatedAPIHandler
public abstract class AbstractAPIHandler extends co.arago.util.validation.RequiredFieldChecksRoot class with fields and tool methods for all API Handlers
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractAPIHandler.Conf<T extends AbstractAPIHandler.Conf<T>>The basic configuration for all APIHAndlerstatic interfaceAbstractAPIHandler.GetterConf
-
Field Summary
Fields Modifier and Type Field Description protected java.net.URLapiUrlprotected java.lang.LonghttpRequestTimeoutprotected intmaxRetriesstatic java.lang.Stringtitleprotected java.lang.StringuserAgentstatic java.lang.Stringversionprotected java.net.URIwebSocketUri
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractAPIHandler(AbstractAPIHandler.GetterConf builder)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static java.net.URIaddQueryAndFragment(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> query, java.lang.String fragment)Add query and fragment to a URI - if any.abstract voidaddToHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Override this to add authentication tokens.java.net.URIbuildApiURI(java.lang.String path)Build a complete uri from the apiUrl and path.java.net.URIbuildEndpointURI(java.lang.String path)Build a complete uri from the apiUrl and path.protected static java.net.URIbuildURI(java.net.URI uri, java.lang.String path, boolean finalSlash)Build a complete uri from the url and path.java.net.URIbuildWebSocketURI(java.lang.String path)Build a complete uri from the webSocketApi and path.booleancheckResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount)The default way to check responses for errors and extract error messages.<T extends HiroMessage>
Tdelete(java.lang.Class<T> clazz, java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic DELETE method which returns a Map constructed via a JSON body httpResponse.java.util.concurrent.CompletableFuture<HttpResponseParser>executeAsyncWithStreamBody(java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout)Method to communicate asynchronously via InputStreams.java.util.concurrent.CompletableFuture<HttpResponseParser>executeAsyncWithStringBody(java.net.URI uri, java.lang.String method, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout)Method to communicate asynchronously via String body.HttpResponseParserexecuteBinary(java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Method to communicate via InputStreams.<T extends HiroMessage>
TexecuteWithStreamBody(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic method which returns an object of typeHiroMessageconstructed via a JSON body httpResponse.<T extends HiroMessage>
TexecuteWithStringBody(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String method, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic method which returns an object of typeHiroMessageconstructed via a JSON body httpResponse.<T extends HiroMessage>
Tget(java.lang.Class<T> clazz, java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic GET method which returns a Map constructed via a JSON body httpResponse.java.net.URLgetApiUrl()HttpResponseParsergetBinary(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic GET method which returns an InputStream from the body of the httpResponse.protected abstract HttpLoggergetHttpLogger()Abstract class that needs to be overwritten by a supplier of a HttpLogger.java.lang.LonggetHttpRequestTimeout()intgetMaxRetries()protected abstract java.net.http.HttpClientgetOrBuildClient()Abstract class that needs to be overwritten by a supplier of a HttpClient.java.net.http.HttpRequest.BuildergetRequestBuilder(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout)Create a HttpRequest.Builder with common options and headers.java.lang.StringgetUserAgent()java.net.URIgetWebSocketUri()Get thewebSocketUrior, if it is missing, construct one fromapiUrl.<T extends HiroMessage>
Tpatch(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic PATCH method which returns a Map constructed via a JSON body httpResponse.<T extends HiroMessage>
TpatchBinary(java.lang.Class<T> clazz, java.net.URI uri, StreamContainer body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic PATCH method which sends an InputStream.<T extends HiroMessage>
Tpost(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic POST method which returns a Map constructed via a JSON body httpResponse.<T extends HiroMessage>
TpostBinary(java.lang.Class<T> clazz, java.net.URI uri, StreamContainer body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic POST method which sends an InputStream.<T extends HiroMessage>
Tput(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic PUT method which returns a Map constructed via a JSON body httpResponse.<T extends HiroMessage>
TputBinary(java.lang.Class<T> clazz, java.net.URI uri, StreamContainer body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic PUT method which sends an InputStream.java.net.http.HttpResponse<java.io.InputStream>send(java.net.http.HttpRequest httpRequest, java.lang.Integer maxRetries)Send a HttpRequest synchronously and return the httpResponsejava.util.concurrent.CompletableFuture<HttpResponseParser>sendAsync(java.net.http.HttpRequest httpRequest)Send a HttpRequest asynchronously and return a future for aHttpResponseParser.
-
-
-
Field Detail
-
title
public static final java.lang.String title
-
version
public static final java.lang.String version
-
apiUrl
protected final java.net.URL apiUrl
-
webSocketUri
protected final java.net.URI webSocketUri
-
userAgent
protected final java.lang.String userAgent
-
httpRequestTimeout
protected final java.lang.Long httpRequestTimeout
-
maxRetries
protected int maxRetries
-
-
Constructor Detail
-
AbstractAPIHandler
protected AbstractAPIHandler(AbstractAPIHandler.GetterConf builder)
-
-
Method Detail
-
getApiUrl
public java.net.URL getApiUrl()
-
getWebSocketUri
public java.net.URI getWebSocketUri()
Get thewebSocketUrior, if it is missing, construct one fromapiUrl.- Returns:
- The URI for the webSocket.
-
getUserAgent
public java.lang.String getUserAgent()
-
getHttpRequestTimeout
public java.lang.Long getHttpRequestTimeout()
-
getMaxRetries
public int getMaxRetries()
-
buildApiURI
public java.net.URI buildApiURI(java.lang.String path)
Build a complete uri from the apiUrl and path. Appends a '/'.- Parameters:
path- The path to append toapiUrl.- Returns:
- The constructed URI
-
buildEndpointURI
public java.net.URI buildEndpointURI(java.lang.String path)
Build a complete uri from the apiUrl and path. Does not append a '/'- Parameters:
path- The path to append toapiUrl.- Returns:
- The constructed URI
-
buildWebSocketURI
public java.net.URI buildWebSocketURI(java.lang.String path)
Build a complete uri from the webSocketApi and path.- Parameters:
path- The path to append towebSocketUri.- Returns:
- The constructed URI
-
buildURI
protected static java.net.URI buildURI(java.net.URI uri, java.lang.String path, boolean finalSlash)Build a complete uri from the url and path.- Parameters:
uri- The uri to use as root.path- The path to append to the url.finalSlash- Append a final slash?- Returns:
- The constructed URI
-
addQueryAndFragment
public static java.net.URI addQueryAndFragment(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> query, java.lang.String fragment)Add query and fragment to a URI - if any.- Parameters:
uri- The URI for the query and fragment.query- Map of query parameters to set. Can be null for no query parameters.fragment- URI Fragment. Can be null for no fragment.- Returns:
- The constructed URI
-
getRequestBuilder
public java.net.http.HttpRequest.Builder getRequestBuilder(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout) throws java.lang.InterruptedException, java.io.IOException, HiroExceptionCreate a HttpRequest.Builder with common options and headers.- Parameters:
uri- The uri for the httpRequest.headers- Initial headers for the httpRequest. Must NOT be null.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.- Returns:
- The HttpRequest.Builder
- Throws:
java.lang.InterruptedException- When call gets interrupted.java.io.IOException- When call has IO errors.HiroException- On Hiro protocol / handling errors.
-
send
public java.net.http.HttpResponse<java.io.InputStream> send(java.net.http.HttpRequest httpRequest, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedExceptionSend a HttpRequest synchronously and return the httpResponse- Parameters:
httpRequest- The httpRequest to sendmaxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A HttpResponse containing an InputStream of the incoming body part of the result.
- Throws:
HiroException- When status errors occur.java.io.IOException- On IO errors with the connection.java.lang.InterruptedException- When the call gets interrupted.
-
sendAsync
public java.util.concurrent.CompletableFuture<HttpResponseParser> sendAsync(java.net.http.HttpRequest httpRequest)
Send a HttpRequest asynchronously and return a future for a
HttpResponseParser.Applies the internal
checkResponse(HttpResponse, int). The retry counter is irrelevant here. When the token expires, it will be detected and a new token will be requested, but you need to handle aCompletionExceptionand look for the causeRetryExceptionwithin it. If this is the cause, you need to retry the same HttpRequest again externally.Also logs the response.
- Parameters:
httpRequest- The httpRequest to send- Returns:
- A future for a
HttpResponseParsercontaining the response.
-
executeWithStringBody
public <T extends HiroMessage> T executeWithStringBody(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String method, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic method which returns an object of typeHiroMessageconstructed via a JSON body httpResponse. Sets an appropriate Accept header.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.method- The method to use.body- The body as String. Can be null for methods that do not supply a body.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- An object of clazz constructed from the JSON result or null if the response has no body.
- Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
executeWithStreamBody
public <T extends HiroMessage> T executeWithStreamBody(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic method which returns an object of typeHiroMessageconstructed via a JSON body httpResponse. Sets an appropriate Accept header.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.method- The method to use.bodyContainer- The body asStreamContainer. Can be null for methods that do not supply a body.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be usedmaxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- An object of clazz constructed from the JSON result or null if the response has no body.
- Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
executeBinary
public HttpResponseParser executeBinary(java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Method to communicate via InputStreams.- Parameters:
uri- The uri to use.method- The method to use.bodyContainer- The body asStreamContainer. Can be null for methods that do not supply a body.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HttpResponseParserwith the result body as InputStream and associated header information. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
executeAsyncWithStringBody
public java.util.concurrent.CompletableFuture<HttpResponseParser> executeAsyncWithStringBody(java.net.URI uri, java.lang.String method, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout) throws java.lang.InterruptedException, java.io.IOException, HiroException
Method to communicate asynchronously via String body. This logs only the request, not the result.- Parameters:
uri- The uri to use.method- The method to use.body- The body as String. Can be null for methods that do not supply a body.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.- Returns:
- A future for the
HttpResponseParser. - Throws:
HiroException- On errors with protocol handling.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
executeAsyncWithStreamBody
public java.util.concurrent.CompletableFuture<HttpResponseParser> executeAsyncWithStreamBody(java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout) throws java.lang.InterruptedException, java.io.IOException, HiroException
Method to communicate asynchronously via InputStreams. This logs only the request, not the result.- Parameters:
uri- The uri to use.method- The method to use.bodyContainer- The body asStreamContainer. Can be null for methods that do not supply a body.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.- Returns:
- A future for the
HttpResponseParser. - Throws:
HiroException- On errors with protocol handling.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
get
public <T extends HiroMessage> T get(java.lang.Class<T> clazz, java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic GET method which returns a Map constructed via a JSON body httpResponse.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
post
public <T extends HiroMessage> T post(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic POST method which returns a Map constructed via a JSON body httpResponse.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.body- The body as String.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
put
public <T extends HiroMessage> T put(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic PUT method which returns a Map constructed via a JSON body httpResponse.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.body- The body as String.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
patch
public <T extends HiroMessage> T patch(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic PATCH method which returns a Map constructed via a JSON body httpResponse.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.body- The body as String.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
delete
public <T extends HiroMessage> T delete(java.lang.Class<T> clazz, java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic DELETE method which returns a Map constructed via a JSON body httpResponse.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
getBinary
public HttpResponseParser getBinary(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic GET method which returns an InputStream from the body of the httpResponse.- Parameters:
uri- The uri to use.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HttpResponseParserwith the result body as InputStream and associated header information. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
postBinary
public <T extends HiroMessage> T postBinary(java.lang.Class<T> clazz, java.net.URI uri, StreamContainer body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic POST method which sends an InputStream.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.body- Body asStreamContainer.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
putBinary
public <T extends HiroMessage> T putBinary(java.lang.Class<T> clazz, java.net.URI uri, StreamContainer body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic PUT method which sends an InputStream.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.body- Body asStreamContainer.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
patchBinary
public <T extends HiroMessage> T patchBinary(java.lang.Class<T> clazz, java.net.URI uri, StreamContainer body, java.util.Map<java.lang.String,java.lang.String> headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries) throws HiroException, java.io.IOException, java.lang.InterruptedException
Basic PATCH method which sends an InputStream.- Type Parameters:
T- Type of result object, derived ofHiroMessage.- Parameters:
clazz- The object to create from the incoming JSON data.uri- The uri to use.body- Body asStreamContainer.headers- Initial headers for the httpRequest. Can be null for no additional headers.httpRequestTimeout- The timeout in ms for the http request. If this is null, thehttpRequestTimeoutwill be used.maxRetries- The amount of retries on errors. When this is null,maxRetrieswill be used.- Returns:
- A
HiroMessageconstructed from the JSON result. - Throws:
HiroException- On errors indicated by http status codes.java.io.IOException- On io errorsjava.lang.InterruptedException- When the connection gets interrupted.
-
getHttpLogger
protected abstract HttpLogger getHttpLogger()
Abstract class that needs to be overwritten by a supplier of a HttpLogger.- Returns:
- The HttpLogger to use with this class.
-
getOrBuildClient
protected abstract java.net.http.HttpClient getOrBuildClient()
Abstract class that needs to be overwritten by a supplier of a HttpClient.- Returns:
- The HttpClient to use with this class.
-
addToHeaders
public abstract void addToHeaders(java.util.Map<java.lang.String,java.lang.String> headers) throws java.lang.InterruptedException, java.io.IOException, HiroExceptionOverride this to add authentication tokens.- Parameters:
headers- Map of headers with initial values.- Throws:
HiroException- On internal errors regarding hiro data processing.java.io.IOException- On IO errors.java.lang.InterruptedException- When a call (possibly of an overwritten method) gets interrupted.
-
checkResponse
public boolean checkResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount) throws HiroException, java.io.IOException, java.lang.InterruptedExceptionThe default way to check responses for errors and extract error messages.- Parameters:
httpResponse- The httpResponse from the HttpRequestretryCount- current counter for retries- Returns:
- true for a retry, false otherwise.
- Throws:
TokenUnauthorizedException- When the statusCode is 401.HiroHttpException- When the statusCode is < 200 or > 399.HiroException- On internal errors regarding hiro data processing.java.io.IOException- On IO errors.java.lang.InterruptedException- When a call (possibly of an overwritten method) gets interrupted.
-
-