use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class AbstractOutboundRouter method process.
@Override
public CoreEvent process(final CoreEvent event) throws MuleException {
ExecutionTemplate<CoreEvent> executionTemplate = createTransactionalExecutionTemplate(muleContext, getTransactionConfig());
ExecutionCallback<CoreEvent> processingCallback = () -> {
try {
return route(event);
} catch (RoutingException e1) {
throw e1;
} catch (Exception e2) {
throw new RoutingException(AbstractOutboundRouter.this, e2);
}
};
try {
return executionTemplate.execute(processingCallback);
} catch (MuleException e) {
throw e;
} catch (Exception e) {
throw new DefaultMuleException(e);
}
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class ExceptionHelperTestCase method getException.
private Exception getException() {
DefaultMuleException innerMuleException = new DefaultMuleException(createStaticMessage("bar"), new Exception("blah"));
innerMuleException.addInfo("info_1", "Imma in!");
DefaultMuleException outerMuleException = new DefaultMuleException(createStaticMessage("foo"), innerMuleException);
outerMuleException.addInfo("info_1", "Imma out!");
outerMuleException.addInfo("info_2", "Imma out!");
return outerMuleException;
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class ErrorBuilderTestCase method buildErrorFromMuleException.
@Test
public void buildErrorFromMuleException() {
MuleException exception = new DefaultMuleException(new RuntimeException(EXCEPTION_MESSAGE));
Error error = builder(exception).errorType(mockErrorType).build();
assertThat(error.getCause(), is(exception));
assertThat(error.getDescription(), containsString(EXCEPTION_MESSAGE));
assertThat(error.getDetailedDescription(), containsString(EXCEPTION_MESSAGE));
assertThat(error.getErrorType(), is(mockErrorType));
assertThat(error.getChildErrors(), is(empty()));
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class MuleMessageProcessingManagerTestCase method createFailureMessageProcessPhase.
private MessageProcessPhase createFailureMessageProcessPhase() {
FailureMessageProcessPhase failureMessageProcessPhase = mock(FailureMessageProcessPhase.class, Answers.RETURNS_DEEP_STUBS.get());
when(failureMessageProcessPhase.supportsTemplate(any(MessageProcessTemplate.class))).thenCallRealMethod();
doAnswer(invocationOnMock -> {
PhaseResultNotifier phaseResultNotifier = (PhaseResultNotifier) invocationOnMock.getArguments()[2];
phaseResultNotifier.phaseFailure(new DefaultMuleException("error"));
return null;
}).when(failureMessageProcessPhase).runPhase(any(MessageProcessTemplate.class), any(MessageProcessContext.class), any(PhaseResultNotifier.class));
return failureMessageProcessPhase;
}
use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.
the class FlowProcessingPhase method runPhase.
@Override
public void runPhase(final FlowProcessingPhaseTemplate flowProcessingPhaseTemplate, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
Runnable flowExecutionWork = () -> {
try {
FlowConstruct flowConstruct = registry.<FlowConstruct>lookupByName(messageProcessContext.getMessageSource().getRootContainerLocation().toString()).get();
try {
final AtomicReference exceptionThrownDuringFlowProcessing = new AtomicReference();
TransactionalExecutionTemplate<CoreEvent> transactionTemplate = createTransactionalExecutionTemplate(muleContext, messageProcessContext.getTransactionConfig().orElse(new MuleTransactionConfig()));
CoreEvent response = transactionTemplate.execute(() -> {
try {
Object message = flowProcessingPhaseTemplate.getOriginalMessage();
if (message == null) {
return null;
}
CoreEvent muleEvent = flowProcessingPhaseTemplate.getEvent();
muleEvent = flowProcessingPhaseTemplate.beforeRouteEvent(muleEvent);
muleEvent = flowProcessingPhaseTemplate.routeEvent(muleEvent);
muleEvent = flowProcessingPhaseTemplate.afterRouteEvent(muleEvent);
sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, muleEvent, flowProcessingPhaseTemplate);
return muleEvent;
} catch (Exception e) {
exceptionThrownDuringFlowProcessing.set(e);
throw e;
}
});
if (exceptionThrownDuringFlowProcessing.get() != null && !(exceptionThrownDuringFlowProcessing.get() instanceof ResponseDispatchException)) {
sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, response, flowProcessingPhaseTemplate);
}
flowProcessingPhaseTemplate.afterSuccessfulProcessingFlow(response);
} catch (ResponseDispatchException e) {
flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
} catch (MessagingException e) {
sendFailureResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, e, flowProcessingPhaseTemplate);
flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
}
phaseResultNotifier.phaseSuccessfully();
} catch (Exception e) {
MuleException me = new DefaultMuleException(e);
try {
flowProcessingPhaseTemplate.afterFailureProcessingFlow(me);
} catch (MuleException e1) {
logger.warn("Failure during exception processing in flow template: " + e.getMessage());
if (logger.isDebugEnabled()) {
logger.debug("Failure during exception processing in flow template: ", e);
}
}
phaseResultNotifier.phaseFailure(e);
}
};
if (messageProcessContext.supportsAsynchronousProcessing()) {
try {
messageProcessContext.getFlowExecutionExecutor().execute(flowExecutionWork);
} catch (SchedulerBusyException e) {
phaseResultNotifier.phaseFailure(e);
}
} else {
flowExecutionWork.run();
}
}
Aggregations