Search in sources :

Example 1 with AccessTokenExpiredException

use of org.mule.runtime.extension.api.connectivity.oauth.AccessTokenExpiredException in project mule by mulesoft.

the class OAuthOperationMessageProcessor method doProcess.

@Override
protected Mono<CoreEvent> doProcess(CoreEvent event, ExecutionContextAdapter<OperationModel> operationContext) {
    return super.doProcess(event, operationContext).onErrorResume(AccessTokenExpiredException.class, e -> {
        OAuthConnectionProviderWrapper connectionProvider = getOAuthConnectionProvider(operationContext);
        if (connectionProvider == null) {
            return error(e);
        }
        AccessTokenExpiredException expiredException = getTokenExpirationException(e);
        if (expiredException != null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format("AccessToken for resourceOwner '%s' expired while executing operation '%s:%s' using config '%s'. " + "Will attempt to refresh token and retry operation", connectionProvider.getResourceOwnerId(), getExtensionModel().getName(), operationContext.getComponentModel().getName(), operationContext.getConfiguration().get().getName()));
            }
            String ownerConfigName = operationContext.getConfiguration().get().getName();
            try {
                oauthManager.refreshToken(ownerConfigName, expiredException.getResourceOwnerId(), getOAuthConnectionProvider(operationContext));
            } catch (Exception refreshException) {
                return error(new MuleRuntimeException(createStaticMessage(format("AccessToken for resourceOwner '%s' expired while executing operation '%s:%s' using config '%s'. Refresh token " + "workflow was attempted but failed with the following exception", connectionProvider.getResourceOwnerId(), getExtensionModel().getName(), operationContext.getComponentModel().getName(), operationContext.getConfiguration().get().getName())), refreshException));
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(format("Access Token successfully refreshed for resourceOwnerId '%s' on config '%s'", connectionProvider.getResourceOwnerId(), operationContext.getConfiguration().get().getName()));
            }
            return super.doProcess(event, operationContext);
        } else {
            return error(e);
        }
    });
}
Also used : AccessTokenExpiredException(org.mule.runtime.extension.api.connectivity.oauth.AccessTokenExpiredException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) OAuthConnectionProviderWrapper(org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper) AccessTokenExpiredException(org.mule.runtime.extension.api.connectivity.oauth.AccessTokenExpiredException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 AccessTokenExpiredException (org.mule.runtime.extension.api.connectivity.oauth.AccessTokenExpiredException)1 OAuthConnectionProviderWrapper (org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper)1