Search in sources :

Example 6 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class FlowExceptionHandler method apply.

@Override
default Publisher<CoreEvent> apply(Exception exception) {
    try {
        if (exception instanceof MessagingException) {
            MessagingException me = (MessagingException) exception;
            me.setProcessedEvent(handleException(exception, me.getEvent()));
            if (me.handled()) {
                return just(me.getEvent());
            } else {
                return error(exception);
            }
        } else {
            return error(exception);
        }
    } catch (Throwable throwable) {
        return error(propagateWrappingFatal(throwable));
    }
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException)

Example 7 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class InvokerMessageProcessor method evaluateArguments.

protected Object[] evaluateArguments(CoreEvent event, List<?> argumentTemplates) throws MessagingException {
    int argSize = argumentTemplates != null ? argumentTemplates.size() : 0;
    Object[] args = new Object[argSize];
    try {
        for (int i = 0; i < args.length; i++) {
            Object argumentTemplate = argumentTemplates.get(i);
            if (argumentTemplate != null) {
                args[i] = transformArgument(evaluateExpressionCandidate(argumentTemplate, event), argumentTypes[i]);
            }
        }
        return args;
    } catch (TransformerException e) {
        throw new MessagingException(event, e, this);
    }
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) CoreMessages.methodWithParamsNotFoundOnObject(org.mule.runtime.core.api.config.i18n.CoreMessages.methodWithParamsNotFoundOnObject) CoreMessages.methodWithNumParamsNotFoundOnObject(org.mule.runtime.core.api.config.i18n.CoreMessages.methodWithNumParamsNotFoundOnObject) TransformerException(org.mule.runtime.core.api.transformer.TransformerException)

Example 8 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class OperationPolicyProcessor method executePolicyChain.

private Mono<PrivilegedEvent> executePolicyChain(PrivilegedEvent operationEvent, PolicyStateId policyStateId, PrivilegedEvent policyEvent) {
    PolicyChain policyChain = policy.getPolicyChain();
    policyChain.onChainError(t -> manageError(policyStateId, operationEvent, (MessagingException) t));
    return just(policyEvent).doOnNext(event -> logPolicy(event.getContext().getCorrelationId(), policyStateId.getPolicyId(), getMessageAttributesAsString(event), "Before operation")).cast(CoreEvent.class).transform(policyChain).cast(PrivilegedEvent.class).doOnNext(policyChainResult -> policyStateHandler.updateState(policyStateId, policyChainResult)).map(policyChainResult -> policyEventConverter.createEvent(policyChainResult, operationEvent)).doOnNext(event -> logPolicy(event.getContext().getCorrelationId(), policyStateId.getPolicyId(), getMessageAttributesAsString(event), "After operation"));
}
Also used : PolicyStateId(org.mule.runtime.core.api.policy.PolicyStateId) PolicyStateHandler(org.mule.runtime.core.api.policy.PolicyStateHandler) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) Message.of(org.mule.runtime.api.message.Message.of) Processor(org.mule.runtime.core.api.processor.Processor) PolicyChain(org.mule.runtime.core.api.policy.PolicyChain) MuleException(org.mule.runtime.api.exception.MuleException) Policy(org.mule.runtime.core.api.policy.Policy) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Optional(java.util.Optional) PolicyChain(org.mule.runtime.core.api.policy.PolicyChain) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Example 9 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException 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));
}
Also used : Optional.empty(java.util.Optional.empty) Logger(org.slf4j.Logger) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer) INFO_ALREADY_LOGGED_KEY(org.mule.runtime.api.exception.MuleException.INFO_ALREADY_LOGGED_KEY) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) HashMap(java.util.HashMap) Either.left(org.mule.runtime.core.api.functional.Either.left) Processor(org.mule.runtime.core.api.processor.Processor) Supplier(java.util.function.Supplier) Either.right(org.mule.runtime.core.api.functional.Either.right) Either(org.mule.runtime.core.api.functional.Either) List(java.util.List) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) Policy(org.mule.runtime.core.api.policy.Policy) MessageProcessors(org.mule.runtime.core.privileged.processor.MessageProcessors) Map(java.util.Map) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Optional(java.util.Optional) Message(org.mule.runtime.api.message.Message) MessagingException(org.mule.runtime.core.internal.exception.MessagingException)

Example 10 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class ReactiveInterceptorAdapter method createMessagingException.

protected MessagingException createMessagingException(CoreEvent event, Throwable cause, Component processor) {
    MessagingExceptionResolver exceptionResolver = new MessagingExceptionResolver(processor);
    MessagingException me = new MessagingException(event, cause, processor);
    return exceptionResolver.resolve(me, muleContext);
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) MessagingExceptionResolver(org.mule.runtime.core.internal.util.MessagingExceptionResolver)

Aggregations

MessagingException (org.mule.runtime.core.internal.exception.MessagingException)69 Test (org.junit.Test)42 SmallTest (org.mule.tck.size.SmallTest)37 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)26 MuleException (org.mule.runtime.api.exception.MuleException)17 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)13 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)11 Optional (java.util.Optional)9 Error (org.mule.runtime.api.message.Error)9 Message (org.mule.runtime.api.message.Message)9 IOException (java.io.IOException)8 Processor (org.mule.runtime.core.api.processor.Processor)8 Publisher (org.reactivestreams.Publisher)8 ConnectException (java.net.ConnectException)7 Component (org.mule.runtime.api.component.Component)7 ConnectionException (org.mule.runtime.api.connection.ConnectionException)7 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)7 SocketException (java.net.SocketException)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)6