Search in sources :

Example 1 with MessagingExceptionHandlerAcceptor

use of org.mule.runtime.core.privileged.exception.MessagingExceptionHandlerAcceptor in project mule by mulesoft.

the class ErrorHandlerTestCase method ifUserDefaultIsMissingCatchAllThenGetsInjectedOurDefault.

@Test
public void ifUserDefaultIsMissingCatchAllThenGetsInjectedOurDefault() throws Exception {
    ErrorHandler errorHandler = new ErrorHandler();
    List<MessagingExceptionHandlerAcceptor> handlerList = new LinkedList<>();
    handlerList.add(mockTestExceptionStrategy1);
    errorHandler.setExceptionListeners(handlerList);
    errorHandler.setMuleContext(mockMuleContext);
    errorHandler.setRootContainerName("root");
    errorHandler.setName("myDefault");
    when(mockMuleContext.getConfiguration().getDefaultErrorHandlerName()).thenReturn("myDefault");
    when(mockMuleContext.getDefaultErrorHandler(of("root"))).thenReturn(errorHandler);
    errorHandler.initialise();
    assertThat(errorHandler.getExceptionListeners(), hasSize(3));
    assertThat(errorHandler.getExceptionListeners().get(0), is(instanceOf(OnCriticalErrorHandler.class)));
    assertThat(errorHandler.getExceptionListeners().get(1), is(mockTestExceptionStrategy1));
    MessagingExceptionHandlerAcceptor injected = errorHandler.getExceptionListeners().get(2);
    assertThat(injected, is(instanceOf(OnErrorPropagateHandler.class)));
}
Also used : MessagingExceptionHandlerAcceptor(org.mule.runtime.core.privileged.exception.MessagingExceptionHandlerAcceptor) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with MessagingExceptionHandlerAcceptor

use of org.mule.runtime.core.privileged.exception.MessagingExceptionHandlerAcceptor in project mule by mulesoft.

the class ErrorHandler method apply.

@Override
public Publisher<CoreEvent> apply(Exception exception) {
    if (exception instanceof MessagingException) {
        CoreEvent event = addExceptionPayload(exception, ((MessagingException) exception).getEvent());
        ((MessagingException) exception).setProcessedEvent(event);
        try {
            for (MessagingExceptionHandlerAcceptor exceptionListener : exceptionListeners) {
                if (exceptionListener.accept(event)) {
                    return exceptionListener.apply(exception);
                }
            }
            throw new MuleRuntimeException(createStaticMessage(MUST_ACCEPT_ANY_EVENT_MESSAGE));
        } catch (Exception e) {
            return error(new MessagingExceptionResolver(this).resolve(new MessagingException(event, e, this), muleContext));
        }
    } else {
        // This should never occur since all exceptions at this point are ME
        return error(exception);
    }
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingExceptionHandlerAcceptor(org.mule.runtime.core.privileged.exception.MessagingExceptionHandlerAcceptor) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MessagingExceptionResolver(org.mule.runtime.core.internal.util.MessagingExceptionResolver) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Aggregations

MessagingExceptionHandlerAcceptor (org.mule.runtime.core.privileged.exception.MessagingExceptionHandlerAcceptor)2 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 MessagingExceptionResolver (org.mule.runtime.core.internal.util.MessagingExceptionResolver)1 SmallTest (org.mule.tck.size.SmallTest)1