use of org.mule.runtime.core.internal.message.InternalEvent 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.message.InternalEvent in project mule by mulesoft.
the class DefaultInterceptionEventTestCase method correlationIdGiven.
@Test
public void correlationIdGiven() throws MuleException {
final InternalEvent event = InternalEvent.builder(create("id", "serverId", TEST_CONNECTOR_LOCATION, "corr1", mock(FlowExceptionHandler.class))).message(of(TEST_PAYLOAD)).build();
final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
assertThat(interceptionEvent.getCorrelationId(), is("corr1"));
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultInterceptionEventTestCase method correlationIdAutogenerated.
@Test
public void correlationIdAutogenerated() throws MuleException {
final InternalEvent event = InternalEvent.builder(create("id", "serverId", TEST_CONNECTOR_LOCATION, mock(FlowExceptionHandler.class))).message(of(TEST_PAYLOAD)).build();
final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
assertThat(interceptionEvent.getCorrelationId(), is("id"));
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultInterceptionEventTestCase method addSession.
@Test
public void addSession() throws MuleException {
final InternalEvent event = this.<InternalEvent.Builder>getEventBuilder().message(of(TEST_PAYLOAD)).build();
final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
final MuleSession session = mock(MuleSession.class);
interceptionEvent.session(session);
assertThat(((PrivilegedEvent) interceptionEvent.resolve()).getSession(), sameInstance(session));
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultInterceptionEventTestCase method changeSession.
@Test
public void changeSession() throws MuleException {
final InternalEvent event = this.<InternalEvent.Builder>getEventBuilder().message(of(TEST_PAYLOAD)).session(mock(MuleSession.class)).build();
final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
final MuleSession session = mock(MuleSession.class);
interceptionEvent.session(session);
assertThat(((PrivilegedEvent) interceptionEvent.resolve()).getSession(), sameInstance(session));
}
Aggregations