Package co.arago.hiro.client.rest
Class AuthenticatedAPIHandler
- java.lang.Object
-
- co.arago.util.validation.RequiredFieldChecks
-
- 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.
-
-
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.-
Nested classes/interfaces inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
AbstractAPIHandler.GetterConf
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringapiNameprotected java.lang.StringapiPathprotected java.net.URIapiUriprotected AbstractTokenAPIHandlertokenAPIHandler-
Fields inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
apiUrl, httpRequestTimeout, maxRetries, 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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Add Authorization.booleancheckResponse(java.net.http.HttpResponse<java.io.InputStream> httpResponse, int retryCount)Checks forTokenUnauthorizedExceptionandHiroHttpExceptionuntilAbstractAPIHandler.maxRetriesis exhausted.java.net.URIgetEndpointUri(URIPath path, java.util.Map<java.lang.String,java.lang.String> query, java.lang.String fragment)Construct my URI with query parameters and fragment.protected HttpLoggergetHttpLogger()Redirect the HttpLogger to the one provided intokenAPIHandler.protected java.net.http.HttpClientgetOrBuildClient()Redirect the HttpClient to the one provided intokenAPIHandler.protected static AbstractAPIHandler.GetterConfmakeHandlerConf(AuthenticatedAPIHandler.Conf<?> builder, AbstractTokenAPIHandler tokenAPIHandler)Construct an AbstractAPIHandler.GetterConf from the values of this Conf and the supplied tokenAPIHandler.-
Methods inherited from class co.arago.hiro.client.connection.AbstractAPIHandler
addQueryAndFragment, buildApiURI, buildEndpointURI, buildURI, buildWebSocketURI, delete, executeAsyncWithStreamBody, executeAsyncWithStringBody, executeBinary, executeWithStreamBody, executeWithStringBody, get, getApiUrl, getBinary, getHttpRequestTimeout, getMaxRetries, getRequestBuilder, 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 AbstractTokenAPIHandler tokenAPIHandler
-
apiUri
protected java.net.URI apiUri
-
-
Constructor Detail
-
AuthenticatedAPIHandler
protected AuthenticatedAPIHandler(AuthenticatedAPIHandler.Conf<?> builder)
Create this APIHandler by using its Builder.- Parameters:
builder- The builder to use.
-
-
Method Detail
-
makeHandlerConf
protected static AbstractAPIHandler.GetterConf makeHandlerConf(AuthenticatedAPIHandler.Conf<?> builder, AbstractTokenAPIHandler tokenAPIHandler)
Construct an AbstractAPIHandler.GetterConf from the values of this Conf and the supplied tokenAPIHandler. This ensures, that some values (AbstractAPIHandler.apiUrlandAbstractAPIHandler.userAgent) are always set via the tokenAPIHandler and some others use default values from there (AbstractAPIHandler.httpRequestTimeoutandAbstractAPIHandler.maxRetries) unless set in the builder for this Handler.- Parameters:
builder- The builder of this handler.tokenAPIHandler- The tokenApiHandler for this Handler.- Returns:
- An AbstractAPIHandler.GetterConf for the parent class.
-
getEndpointUri
public java.net.URI getEndpointUri(URIPath path, java.util.Map<java.lang.String,java.lang.String> 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- Map of 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(java.util.Map<java.lang.String,java.lang.String> headers) throws java.lang.InterruptedException, java.io.IOException, HiroExceptionAdd 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.maxRetriesis exhausted. Also tries to refresh the token onTokenUnauthorizedException.- Overrides:
checkResponsein classAbstractAPIHandler- Parameters:
httpResponse- The httpResponse from the HttpRequestretryCount- current counter for retries- Returns:
- true for a retry, false otherwise.
- Throws:
HiroException- If the check fails with a http status code error.java.io.IOException- When the refresh fails with an IO error.java.lang.InterruptedException- Call got interrupted.
-
getHttpLogger
protected HttpLogger getHttpLogger()
Redirect the HttpLogger to the one provided intokenAPIHandler.- Specified by:
getHttpLoggerin classAbstractAPIHandler- Returns:
- The HttpLogger to use with this class.
-
getOrBuildClient
protected java.net.http.HttpClient getOrBuildClient()
Redirect the HttpClient to the one provided intokenAPIHandler.- Specified by:
getOrBuildClientin classAbstractAPIHandler- Returns:
- The HttpClient to use with this class.
-
-