Search in sources :

Example 1 with DefaultMuleException

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);
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DispatchException(org.mule.runtime.core.privileged.connector.DispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Example 2 with DefaultMuleException

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;
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ExceptionHelper.getRootException(org.mule.runtime.api.exception.ExceptionHelper.getRootException) ExceptionHelper.getNonMuleException(org.mule.runtime.api.exception.ExceptionHelper.getNonMuleException) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) ExceptionHelper.getRootMuleException(org.mule.runtime.api.exception.ExceptionHelper.getRootMuleException) ResolverException(org.mule.runtime.core.internal.transformer.ResolverException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Example 3 with DefaultMuleException

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()));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) Error(org.mule.runtime.api.message.Error) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with DefaultMuleException

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;
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MessageProcessContext(org.mule.runtime.core.privileged.execution.MessageProcessContext) MessageProcessTemplate(org.mule.runtime.core.privileged.execution.MessageProcessTemplate)

Example 5 with DefaultMuleException

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();
    }
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) AtomicReference(java.util.concurrent.atomic.AtomicReference) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SchedulerBusyException(org.mule.runtime.api.scheduler.SchedulerBusyException) ResponseDispatchException(org.mule.runtime.core.privileged.exception.ResponseDispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) TransactionalExecutionTemplate.createTransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate.createTransactionalExecutionTemplate) TransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ResponseDispatchException(org.mule.runtime.core.privileged.exception.ResponseDispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) SchedulerBusyException(org.mule.runtime.api.scheduler.SchedulerBusyException)

Aggregations

DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)26 Test (org.junit.Test)12 MuleException (org.mule.runtime.api.exception.MuleException)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)8 SmallTest (org.mule.tck.size.SmallTest)6 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)5 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)5 IOException (java.io.IOException)3 ConnectionException (org.mule.runtime.api.connection.ConnectionException)3 URL (java.net.URL)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)2 MuleCoreExtension (org.mule.runtime.container.api.MuleCoreExtension)2 Processor (org.mule.runtime.core.api.processor.Processor)2 MessageProcessors.processToApply (org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply)2 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)2 RoutingException (org.mule.runtime.core.privileged.routing.RoutingException)2