Package co.arago.hiro.client.rest
Class AuthenticatedAPIHandler
- java.lang.Object
-
- co.arago.hiro.client.connection.AbstractAPIHandler
-
- co.arago.hiro.client.rest.AuthenticatedAPIHandler
-
public abstract class AuthenticatedAPIHandler extends AbstractAPIHandler
This class is the basis of all authenticated API handlers that make use of the different sections of the HIRO API. It copies its configuration from the suppliedTokenAPIHandlerand overridesAbstractAPIHandler.addToHeaders(HttpHeaderMap)andAbstractAPIHandler.checkResponse(HttpResponse, int)to handle tokens.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAuthenticatedAPIHandler.APIRequestConf<T extends AuthenticatedAPIHandler.APIRequestConf<T,R>,R>The basic configuration for all requests.static classAuthenticatedAPIHandler.Conf<T extends AuthenticatedAPIHandler.Conf<T>>Configuration interface for all the parameters of an AuthenticatedAPIHandler.static classAuthenticatedAPIHandler.SendBodyAPIRequestConf<T extends AuthenticatedAPIHandler.SendBodyAPIRequestConf<T,R>,R>The basic configuration for all requests that are sending JSON data.static classAuthenticatedAPIHandler.SendStreamAPIRequestConf<T extends AuthenticatedAPIHandler.SendStreamAPIRequestConf<T,R>,R>The basic configuration for all requests that upload binary data.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringapiNameprotected java.lang.StringapiPathprotected java.net.URIapiURIprotected TokenAPIHandlertokenAPIHandler-
Fields inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
httpClientHandler, httpRequestTimeout, maxRetries, rootApiURI, title, userAgent, version, webSocketURI
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAuthenticatedAPIHandler(AuthenticatedAPIHandler.Conf<?> builder)Create this APIHandler by using its Builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToHeaders(HttpHeaderMap headers)Add Authorization.booleancheckResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount)Checks forTokenUnauthorizedExceptionandHiroHttpExceptionuntilAbstractAPIHandler.getMaxRetries()is exhausted.java.net.URIgetEndpointURI(URIPath path, URIEncodedData query, java.lang.String fragment)Construct my URI with query parameters and fragment.-
Methods inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
addQueryFragmentAndNormalize, buildApiURI, buildEndpointURI, buildURI, buildWebSocketURI, delete, executeAsyncWithStreamBody, executeAsyncWithStringBody, executeBinary, executeWithStreamBody, executeWithStringBody, get, getBinary, getConf, getHttpLogger, getHttpRequestTimeout, getMaxRetries, getOrBuildClient, getRequestBuilder, getRootApiURI, getUserAgent, getWebSocketURI, patch, patchBinary, post, postBinary, put, putBinary, send, sendAsync
-
-
-
-
Field Detail
-
apiName
protected final java.lang.String apiName
-
apiPath
protected final java.lang.String apiPath
-
tokenAPIHandler
protected final TokenAPIHandler tokenAPIHandler
-
apiURI
protected java.net.URI apiURI
-
-
Constructor Detail
-
AuthenticatedAPIHandler
protected AuthenticatedAPIHandler(AuthenticatedAPIHandler.Conf<?> builder)
Create this APIHandler by using its Builder. The API configuration will be copied over from the builder.tokenAPIHandler.- Parameters:
builder- The builder to use.
-
-
Method Detail
-
getEndpointURI
public java.net.URI getEndpointURI(URIPath path, URIEncodedData query, java.lang.String fragment) throws java.io.IOException, java.lang.InterruptedException, HiroException
Construct my URI with query parameters and fragment. This method will query /api/version once to construct the URI unlessapiPathis set.- Parameters:
path- The path to append to the API path.query- Query parameters for this URI. Can be null for no query parameters.fragment- The fragment to add to the URI.- Returns:
- The URI with query parameters and fragment.
- Throws:
java.io.IOException- On a failed call to /api/versionjava.lang.InterruptedException- Call got interruptedHiroException- When calling /api/version responds with an error
-
addToHeaders
public void addToHeaders(HttpHeaderMap headers) throws java.lang.InterruptedException, java.io.IOException, HiroException
Add Authorization.- Specified by:
addToHeadersin classAbstractAPIHandler- Parameters:
headers- Map of headers with initial values.- Throws:
java.lang.InterruptedException- When a call (possibly of an overwritten method) gets interrupted.java.io.IOException- On IO errors.HiroException- On internal errors regarding hiro data processing.
-
checkResponse
public boolean checkResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount) throws HiroException, java.io.IOException, java.lang.InterruptedExceptionChecks forTokenUnauthorizedExceptionandHiroHttpExceptionuntilAbstractAPIHandler.getMaxRetries()is exhausted. Also tries to refresh the token onTokenUnauthorizedException.- Overrides:
checkResponsein classAbstractAPIHandler- Parameters:
httpResponse- The httpResponse from the HttpRequestretryCount- current counter for retries. Counts down to zero.- Returns:
- true for a retry, false otherwise.
- Throws:
TokenUnauthorizedException- When the statusCode is 401 and all retries are exhausted or the token cannot be refreshed.HiroHttpException- When the statusCode is < 200 or > 399 and all retries are exhausted.HiroException- On internal errors regarding hiro data processing.java.io.IOException- When the refresh fails with an IO error.java.lang.InterruptedException- Call got interrupted.
-
-