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)));
}
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);
}
}
Aggregations