use of org.mule.runtime.api.component.Component 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.api.component.Component 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;
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class ReactiveInterceptionAction method fail.
@Override
public CompletableFuture<InterceptionEvent> fail(ErrorType errorType) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Called fail() for processor {} with errorType {}", ((Component) processor).getLocation().getLocation(), errorType.getIdentifier());
}
Throwable cause = new InterceptionException("");
interceptionEvent.setError(errorType, cause);
CompletableFuture<InterceptionEvent> completableFuture = new CompletableFuture<>();
completableFuture.completeExceptionally(new MessagingException(interceptionEvent.resolve(), cause, (Component) processor));
return completableFuture;
}
use of org.mule.runtime.api.component.Component 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;
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class AbstractExceptionListener method fireNotification.
protected void fireNotification(Exception ex, CoreEvent event) {
if (enableNotifications) {
if (ex.getCause() != null && getCause(ex) instanceof SecurityException) {
fireNotification(new SecurityNotification((SecurityException) getCause(ex), SECURITY_AUTHENTICATION_FAILED));
} else {
Component component = null;
if (ex instanceof MessagingException) {
component = ((MessagingException) ex).getFailingComponent();
}
fireNotification(new ExceptionNotification(createInfo(event, ex, component), getLocation()));
}
}
}
Aggregations