Search in sources :

Example 31 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class AbstractMessageSequenceSplitter method processParts.

protected List<CoreEvent> processParts(MessageSequence<?> seq, CoreEvent originalEvent) throws MuleException {
    List<CoreEvent> resultEvents = new ArrayList<>();
    int correlationSequence = 0;
    MessageSequence<?> messageSequence = seq;
    if (batchSize > 1) {
        messageSequence = new PartitionedMessageSequence<>(seq, batchSize);
    }
    Integer count = messageSequence.size();
    CoreEvent lastResult = null;
    for (; messageSequence.hasNext(); ) {
        correlationSequence++;
        final Builder builder = builder(originalEvent);
        propagateFlowVars(lastResult, builder);
        if (counterVariableName != null) {
            builder.addVariable(counterVariableName, correlationSequence);
        }
        builder.groupCorrelation(Optional.of(count != null ? GroupCorrelation.of(correlationSequence, count) : GroupCorrelation.of(correlationSequence)));
        Object nextValue = messageSequence.next();
        initEventBuilder(nextValue, originalEvent, builder, resolvePropagatedFlowVars(lastResult));
        try {
            // TODO MULE-13052 Migrate Splitter and Foreach implementation to non-blocking
            CoreEvent resultEvent = processToApplyWithChildContext(builder.build(), applyNext());
            if (resultEvent != null) {
                resultEvents.add(builder(originalEvent.getContext(), resultEvent).build());
                lastResult = resultEvent;
            }
        } catch (MessagingException e) {
            if (!filterOnErrorTypeAcceptor.accept(e.getEvent())) {
                throw e;
            }
        } finally {
            if (nextValue instanceof EventBuilderConfigurer) {
                ((EventBuilderConfigurer) nextValue).eventCompleted();
            }
        }
    }
    if (correlationSequence == 1) {
        logger.debug("Splitter only returned a single result. If this is not expected, please check your split expression");
    }
    return resultEvents;
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Builder(org.mule.runtime.core.api.event.CoreEvent.Builder) ArrayList(java.util.ArrayList)

Example 32 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class ExtensionSourceExceptionCallbackTestCase method exceptionHandlingCallbackInvoked.

@Test
public void exceptionHandlingCallbackInvoked() {
    ArgumentCaptor<MessagingException> exceptionCaptor = forClass(MessagingException.class);
    onException();
    verify(exceptionHandlingCallback).accept(exceptionCaptor.capture());
    MessagingException messagingException = exceptionCaptor.getValue();
    assertThat(messagingException, is(notNullValue()));
    assertThat(messagingException.getCause(), is(sameInstance(exception)));
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 33 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method getCauseExceptionWithoutCause.

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

Example 34 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method getCauseExceptionWithMuleCause.

@Test
public void getCauseExceptionWithMuleCause() {
    DefaultMuleException causeException = new DefaultMuleException("");
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, causeException);
    assertThat(exception.getRootCause(), is(causeException));
}
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 35 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method causedExactlyByWithNonMuleCauseWithNonMuleCause.

@Test
public void causedExactlyByWithNonMuleCauseWithNonMuleCause() {
    ConnectException causeCauseException = new ConnectException();
    IOException causeException = new IOException(causeCauseException);
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, causeException);
    assertThat(exception.causedExactlyBy(ConnectException.class), is(true));
    assertThat(exception.causedExactlyBy(SocketException.class), is(false));
    assertThat(exception.causedExactlyBy(IOException.class), is(true));
    assertThat(exception.causedExactlyBy(MessagingException.class), is(true));
}
Also used : SocketException(java.net.SocketException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) IOException(java.io.IOException) ConnectException(java.net.ConnectException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

MessagingException (org.mule.runtime.core.internal.exception.MessagingException)69 Test (org.junit.Test)42 SmallTest (org.mule.tck.size.SmallTest)37 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)26 MuleException (org.mule.runtime.api.exception.MuleException)17 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)13 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)11 Optional (java.util.Optional)9 Error (org.mule.runtime.api.message.Error)9 Message (org.mule.runtime.api.message.Message)9 IOException (java.io.IOException)8 Processor (org.mule.runtime.core.api.processor.Processor)8 Publisher (org.reactivestreams.Publisher)8 ConnectException (java.net.ConnectException)7 Component (org.mule.runtime.api.component.Component)7 ConnectionException (org.mule.runtime.api.connection.ConnectionException)7 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)7 SocketException (java.net.SocketException)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)6