use of org.mule.runtime.api.exception.MuleException.INFO_ALREADY_LOGGED_KEY in project mule by mulesoft.
the class CompositeSourcePolicy method processNextOperation.
/**
* Executes the flow.
*
* If there's a {@link SourcePolicyParametersTransformer} provided then it will use it to convert the source response or source
* failure response from the parameters back to a {@link Message} that can be routed through the policy chain which later will
* be convert back to response or failure response parameters thus allowing the policy chain to modify the response.. That
* message will be the result of the next-operation of the policy.
*
* If no {@link SourcePolicyParametersTransformer} is provided, then the same response from the flow is going to be routed as
* response of the next-operation of the policy chain. In this case, the same response from the flow is going to be used to
* generate the response or failure response for the source so the policy chain is not going to be able to modify the response
* sent by the source.
*
* When the flow execution fails, it will create a {@link FlowExecutionException} instead of a regular
* {@link MessagingException} to signal that the failure was through the the flow exception and not the policy logic.
*/
@Override
protected Publisher<CoreEvent> processNextOperation(CoreEvent event) {
return just(event).flatMap(request -> from(processWithChildContext(request, flowExecutionProcessor, empty()))).map(flowExecutionResponse -> {
originalResponseParameters = getParametersProcessor().getSuccessfulExecutionResponseParametersFunction().apply(flowExecutionResponse);
Message message = getParametersTransformer().map(parametersTransformer -> parametersTransformer.fromSuccessResponseParametersToMessage(originalResponseParameters)).orElseGet(flowExecutionResponse::getMessage);
return CoreEvent.builder(event).message(message).build();
}).onErrorMap(MessagingException.class, messagingException -> {
originalFailureResponseParameters = getParametersProcessor().getFailedExecutionResponseParametersFunction().apply(messagingException.getEvent());
Message message = getParametersTransformer().map(parametersTransformer -> parametersTransformer.fromFailureResponseParametersToMessage(originalFailureResponseParameters)).orElse(messagingException.getEvent().getMessage());
MessagingException flowExecutionException = new FlowExecutionException(CoreEvent.builder(messagingException.getEvent()).message(message).build(), messagingException.getCause(), messagingException.getFailingComponent());
if (messagingException.getInfo().containsKey(INFO_ALREADY_LOGGED_KEY)) {
flowExecutionException.addInfo(INFO_ALREADY_LOGGED_KEY, messagingException.getInfo().get(INFO_ALREADY_LOGGED_KEY));
}
return flowExecutionException;
}).doOnError(e -> LOGGER.error(e.getMessage(), e));
}
use of org.mule.runtime.api.exception.MuleException.INFO_ALREADY_LOGGED_KEY in project mule by mulesoft.
the class MessagingExceptionResolver method resolve.
/**
* Resolves a new {@link MessagingException} with the real cause of the problem based on the content of an Incoming
* {@link MessagingException} with a chain of causes inside it and the current event that the exception is carrying.
* <p>
* This method will pick the FIRST cause exception that has a mule or extension KNOWN error as the real cause, if there is not
* an exception in the causes that match with an Known error type then this method will try to find the error that the current
* {@link Event} is carrying.
* <p>
* When there are multiple exceptions that contains the same root error type, then this method will wrap the one that has
* highest position in the causes list
*
* @return a {@link MessagingException} with the proper {@link Error} associated to it's {@link CoreEvent}
*/
public MessagingException resolve(final MessagingException me, MuleContext context) {
ErrorTypeLocator locator = ((PrivilegedMuleContext) context).getErrorTypeLocator();
Optional<Pair<Throwable, ErrorType>> rootCause = findRoot(component, me, locator);
if (!rootCause.isPresent()) {
return updateCurrent(me, component, context);
}
Throwable root = rootCause.get().getFirst();
ErrorType rootErrorType = rootCause.get().getSecond();
Component failingComponent = getFailingProcessor(me, root).orElse(component);
ErrorType errorType = getErrorMappings(component).stream().filter(m -> m.match(rootErrorType)).findFirst().map(ErrorMapping::getTarget).orElse(rootErrorType);
Error error = ErrorBuilder.builder(getMessagingExceptionCause(root)).errorType(errorType).build();
CoreEvent event = CoreEvent.builder(me.getEvent()).error(error).build();
MessagingException result;
if (root instanceof MessagingException) {
((MessagingException) root).setProcessedEvent(event);
result = ((MessagingException) root);
} else {
result = me instanceof FlowExecutionException ? new FlowExecutionException(event, root, failingComponent) : new MessagingException(event, root, failingComponent);
}
if (me.getInfo().containsKey(INFO_ALREADY_LOGGED_KEY)) {
result.addInfo(INFO_ALREADY_LOGGED_KEY, me.getInfo().get(INFO_ALREADY_LOGGED_KEY));
}
return enrich(result, failingComponent, event, context);
}
Aggregations