Search in sources :

Example 16 with InternalEvent

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));
    }
}
Also used : ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) Logger(org.slf4j.Logger) Exceptions.propagate(reactor.core.Exceptions.propagate) Flux.from(reactor.core.publisher.Flux.from) LoggerFactory(org.slf4j.LoggerFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) Processor(org.mule.runtime.core.api.processor.Processor) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) Mono.fromFuture(reactor.core.publisher.Mono.fromFuture) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) CompletionException(java.util.concurrent.CompletionException) Component(org.mule.runtime.api.component.Component) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) CompletionException(java.util.concurrent.CompletionException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent)

Example 17 with InternalEvent

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"));
}
Also used : DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test)

Example 18 with InternalEvent

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"));
}
Also used : DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test)

Example 19 with InternalEvent

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));
}
Also used : DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test)

Example 20 with InternalEvent

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));
}
Also used : DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test)

Aggregations

InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)32 Test (org.junit.Test)30 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)24 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)23 InOrder (org.mockito.InOrder)22 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)22 SmallTest (org.mule.tck.size.SmallTest)22 DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)21 InterceptionEvent (org.mule.runtime.api.interception.InterceptionEvent)20 ProcessorParameterValue (org.mule.runtime.api.interception.ProcessorParameterValue)16 CompletableFuture (java.util.concurrent.CompletableFuture)14 InterceptionAction (org.mule.runtime.api.interception.InterceptionAction)14 DefaultInterceptionEvent (org.mule.runtime.core.internal.interception.DefaultInterceptionEvent)7 ProcessorInterceptorFactory (org.mule.runtime.api.interception.ProcessorInterceptorFactory)5 Component (org.mule.runtime.api.component.Component)4 Message (org.mule.runtime.api.message.Message)4 MuleSession (org.mule.runtime.core.privileged.event.MuleSession)4 Collections.singletonList (java.util.Collections.singletonList)3 Map (java.util.Map)3 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)3