REQUEST
- The request type.RESPONSE
- The response type.public abstract class RefreshAuthTokenWrapper<REQUEST extends BmcRequest<?>,RESPONSE> extends Object implements AsyncHandler<REQUEST,RESPONSE>, Future<RESPONSE>
Combined future and callbacks for asynchronous requests intended to work with some authenticated calls, like instance principals.
This handler wraps a base AsyncHandler and has additional logic so that if a call fails with a 401, we'll refresh the auth token and then try again up to a given number of retries (it is recommended that we only do one retry).
It also wraps a delegate Future, and when the result of the future is requested, but the call fails with a 401, we perform the additional logic described above.
This is to account for scenarios where we have a valid/non-expired token but the permissions for the instance have changed since the token was issued and so on the server-side the presented token is considered invalid.
Constructor and Description |
---|
RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider,
AsyncHandler<REQUEST,RESPONSE> innerHandler,
Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> futureSupplier) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
beforeRetryAction()
Abstract action to be taken before a retry.
|
protected Future<RESPONSE> |
buildResponseFuture()
Call the future supplier to get the response future.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
RESPONSE |
get() |
RESPONSE |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
void |
onError(REQUEST request,
Throwable error)
Called if the request could not be completed successfully.
|
void |
onSuccess(REQUEST request,
RESPONSE response)
Called if the request was successfully completed.
|
boolean |
retryCall()
If we need to retry the request (i.e.
|
public RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST,RESPONSE> innerHandler, Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> futureSupplier)
public void onSuccess(REQUEST request, RESPONSE response)
AsyncHandler
Called if the request was successfully completed.
onSuccess
in interface AsyncHandler<REQUEST extends BmcRequest<?>,RESPONSE>
request
- The request that was made.response
- The response that was received.public void onError(REQUEST request, Throwable error)
AsyncHandler
Called if the request could not be completed successfully.
onError
in interface AsyncHandler<REQUEST extends BmcRequest<?>,RESPONSE>
request
- The request that was made.error
- The error that was received.public boolean retryCall()
If we need to retry the request (i.e. on a 401), this method contains the information on how to do that. This method will be leveraged by the onError callback of this handler.
protected abstract void beforeRetryAction()
Abstract action to be taken before a retry.
protected Future<RESPONSE> buildResponseFuture()
Call the future supplier to get the response future.
public boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled
in interface Future<RESPONSE>
public RESPONSE get() throws InterruptedException, ExecutionException
get
in interface Future<RESPONSE>
InterruptedException
ExecutionException
public RESPONSE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<RESPONSE>
InterruptedException
ExecutionException
TimeoutException
Copyright © 2016–2024. All rights reserved.