use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class AbstractExecutableComponent method execute.
@Override
public final CompletableFuture<ExecutionResult> execute(InputEvent inputEvent) {
CompletableFuture completableFuture = new CompletableFuture();
CoreEvent.Builder builder = CoreEvent.builder(createEventContext(of(completableFuture)));
CoreEvent event = builder.message(inputEvent.getMessage()).error(inputEvent.getError().orElse(null)).variables(inputEvent.getVariables()).build();
return from(MessageProcessors.process(event, getExecutableFunction())).onErrorMap(throwable -> {
MessagingException messagingException = (MessagingException) throwable;
CoreEvent messagingExceptionEvent = messagingException.getEvent();
return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
}).<ExecutionResult>map(result -> new ExecutionResultImplementation(result, completableFuture)).toFuture();
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class AbstractMessageProcessorChain method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
List<BiFunction<Processor, ReactiveProcessor, ReactiveProcessor>> interceptors = resolveInterceptors();
Flux<CoreEvent> stream = from(publisher);
for (Processor processor : getProcessorsToExecute()) {
// Perform assembly for processor chain by transforming the existing publisher with a publisher function for each processor
// along with the interceptors that decorate it.
stream = stream.transform(applyInterceptors(interceptors, processor)).subscriberContext(context -> context.put(REACTOR_ON_OPERATOR_ERROR_LOCAL, getLocalOperatorErrorHook(processor))).errorStrategyContinue(getContinueStrategyErrorHandler(processor));
}
return stream.subscriberContext(ctx -> {
ClassLoader tccl = currentThread().getContextClassLoader();
if (tccl == null || tccl.getParent() == null || appClClass == null || !appClClass.isAssignableFrom(tccl.getClass())) {
return ctx;
} else {
return ctx.put(TCCL_ORIGINAL_REACTOR_CTX_KEY, tccl).put(TCCL_REACTOR_CTX_KEY, tccl.getParent());
}
});
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class IdempotentRedeliveryPolicy method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
Optional<Exception> exceptionSeen = empty();
String messageId = null;
try {
messageId = getIdForEvent(event);
} catch (ExpressionRuntimeException e) {
logger.warn("The message cannot be processed because the digest could not be generated. Either make the payload serializable or use an expression.");
return null;
} catch (Exception ex) {
exceptionSeen = of(ex);
}
Lock lock = lockFactory.createLock(idrId + "-" + messageId);
lock.lock();
try {
RedeliveryCounter counter = findCounter(messageId);
if (exceptionSeen.isPresent()) {
throw new MessageRedeliveredException(messageId, counter.counter.get(), maxRedeliveryCount, exceptionSeen.get());
} else if (counter != null && counter.counter.get() > maxRedeliveryCount) {
throw new MessageRedeliveredException(messageId, counter.errors, counter.counter.get(), maxRedeliveryCount);
}
try {
CoreEvent returnEvent = processNext(CoreEvent.builder(DefaultEventContext.child((BaseEventContext) event.getContext(), empty()), event).build());
counter = findCounter(messageId);
if (counter != null) {
resetCounter(messageId);
}
return returnEvent;
} catch (Exception ex) {
if (ex instanceof MessagingException) {
incrementCounter(messageId, (MessagingException) ex);
throw ex;
} else {
MessagingException me = createMessagingException(event, ex, this);
incrementCounter(messageId, me);
throw ex;
}
}
} finally {
lock.unlock();
}
}
use of org.mule.runtime.core.api.event.CoreEvent 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);
}
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class AbstractReplyToPropertyRequestReplyReplier method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
CoreEvent resultEvent;
PrivilegedEvent privilegedEvent = (PrivilegedEvent) event;
if (shouldProcessEvent(privilegedEvent)) {
Object replyTo = privilegedEvent.getReplyToDestination();
ReplyToHandler replyToHandler = privilegedEvent.getReplyToHandler();
resultEvent = processNext(event, empty());
// Allow components to stop processing of the ReplyTo property (e.g. CXF)
if (resultEvent != null) {
// reply-to processing should not resurrect a dead event
event = processReplyTo(event, resultEvent, replyToHandler, replyTo);
}
} else {
resultEvent = processNext(event, empty());
}
return resultEvent;
}
Aggregations