Class AbstractAPIHandler

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static java.net.URI addQueryFragmentAndNormalize​(java.net.URI uri, URIEncodedData query, java.lang.String fragment)
      Add query and fragment to a URI - if any.
      abstract void addToHeaders​(HttpHeaderMap headers)
      Override this to add authentication tokens.
      java.net.URI buildApiURI​(java.lang.String path)
      Build a complete uri from the apiUrl and path.
      java.net.URI buildEndpointURI​(java.lang.String path)
      Build a complete uri from the apiUrl and path.
      static java.net.URI buildURI​(java.net.URI uri, java.lang.String path, boolean finalSlash)
      Build a complete uri from the url and path.
      java.net.URI buildWebSocketURI​(java.lang.String path)
      Build a complete uri from the webSocketApi and path.
      boolean checkResponse​(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>
      T
      delete​(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.
      HttpResponseParser executeBinary​(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>
      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)
      Basic method which returns an object of type HiroMessage constructed via a JSON body httpResponse.
      <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)
      Basic method which returns an object of type HiroMessage constructed via a JSON body httpResponse.
      <T extends HiroMessage>
      T
      get​(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.
      HttpResponseParser getBinary​(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.
      HttpLogger getHttpLogger()  
      java.lang.Long getHttpRequestTimeout()  
      int getMaxRetries()  
      java.net.http.HttpClient getOrBuildClient()  
      java.net.http.HttpRequest.Builder getRequestBuilder​(java.net.URI uri, HttpHeaderMap headers, java.lang.Long httpRequestTimeout)
      Create a HttpRequest.Builder with common options and headers.
      java.net.URI getRootApiURI()  
      java.lang.String getUserAgent()  
      java.net.URI getWebSocketURI()
      Get the webSocketURI or, if it is missing, construct one from rootApiURI.
      <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)
      Basic PATCH method which returns a Map constructed via a JSON body httpResponse.
      <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)
      Basic PATCH method which sends an InputStream.
      <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)
      Basic POST method which returns a Map constructed via a JSON body httpResponse.
      <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)
      Basic POST method which sends an InputStream.
      <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)
      Basic PUT method which returns a Map constructed via a JSON body httpResponse.
      <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)
      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 httpResponse
      java.util.concurrent.CompletableFuture<HttpResponseParser> sendAsync​(java.net.http.HttpRequest httpRequest)
      Send a HttpRequest asynchronously and return a future for a HttpResponseParser.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • 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.Conf and therefore will be shared among all APIHandlers that use this configuration.
      • getRootApiURI

        public java.net.URI getRootApiURI()
      • getWebSocketURI

        public java.net.URI getWebSocketURI()
        Get the webSocketURI or, if it is missing, construct one from rootApiURI.
        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 to rootApiURI.
        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 to rootApiURI.
        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 to webSocketURI.
        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,
                                                                   HiroException
        Create 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, the httpRequestTimeout will 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.InterruptedException
        Send a HttpRequest synchronously and return the httpResponse
        Parameters:
        httpRequest - The httpRequest to send
        maxRetries - The amount of retries on errors. When this is null, maxRetries will 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 a CompletionException and look for the cause RetryException within 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 HttpResponseParser containing 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 type HiroMessage constructed via a JSON body httpResponse. Sets an appropriate Accept header.
        Type Parameters:
        T - Type of result object, derived of HiroMessage.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will 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 errors
        java.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 type HiroMessage constructed via a JSON body httpResponse. Sets an appropriate Accept header.
        Type Parameters:
        T - Type of result object, derived of HiroMessage.
        Parameters:
        clazz - The object to create from the incoming JSON data.
        uri - The uri to use.
        method - The method to use.
        bodyContainer - The body as StreamContainer. 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, the httpRequestTimeout will be used
        maxRetries - The amount of retries on errors. When this is null, maxRetries will 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 errors
        java.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 as StreamContainer. 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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HttpResponseParser with the result body as InputStream and associated header information.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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, the httpRequestTimeout will be used.
        Returns:
        A future for the HttpResponseParser.
        Throws:
        HiroException - On errors with protocol handling.
        java.io.IOException - On io errors
        java.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 as StreamContainer. 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, the httpRequestTimeout will be used.
        Returns:
        A future for the HttpResponseParser.
        Throws:
        HiroException - On errors with protocol handling.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HttpResponseParser with the result body as InputStream and associated header information.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        Parameters:
        clazz - The object to create from the incoming JSON data.
        uri - The uri to use.
        body - Body as StreamContainer.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        Parameters:
        clazz - The object to create from the incoming JSON data.
        uri - The uri to use.
        body - Body as StreamContainer.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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 of HiroMessage.
        Parameters:
        clazz - The object to create from the incoming JSON data.
        uri - The uri to use.
        body - Body as StreamContainer.
        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, the httpRequestTimeout will be used.
        maxRetries - The amount of retries on errors. When this is null, maxRetries will be used.
        Returns:
        A HiroMessage constructed from the JSON result.
        Throws:
        HiroException - On errors indicated by http status codes.
        java.io.IOException - On io errors
        java.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.InterruptedException
        The default way to check responses for errors and extract error messages.
        Parameters:
        httpResponse - The httpResponse from the HttpRequest
        retryCount - 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.