Class RefreshAuthTokenWrapper<REQUEST extends BmcRequest<?>,RESPONSE>
- java.lang.Object
-
- com.oracle.bmc.util.internal.RefreshAuthTokenWrapper<REQUEST,RESPONSE>
-
- Type Parameters:
REQUEST- The request type.RESPONSE- The response type.
- All Implemented Interfaces:
AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>
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 Summary
Constructors Constructor Description RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST,RESPONSE> innerHandler, Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> futureSupplier)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidbeforeRetryAction()Abstract action to be taken before a retry.protected Future<RESPONSE>buildResponseFuture()Call the future supplier to get the response future.booleancancel(boolean mayInterruptIfRunning)RESPONSEget()RESPONSEget(long timeout, TimeUnit unit)booleanisCancelled()booleanisDone()voidonError(REQUEST request, Throwable error)Called if the request could not be completed successfully.voidonSuccess(REQUEST request, RESPONSE response)Called if the request was successfully completed.booleanretryCall()If we need to retry the request (i.e.
-
-
-
Constructor Detail
-
RefreshAuthTokenWrapper
public RefreshAuthTokenWrapper(RefreshableOnNotAuthenticatedProvider<?> authDetailsProvider, AsyncHandler<REQUEST,RESPONSE> innerHandler, Function<AsyncHandler<REQUEST,RESPONSE>,Future<RESPONSE>> futureSupplier)
-
-
Method Detail
-
onSuccess
public void onSuccess(REQUEST request, RESPONSE response)
Description copied from interface:AsyncHandlerCalled if the request was successfully completed.- Specified by:
onSuccessin interfaceAsyncHandler<REQUEST extends BmcRequest<?>,RESPONSE>- Parameters:
request- The request that was made.response- The response that was received.
-
onError
public void onError(REQUEST request, Throwable error)
Description copied from interface:AsyncHandlerCalled if the request could not be completed successfully.- Specified by:
onErrorin interfaceAsyncHandler<REQUEST extends BmcRequest<?>,RESPONSE>- Parameters:
request- The request that was made.error- The error that was received.
-
retryCall
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.
- Returns:
- false if the retry was not allowed because of the number of attempts
-
beforeRetryAction
protected abstract void beforeRetryAction()
Abstract action to be taken before a retry.
-
buildResponseFuture
protected Future<RESPONSE> buildResponseFuture()
Call the future supplier to get the response future.- Returns:
- response future
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancelin interfaceFuture<REQUEST extends BmcRequest<?>>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<REQUEST extends BmcRequest<?>>
-
isDone
public boolean isDone()
- Specified by:
isDonein interfaceFuture<REQUEST extends BmcRequest<?>>
-
get
public RESPONSE get() throws InterruptedException, ExecutionException
- Specified by:
getin interfaceFuture<REQUEST extends BmcRequest<?>>- Throws:
InterruptedExceptionExecutionException
-
get
public RESPONSE get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
getin interfaceFuture<REQUEST extends BmcRequest<?>>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
-