use of org.mule.runtime.core.api.processor.ReactiveProcessor 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.processor.ReactiveProcessor 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.api.processor.ReactiveProcessor in project mule by mulesoft.
the class ReactiveInterceptorAdapter method apply.
// TODO MULE-13449 Loggers in this method must be INFO
@Override
public ReactiveProcessor apply(Processor component, ReactiveProcessor next) {
if (!isInterceptable(component)) {
return next;
}
final ComponentLocation componentLocation = ((Component) component).getLocation();
if (!interceptorFactory.intercept(componentLocation)) {
return next;
}
final ProcessorInterceptor interceptor = interceptorFactory.get();
Map<String, String> dslParameters = (Map<String, String>) ((Component) component).getAnnotation(ANNOTATION_PARAMETERS);
ReactiveProcessor interceptedProcessor = doApply(component, next, componentLocation, interceptor, dslParameters);
LOGGER.debug("Interceptor '{}' for processor '{}' configured.", interceptor, componentLocation.getLocation());
return interceptedProcessor;
}
Aggregations