use of org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper 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);
}
});
}
use of org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper in project mule by mulesoft.
the class OAuthOperationMessageProcessor method getOAuthConnectionProvider.
private OAuthConnectionProviderWrapper getOAuthConnectionProvider(ExecutionContextAdapter operationContext) {
ConfigurationInstance config = ((ConfigurationInstance) operationContext.getConfiguration().get());
ConnectionProvider provider = unwrapProviderWrapper(config.getConnectionProvider().get(), OAuthConnectionProviderWrapper.class);
return provider instanceof OAuthConnectionProviderWrapper ? (OAuthConnectionProviderWrapper) provider : null;
}
Aggregations