Search in sources :

Example 56 with MessagingException

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

the class ReactiveInterceptionAction method fail.

@Override
public CompletableFuture<InterceptionEvent> fail(ErrorType errorType) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Called fail() for processor {} with errorType {}", ((Component) processor).getLocation().getLocation(), errorType.getIdentifier());
    }
    Throwable cause = new InterceptionException("");
    interceptionEvent.setError(errorType, cause);
    CompletableFuture<InterceptionEvent> completableFuture = new CompletableFuture<>();
    completableFuture.completeExceptionally(new MessagingException(interceptionEvent.resolve(), cause, (Component) processor));
    return completableFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) Component(org.mule.runtime.api.component.Component)

Example 57 with MessagingException

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

the class AbstractExceptionListener method fireNotification.

protected void fireNotification(Exception ex, CoreEvent event) {
    if (enableNotifications) {
        if (ex.getCause() != null && getCause(ex) instanceof SecurityException) {
            fireNotification(new SecurityNotification((SecurityException) getCause(ex), SECURITY_AUTHENTICATION_FAILED));
        } else {
            Component component = null;
            if (ex instanceof MessagingException) {
                component = ((MessagingException) ex).getFailingComponent();
            }
            fireNotification(new ExceptionNotification(createInfo(event, ex, component), getLocation()));
        }
    }
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ExceptionNotification(org.mule.runtime.api.notification.ExceptionNotification) SecurityException(org.mule.runtime.api.security.SecurityException) Component(org.mule.runtime.api.component.Component) SecurityNotification(org.mule.runtime.api.notification.SecurityNotification)

Example 58 with MessagingException

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

the class AbstractExecutableComponent method execute.

@Override
public final CompletableFuture<Event> execute(Event event) {
    CoreEvent internalEvent;
    BaseEventContext child = createChildEventContext(event.getContext());
    if (event instanceof CoreEvent) {
        internalEvent = builder(child, (CoreEvent) event).build();
    } else {
        internalEvent = CoreEvent.builder(createEventContext(null)).message(event.getMessage()).error(event.getError().orElse(null)).variables(event.getVariables()).build();
    }
    return from(MessageProcessors.process(internalEvent, getExecutableFunction())).onErrorMap(throwable -> {
        MessagingException messagingException = (MessagingException) throwable;
        CoreEvent messagingExceptionEvent = messagingException.getEvent();
        return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
    }).map(r -> builder(event.getContext(), r).build()).cast(Event.class).toFuture();
}
Also used : Optional.of(java.util.Optional.of) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) CoreEvent.builder(org.mule.runtime.core.api.event.CoreEvent.builder) Event(org.mule.runtime.api.event.Event) ExecutionResult(org.mule.runtime.api.component.execution.ExecutionResult) Inject(javax.inject.Inject) MuleContext(org.mule.runtime.core.api.MuleContext) Mono.from(reactor.core.publisher.Mono.from) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) EventContext(org.mule.runtime.api.event.EventContext) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) NullExceptionHandler(org.mule.runtime.core.api.exception.NullExceptionHandler) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InputEvent(org.mule.runtime.api.component.execution.InputEvent) String.format(java.lang.String.format) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) ComponentExecutionException(org.mule.runtime.api.component.execution.ComponentExecutionException) MessageProcessors(org.mule.runtime.core.privileged.processor.MessageProcessors) ExecutableComponent(org.mule.runtime.api.component.execution.ExecutableComponent) Optional(java.util.Optional) DefaultEventContext.child(org.mule.runtime.core.internal.event.DefaultEventContext.child) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ComponentExecutionException(org.mule.runtime.api.component.execution.ComponentExecutionException) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) InputEvent(org.mule.runtime.api.component.execution.InputEvent)

Example 59 with MessagingException

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

the class IdempotentRedeliveryPolicy method createMessagingException.

private 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)

Example 60 with MessagingException

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

the class ExtensionSourceExceptionCallback method onException.

/**
 * Invokes {@link ResponseCompletionCallback#responseSentWithFailure(MessagingException, CoreEvent)} over the
 * {@link #completionCallback}, using the {@code exception} and {@link #event}
 *
 * @param exception a {@link Throwable}
 * @return a response {@link CoreEvent}
 */
@Override
public void onException(Throwable exception) {
    MessagingException messagingException = exception instanceof MessagingException ? (MessagingException) exception : new MessagingException(event, exception);
    CoreEvent errorEvent = createErrorEvent(event, messageProcessorContext.getMessageSource(), messagingException, messageProcessorContext.getErrorTypeLocator());
    messagingException.setProcessedEvent(errorEvent);
    CoreEvent errorHandlingEvent = completionCallback.responseSentWithFailure(messagingException, errorEvent);
    messagingException.setProcessedEvent(errorHandlingEvent);
    errorResponseHandler.accept(messagingException);
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

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