Search in sources :

Example 51 with MessagingException

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

the class SuspendXaTransactionInterceptor method execute.

@Override
public T execute(ExecutionCallback<T> callback, ExecutionContext executionContext) throws Exception {
    Transaction suspendedXATx = null;
    Transaction tx = TransactionCoordination.getInstance().getTransaction();
    byte action = transactionConfig.getAction();
    if ((action == TransactionConfig.ACTION_NONE || action == TransactionConfig.ACTION_ALWAYS_BEGIN) && tx != null && tx.isXA()) {
        if (logger.isDebugEnabled()) {
            logger.debug("suspending XA tx " + action + ", " + "current TX: " + tx);
        }
        suspendedXATx = tx;
        suspendXATransaction(suspendedXATx);
    }
    try {
        T result = next.execute(callback, executionContext);
        resumeXaTransactionIfRequired(suspendedXATx);
        return result;
    } catch (MessagingException e) {
        if (processOnException) {
            TransactionCoordination.getInstance().resumeXaTransactionIfAvailable();
        }
        throw e;
    }
}
Also used : Transaction(org.mule.runtime.core.api.transaction.Transaction) MessagingException(org.mule.runtime.core.internal.exception.MessagingException)

Example 52 with MessagingException

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

the class EventCorrelator method handleGroupExpiry.

protected void handleGroupExpiry(EventGroup group) throws MuleException {
    try {
        removeEventGroup(group);
    } catch (ObjectStoreException e) {
        throw new DefaultMuleException(e);
    }
    if (isFailOnTimeout()) {
        CoreEvent messageCollectionEvent = group.getMessageCollectionEvent();
        notificationFirer.dispatch(new RoutingNotification(messageCollectionEvent.getMessage(), null, CORRELATION_TIMEOUT));
        try {
            group.clear();
        } catch (ObjectStoreException e) {
            logger.warn("Failed to clear group with id " + group.getGroupId() + " since underlying ObjectStore threw Exception:" + e.getMessage());
        }
        throw new CorrelationTimeoutException(correlationTimedOut(group.getGroupId()));
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug(MessageFormat.format("Aggregator expired, but ''failOnTimeOut'' is false. Forwarding {0} events out of {1} " + "total for group ID: {2}", group.size(), group.expectedSize().map(v -> v.toString()).orElse(NOT_SET), group.getGroupId()));
        }
        try {
            if (!(group.getCreated() + DAYS.toMillis(1) < currentTimeMillis())) {
                CoreEvent newEvent = CoreEvent.builder(callback.aggregateEvents(group)).build();
                group.clear();
                if (!correlatorStore.contains((String) group.getGroupId(), getExpiredAndDispatchedPartitionKey())) {
                    // returned?
                    if (timeoutMessageProcessor != null) {
                        processToApply(newEvent, timeoutMessageProcessor, false, empty());
                    } else {
                        throw new MessagingException(createStaticMessage(MessageFormat.format("Group {0} timed out, but no timeout message processor was " + "configured.", group.getGroupId())), newEvent);
                    }
                    correlatorStore.store((String) group.getGroupId(), group.getCreated(), getExpiredAndDispatchedPartitionKey());
                } else {
                    logger.warn(MessageFormat.format("Discarding group {0}", group.getGroupId()));
                }
            }
        } catch (MessagingException me) {
            throw me;
        } catch (Exception e) {
            throw new MessagingException(group.getMessageCollectionEvent(), e);
        }
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) NOT_SET(org.mule.runtime.core.api.message.GroupCorrelation.NOT_SET) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) System.currentTimeMillis(java.lang.System.currentTimeMillis) DeserializationPostInitialisable(org.mule.runtime.core.privileged.store.DeserializationPostInitialisable) LoggerFactory(org.slf4j.LoggerFactory) MINUTES(java.util.concurrent.TimeUnit.MINUTES) PartitionableObjectStore(org.mule.runtime.api.store.PartitionableObjectStore) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Processor(org.mule.runtime.core.api.processor.Processor) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) Scheduler(org.mule.runtime.api.scheduler.Scheduler) DAYS(java.util.concurrent.TimeUnit.DAYS) CORRELATION_TIMEOUT(org.mule.runtime.api.notification.RoutingNotification.CORRELATION_TIMEOUT) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Mono.empty(reactor.core.publisher.Mono.empty) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) MISSED_AGGREGATION_GROUP_EVENT(org.mule.runtime.api.notification.RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) ObjectStore(org.mule.runtime.api.store.ObjectStore) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StringMessageUtils.truncate(org.mule.runtime.core.api.util.StringMessageUtils.truncate) StringMessageUtils(org.mule.runtime.core.api.util.StringMessageUtils) String.format(java.lang.String.format) EventGroup(org.mule.runtime.core.internal.routing.EventGroup) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) List(java.util.List) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) CoreMessages.objectIsNull(org.mule.runtime.core.api.config.i18n.CoreMessages.objectIsNull) CoreMessages.correlationTimedOut(org.mule.runtime.core.api.config.i18n.CoreMessages.correlationTimedOut) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 53 with MessagingException

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

the class Foreach method splitAndProcess.

private Publisher<CoreEvent> splitAndProcess(CoreEvent request) {
    AtomicInteger count = new AtomicInteger();
    final AtomicReference<CoreEvent> currentEvent = new AtomicReference<>(request);
    // Split into sequence of TypedValue
    return fromIterable(() -> splitRequest(request)).onErrorMap(throwable -> new MessagingException(request, throwable, Foreach.this)).transform(p -> batchSize > 1 ? from(p).buffer(batchSize).map(list -> new TypedValue<>(list, fromObject(list))) : p).flatMapSequential(typedValue -> {
        EventContext parentContext = currentEvent.get().getContext();
        BaseEventContext childContext = newChildContext(currentEvent.get(), ofNullable(getLocation()));
        Builder partEventBuilder = builder(childContext, currentEvent.get());
        if (typedValue.getValue() instanceof EventBuilderConfigurer) {
            // Support EventBuilderConfigurer currently used by Batch Module
            EventBuilderConfigurer configurer = (EventBuilderConfigurer) typedValue.getValue();
            configurer.configure(partEventBuilder);
            childContext.onResponse((e, t) -> {
                configurer.eventCompleted();
            });
        } else if (typedValue.getValue() instanceof Message) {
            // If value is a Message then use it directly conserving attributes and properties.
            partEventBuilder.message((Message) typedValue.getValue());
        } else {
            // Otherwise create a new message
            partEventBuilder.message(Message.builder().payload(typedValue).build());
        }
        return Mono.from(just(partEventBuilder.addVariable(counterVariableName, count.incrementAndGet()).build()).transform(nestedChain).doOnNext(completeSuccessIfNeeded(childContext, true)).switchIfEmpty(Mono.from(childContext.getResponsePublisher())).map(result -> builder(parentContext, result).build()).doOnNext(result -> currentEvent.set(CoreEvent.builder(result).build())).doOnError(MessagingException.class, me -> me.setProcessedEvent(builder(parentContext, me.getEvent()).build())).doOnSuccess(result -> {
            if (result == null) {
                childContext.success();
            }
        }));
    }, // Force sequential execution of the chain for each element
    1).switchIfEmpty(defer(() -> {
        if (count.get() == 0) {
            logger.warn("Split expression returned no results. If this is not expected please check your expression");
            return just(request);
        } else {
            return empty();
        }
    })).takeLast(1).map(s -> CoreEvent.builder(currentEvent.get()).message(request.getMessage()).build()).errorStrategyStop();
}
Also used : MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) Message(org.mule.runtime.api.message.Message) Flux.from(reactor.core.publisher.Flux.from) Mono.defer(reactor.core.publisher.Mono.defer) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) DataType.fromObject(org.mule.runtime.api.metadata.DataType.fromObject) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CoreEvent.builder(org.mule.runtime.core.api.event.CoreEvent.builder) Iterators(com.google.common.collect.Iterators) Collections.singletonList(java.util.Collections.singletonList) Scope(org.mule.runtime.core.privileged.processor.Scope) MuleException(org.mule.runtime.api.exception.MuleException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageProcessors.newChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.newChildContext) Builder(org.mule.runtime.core.api.event.CoreEvent.Builder) Map(java.util.Map) Mono.just(reactor.core.publisher.Mono.just) AbstractMessageProcessorOwner(org.mule.runtime.core.api.processor.AbstractMessageProcessorOwner) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) EventBuilderConfigurer(org.mule.runtime.core.internal.routing.outbound.EventBuilderConfigurer) Mono.empty(reactor.core.publisher.Mono.empty) DEFAULT_SPLIT_EXPRESSION(org.mule.runtime.core.internal.routing.ExpressionSplittingStrategy.DEFAULT_SPLIT_EXPRESSION) EventContext(org.mule.runtime.api.event.EventContext) Iterator(java.util.Iterator) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) Flux.fromIterable(reactor.core.publisher.Flux.fromIterable) Optional.ofNullable(java.util.Optional.ofNullable) MessageProcessors.completeSuccessIfNeeded(org.mule.runtime.core.privileged.processor.MessageProcessors.completeSuccessIfNeeded) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Mono(reactor.core.publisher.Mono) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) EventBuilderConfigurerList(org.mule.runtime.core.internal.routing.outbound.EventBuilderConfigurerList) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) TypedValue(org.mule.runtime.api.metadata.TypedValue) List(java.util.List) Optional(java.util.Optional) EventBuilderConfigurerIterator(org.mule.runtime.core.internal.routing.outbound.EventBuilderConfigurerIterator) MessageProcessors.getProcessingStrategy(org.mule.runtime.core.privileged.processor.MessageProcessors.getProcessingStrategy) EventContext(org.mule.runtime.api.event.EventContext) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) EventBuilderConfigurer(org.mule.runtime.core.internal.routing.outbound.EventBuilderConfigurer) Message(org.mule.runtime.api.message.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) AtomicReference(java.util.concurrent.atomic.AtomicReference) TypedValue(org.mule.runtime.api.metadata.TypedValue)

Example 54 with MessagingException

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

the class ReactiveAroundInterceptorAdapter method doAround.

private CompletableFuture<InternalEvent> doAround(InternalEvent event, ProcessorInterceptor interceptor, Processor component, Map<String, String> dslParameters, ReactiveProcessor next) {
    final InternalEvent eventWithResolvedParams = addResolvedParameters(event, component, dslParameters);
    DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(eventWithResolvedParams);
    final ReactiveInterceptionAction reactiveInterceptionAction = new ReactiveInterceptionAction(interceptionEvent, next, component, ((PrivilegedMuleContext) getMuleContext()).getErrorTypeLocator());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Calling around() for '{}' in processor '{}'...", interceptor, ((Component) component).getLocation().getLocation());
    }
    try {
        return withContextClassLoader(interceptor.getClass().getClassLoader(), () -> interceptor.around(((Component) component).getLocation(), getResolvedParams(eventWithResolvedParams), interceptionEvent, reactiveInterceptionAction)).exceptionally(t -> {
            if (t instanceof MessagingException) {
                throw new CompletionException(t);
            } else {
                throw new CompletionException(createMessagingException(eventWithResolvedParams, t instanceof CompletionException ? t.getCause() : t, ((Component) component)));
            }
        }).thenApply(interceptedEvent -> interceptedEvent != null ? ((DefaultInterceptionEvent) interceptedEvent).resolve() : null);
    } catch (Exception e) {
        throw propagate(createMessagingException(interceptionEvent.resolve(), e, (Component) component));
    }
}
Also used : ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) Logger(org.slf4j.Logger) Exceptions.propagate(reactor.core.Exceptions.propagate) Flux.from(reactor.core.publisher.Flux.from) LoggerFactory(org.slf4j.LoggerFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) Processor(org.mule.runtime.core.api.processor.Processor) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) Mono.fromFuture(reactor.core.publisher.Mono.fromFuture) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) CompletionException(java.util.concurrent.CompletionException) Component(org.mule.runtime.api.component.Component) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) CompletionException(java.util.concurrent.CompletionException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent)

Example 55 with MessagingException

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

the class ReactiveInterceptionAction method fail.

@Override
public CompletableFuture<InterceptionEvent> fail(Throwable cause) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Called fail() for processor {} with cause {} ({})", ((Component) processor).getLocation().getLocation(), cause.getClass(), cause.getMessage());
    }
    Error newError = getErrorFromFailingProcessor(null, (Component) processor, cause, errorTypeLocator);
    interceptionEvent.setError(newError.getErrorType(), cause);
    CompletableFuture<InterceptionEvent> completableFuture = new CompletableFuture<>();
    completableFuture.completeExceptionally(new MessagingException(interceptionEvent.resolve(), cause, (Component) processor));
    return completableFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) Error(org.mule.runtime.api.message.Error) Component(org.mule.runtime.api.component.Component)

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