Search in sources :

Example 16 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class MessagingExceptionTestCase method getCauseExceptionWithMuleCauseWithMuleCause.

@Test
public void getCauseExceptionWithMuleCauseWithMuleCause() {
    DefaultMuleException causeCauseException = new DefaultMuleException("");
    DefaultMuleException causeException = new DefaultMuleException(causeCauseException);
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, causeException);
    assertThat(exception.getRootCause(), is(causeCauseException));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 17 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class MessagingExceptionTestCase method causedByWithMuleCauseWithMuleCause.

@Test
public void causedByWithMuleCauseWithMuleCause() {
    DefaultMuleException causeCauseException = new DefaultMuleException("");
    DefaultMuleException causeException = new DefaultMuleException(causeCauseException);
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, causeException);
    assertThat(exception.causedBy(DefaultMuleException.class), is(true));
    assertThat(exception.causedBy(MessagingException.class), is(true));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 18 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method childErrorsErrorBinding.

@Test
public void childErrorsErrorBinding() throws Exception {
    String childErrorMessage = "error";
    String otherChildErrorMessage = "oops";
    ErrorType errorType = mock(ErrorType.class);
    Error error = mock(Error.class);
    when(error.getChildErrors()).thenReturn(asList(ErrorBuilder.builder(new IOException(childErrorMessage)).errorType(errorType).build(), ErrorBuilder.builder(new DefaultMuleException(otherChildErrorMessage)).errorType(errorType).build()));
    Optional opt = Optional.of(error);
    CoreEvent event = getEventWithError(opt);
    doReturn(testEvent().getMessage()).when(event).getMessage();
    String expression = "error.childErrors reduce ((child, acc = '') -> acc ++ child.cause.message)";
    TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(format("%s%s", childErrorMessage, otherChildErrorMessage)));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 19 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class SystemUtils method parseCommandLine.

// TODO MULE-1947 Command-line arguments should be handled exclusively by the bootloader
private static CommandLine parseCommandLine(String[] args, String[][] opts) throws MuleException {
    Options options = new Options();
    for (String[] opt : opts) {
        options.addOption(opt[0], opt[1].equals("true") ? true : false, opt[2]);
    }
    BasicParser parser = new BasicParser();
    try {
        CommandLine line = parser.parse(options, args, true);
        if (line == null) {
            throw new DefaultMuleException("Unknown error parsing the Mule command line");
        }
        return line;
    } catch (ParseException p) {
        throw new DefaultMuleException("Unable to parse the Mule command line because of: " + p.toString(), p);
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) Options(org.apache.commons.cli.Options) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException)

Example 20 with DefaultMuleException

use of org.mule.runtime.api.exception.DefaultMuleException in project mule by mulesoft.

the class TryScope method process.

@Override
public CoreEvent process(final CoreEvent event) throws MuleException {
    if (nestedChain == null) {
        return event;
    } else {
        ExecutionTemplate<CoreEvent> executionTemplate = createScopeTransactionalExecutionTemplate(muleContext, transactionConfig);
        ExecutionCallback<CoreEvent> processingCallback = () -> {
            try {
                CoreEvent e = processToApply(event, p -> from(p).flatMap(request -> processWithChildContext(request, nestedChain, ofNullable(getLocation()), messagingExceptionHandler)));
                return e;
            } catch (Exception e) {
                throw e;
            }
        };
        try {
            return executionTemplate.execute(processingCallback);
        } catch (MuleException e) {
            throw e;
        } catch (Exception e) {
            throw new DefaultMuleException(errorInvokingMessageProcessorWithinTransaction(nestedChain, transactionConfig), e);
        }
    }
}
Also used : CoreMessages.errorInvokingMessageProcessorWithinTransaction(org.mule.runtime.core.api.config.i18n.CoreMessages.errorInvokingMessageProcessorWithinTransaction) TransactionalExecutionTemplate.createScopeTransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate.createScopeTransactionalExecutionTemplate) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) Optional.of(java.util.Optional.of) Flux.from(reactor.core.publisher.Flux.from) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) LoggerFactory(org.slf4j.LoggerFactory) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) TransactionCoordination.isTransactionActive(org.mule.runtime.core.api.transaction.TransactionCoordination.isTransactionActive) Collections.singletonList(java.util.Collections.singletonList) Scope(org.mule.runtime.core.privileged.processor.Scope) TransactionConfig(org.mule.runtime.core.api.transaction.TransactionConfig) MuleException(org.mule.runtime.api.exception.MuleException) AbstractMessageProcessorOwner(org.mule.runtime.core.api.processor.AbstractMessageProcessorOwner) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) Optional.ofNullable(java.util.Optional.ofNullable) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) ACTION_INDIFFERENT(org.mule.runtime.core.api.transaction.TransactionConfig.ACTION_INDIFFERENT) FlowExceptionHandler(org.mule.runtime.core.api.exception.FlowExceptionHandler) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) List(java.util.List) ExecutionTemplate(org.mule.runtime.core.api.execution.ExecutionTemplate) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) MessageProcessors.getProcessingStrategy(org.mule.runtime.core.privileged.processor.MessageProcessors.getProcessingStrategy) ExecutionCallback(org.mule.runtime.core.api.execution.ExecutionCallback) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

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