Package co.arago.hiro.client.connection
Class AbstractAPIHandler
- java.lang.Object
-
- co.arago.hiro.client.connection.AbstractAPIHandler
-
- Direct Known Subclasses:
AbstractVersionAPIHandler,AuthenticatedAPIHandler
public abstract class AbstractAPIHandler extends java.lang.ObjectRoot 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 APIHAndler.
-
Field Summary
Fields Modifier and Type Field Description protected HttpClientHandlerhttpClientHandlerThis is a reference which will be shared among all AbstractAPIHandler that use the same configurationAbstractAPIHandler.Conf.protected java.lang.LonghttpRequestTimeoutprotected intmaxRetriesprotected java.net.URIrootApiURIstatic java.lang.Stringtitleprotected java.lang.StringuserAgentstatic java.lang.Stringversionprotected java.net.URIwebSocketURI
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractAPIHandler(AbstractAPIHandler.Conf<?> builder)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static java.net.URIaddQueryFragmentAndNormalize(java.net.URI uri, URIEncodedData query, java.lang.String fragment)Add query and fragment to a URI - if any.abstract voidaddToHeaders(HttpHeaderMap 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.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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap headers, java.lang.Long httpRequestTimeout)Method to communicate asynchronously via String body.HttpResponseParserexecuteBinary(java.net.URI uri, java.lang.String method, StreamContainer bodyContainer, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic GET method which returns a Map constructed via a JSON body httpResponse.HttpResponseParsergetBinary(java.net.URI uri, HttpHeaderMap headers, java.lang.Long httpRequestTimeout, java.lang.Integer maxRetries)Basic GET method which returns an InputStream from the body of the httpResponse.AbstractAPIHandler.Conf<?>getConf()Return a copy of the configuration.HttpLoggergetHttpLogger()java.lang.LonggetHttpRequestTimeout()intgetMaxRetries()java.net.http.HttpClientgetOrBuildClient()java.net.http.HttpRequest.BuildergetRequestBuilder(java.net.URI uri, HttpHeaderMap headers, java.lang.Long httpRequestTimeout)Create a HttpRequest.Builder with common options and headers.java.net.URIgetRootApiURI()java.lang.StringgetUserAgent()java.net.URIgetWebSocketURI()Get thewebSocketURIor, if it is missing, construct one fromrootApiURI.<T extends HiroMessage>
Tpatch(java.lang.Class<T> clazz, java.net.URI uri, java.lang.String body, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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
-
rootApiURI
protected final java.net.URI rootApiURI
-
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
-
httpClientHandler
protected HttpClientHandler httpClientHandler
This is a reference which will be shared among all AbstractAPIHandler that use the same configurationAbstractAPIHandler.Conf.
-
-
Constructor Detail
-
AbstractAPIHandler
protected AbstractAPIHandler(AbstractAPIHandler.Conf<?> builder)
Constructor.- Parameters:
builder- The builder to use.- Implementation Note:
- If the builder does not carry a httpClientHandler, a default will be created here.
-
-
Method Detail
-
getConf
public AbstractAPIHandler.Conf<?> getConf()
Return a copy of the configuration.- Returns:
- A copy of the configuration.
- See Also:
AuthenticatedAPIHandler- Implementation Note:
- Please take note, that the included httpClientHandler of this class will be
added to the returned
AbstractAPIHandler.Confand therefore will be shared among all APIHandlers that use this configuration.
-
getRootApiURI
public java.net.URI getRootApiURI()
-
getWebSocketURI
public java.net.URI getWebSocketURI()
Get thewebSocketURIor, if it is missing, construct one fromrootApiURI.- 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 torootApiURI.- 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 torootApiURI.- 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
public 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
-
addQueryFragmentAndNormalize
public static java.net.URI addQueryFragmentAndNormalize(java.net.URI uri, URIEncodedData 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, otherwise uri must not have a query already.fragment- URI Fragment. Can be null for no fragment, otherwise uri must not have a fragment already.- Returns:
- The constructed URI
- Throws:
java.lang.IllegalArgumentException- When the given URI already has a query and the given query is not blank or the URI has a fragment and the given fragment is not blank.
-
getRequestBuilder
public java.net.http.HttpRequest.Builder getRequestBuilder(java.net.URI uri, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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, HttpHeaderMap 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
public HttpLogger getHttpLogger()
- Returns:
- The HttpLogger to use with this class.
-
getOrBuildClient
public java.net.http.HttpClient getOrBuildClient()
- Returns:
- The HttpClient to use with this class.
-
addToHeaders
public abstract void addToHeaders(HttpHeaderMap headers) throws java.lang.InterruptedException, java.io.IOException, HiroException
Override 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.
-
-