use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class DefaultExtensionsOAuthManager method refreshToken.
/**
* {@inheritDoc}
*/
@Override
public void refreshToken(String ownerConfigName, String resourceOwnerId, OAuthConnectionProviderWrapper connectionProvider) {
AuthorizationCodeOAuthDancer dancer = dancers.get(ownerConfigName);
try {
dancer.refreshToken(resourceOwnerId).get();
connectionProvider.updateAuthState();
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage(format("Could not refresh token for resourceOwnerId '%s' using config '%s'", resourceOwnerId, ownerConfigName)), e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ReflectiveFunctionExecutorFactory method createExecutor.
@Override
public FunctionExecutor createExecutor(FunctionModel functionModel, FunctionParameterDefaultValueResolverFactory defaultResolverFactory) {
DataType returnType = fromType(getType(functionModel.getOutput().getType()).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format("Failed to obtain the return type for function [%s]", functionModel.getName())))));
List<FunctionParameter> functionParameters = functionModel.getAllParameterModels().stream().map(p -> {
MetadataType paramType = p.getType();
DataType type = isTypedValue(paramType) ? fromType(TypedValue.class) : toDataType(paramType);
if (p.isRequired()) {
return new FunctionParameter(p.getName(), type);
}
Object defaultValue = p.getDefaultValue();
if (defaultValue == null) {
return new FunctionParameter(p.getName(), type, context -> Defaults.defaultValue(type.getType()));
}
return new FunctionParameter(p.getName(), type, defaultResolverFactory.create(defaultValue, type));
}).collect(toList());
return new ReflectiveExpressionFunctionExecutor(functionModel, returnType, functionParameters, method, getDelegateInstance());
}
use of org.mule.runtime.api.exception.MuleRuntimeException 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.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ConnectionArgumentResolver method resolve.
/**
* Returns the connection previously set on the {@code executionContext} under the key
* {@link ExtensionProperties#CONNECTION_PARAM}
*
* @param executionContext an {@link ExecutionContext}
* @return the connection
* @throws IllegalArgumentException if the connection was not set
* @throws ClassCastException if {@code executionContext} is not an {@link ExecutionContextAdapter}
*/
@Override
public LazyValue<Object> resolve(ExecutionContext executionContext) {
return new LazyValue<>(() -> {
ConnectionHandler connectionHandler = ((ExecutionContextAdapter<ComponentModel>) executionContext).getVariable(CONNECTION_PARAM);
checkArgument(connectionHandler != null, "No connection was provided for the component [" + executionContext.getComponentModel().getName() + "]");
try {
return connectionHandler.getConnection();
} catch (ConnectionException e) {
throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage(String.format("Error was found trying to obtain a connection to execute %s '%s' of extension '%s'", getComponentModelTypeName(executionContext.getComponentModel()), executionContext.getComponentModel().getName(), executionContext.getExtensionModel().getName())), e);
}
});
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class OAuthConnectionProviderObjectBuilder method getCustomParameters.
private Map<String, String> getCustomParameters(CoreEvent event) {
Map<String, String> oauthParams = new HashMap<>();
withCustomParameters((parameter, property) -> {
String alias = property.getRequestAlias();
if (StringUtils.isBlank(alias)) {
alias = parameter.getName();
}
ValueResolver resolver = resolverSet.getResolvers().get(alias);
if (resolver != null) {
try {
oauthParams.put(alias, resolveString(event, resolver));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
return oauthParams;
}
Aggregations