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;
}
}
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);
}
}
}
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();
}
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));
}
}
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;
}
Aggregations