Interface TokenAPIHandler

    • Method Detail

      • getConf

        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.
      • addToHeaders

        void addToHeaders​(HttpHeaderMap headers)
        Override this to add authentication tokens. TokenHandlers do not have tokens, so this only returns default headers.
        Parameters:
        headers - Map of headers with initial values.
      • getToken

        java.lang.String getToken()
                           throws java.io.IOException,
                                  java.lang.InterruptedException,
                                  HiroException
        Return the current token.
        Returns:
        The current token.
        Throws:
        java.lang.InterruptedException - When call gets interrupted.
        java.io.IOException - When call has IO errors.
        HiroException - On Hiro protocol / handling errors.
      • decodeToken

        DecodedToken decodeToken()
                          throws HiroException,
                                 java.io.IOException,
                                 java.lang.InterruptedException
        Decode the payload part of the internal token.
        Returns:
        Decoded token as DecodedToken.
        Throws:
        java.lang.InterruptedException - When call gets interrupted.
        java.io.IOException - When call has IO errors.
        HiroException - On Hiro protocol / handling errors.
      • refreshToken

        void refreshToken()
                   throws java.io.IOException,
                          java.lang.InterruptedException,
                          HiroException
        Refresh an invalid token.
        Throws:
        java.lang.InterruptedException - When call gets interrupted.
        java.io.IOException - When call has IO errors.
        HiroException - On Hiro protocol / handling errors.
      • revokeToken

        void revokeToken()
                  throws java.io.IOException,
                         java.lang.InterruptedException,
                         HiroException
        Revoke a token
        Throws:
        java.lang.InterruptedException - When call gets interrupted.
        java.io.IOException - When call has IO errors.
        HiroException - On Hiro protocol / handling errors.
      • hasToken

        boolean hasToken()
        Check for existence of a token in the TokenAPIHandler.
        Returns:
        true if a token has been set or retrieved, false if the token is empty.
      • hasRefreshToken

        boolean hasRefreshToken()
        Check for existence of a refresh token in the TokenAPIHandler.
        Returns:
        true if a refresh token retrieved, false if no such token exists or these tokens are not applicable for this TokenAPIHandler.
      • expiryInstant

        java.time.Instant expiryInstant()
        Calculate the Instant after which the token should be refreshed.
        Returns:
        The Instant after which the token shall be refreshed. null if token cannot be refreshed.
      • checkResponse

        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.
      • getApiURIOf

        java.net.URI getApiURIOf​(java.lang.String apiName)
                          throws java.io.IOException,
                                 java.lang.InterruptedException,
                                 HiroException
        Determine the API URI path for a named API.
        Parameters:
        apiName - Name of the API
        Returns:
        The URI for that API
        Throws:
        HiroException - When the request fails.
        java.io.IOException - When the connection fails.
        java.lang.InterruptedException - When interrupted.
      • buildWebSocketURI

        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
      • getOrBuildClient

        java.net.http.HttpClient getOrBuildClient()
        Returns:
        The HttpClient to use with this class.
      • getVersionMap

        VersionResponse getVersionMap()
                               throws HiroException,
                                      java.io.IOException,
                                      java.lang.InterruptedException
        Returns the current versionMap. If no versionMap is available, it will be requested, cached and then returned. if a sharedConnectionHandler is set, the versionMap will be obtained from there.
        Returns:
        The (cached) versionMap.
        Throws:
        HiroException - When the request fails.
        java.io.IOException - When the connection fails.
        java.lang.InterruptedException - When interrupted.
      • getRootApiURI

        java.net.URI getRootApiURI()
        Returns:
        Root URI of the API.
      • getUserAgent

        java.lang.String getUserAgent()
      • close

        void close()
        Close the underlying httpClientHandler.
        Specified by:
        close in interface java.lang.AutoCloseable
      • decodeToken

        static DecodedToken decodeToken​(java.lang.String token)
                                 throws HiroException,
                                        java.io.IOException
        Decode the payload part of any token.
        Parameters:
        token - The token to decode.
        Returns:
        Decoded token as DecodedToken.
        Throws:
        java.io.IOException - When call has IO errors.
        HiroException - On Hiro protocol / handling errors.