Search in sources :

Example 1 with OAuthConnectionProviderWrapper

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);
        }
    });
}
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)

Example 2 with OAuthConnectionProviderWrapper

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;
}
Also used : OAuthConnectionProviderWrapper(org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider)

Aggregations

OAuthConnectionProviderWrapper (org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.OAuthConnectionProviderWrapper)2 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 AccessTokenExpiredException (org.mule.runtime.extension.api.connectivity.oauth.AccessTokenExpiredException)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1