Search in sources :

Example 1 with DefaultInterceptionEvent

use of org.mule.runtime.core.internal.interception.DefaultInterceptionEvent in project mule by mulesoft.

the class DefaultInterceptionEventTestCase method correlationIdLegacy.

@Test
public void correlationIdLegacy() throws MuleException {
    final InternalEvent event = InternalEvent.builder(create("id", "serverId", TEST_CONNECTOR_LOCATION, mock(FlowExceptionHandler.class))).correlationId("corr1").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) FlowExceptionHandler(org.mule.runtime.core.api.exception.FlowExceptionHandler) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test)

Example 2 with DefaultInterceptionEvent

use of org.mule.runtime.core.internal.interception.DefaultInterceptionEvent in project mule by mulesoft.

the class DefaultInterceptionEventTestCase method updateSession.

@Test
public void updateSession() throws MuleException {
    final InternalEvent event = this.<InternalEvent.Builder>getEventBuilder().message(of(TEST_PAYLOAD)).build();
    final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
    final MuleSession session = ((PrivilegedEvent) event).getSession();
    session.setProperty("myKey", "myValue");
    interceptionEvent.session(session);
    assertThat(((PrivilegedEvent) interceptionEvent.resolve()).getSession().getProperty("myKey"), is("myValue"));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) 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 3 with DefaultInterceptionEvent

use of org.mule.runtime.core.internal.interception.DefaultInterceptionEvent 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 4 with DefaultInterceptionEvent

use of org.mule.runtime.core.internal.interception.DefaultInterceptionEvent 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 5 with DefaultInterceptionEvent

use of org.mule.runtime.core.internal.interception.DefaultInterceptionEvent 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)

Aggregations

DefaultInterceptionEvent (org.mule.runtime.core.internal.interception.DefaultInterceptionEvent)7 InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)7 Test (org.junit.Test)6 MuleSession (org.mule.runtime.core.privileged.event.MuleSession)3 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Component (org.mule.runtime.api.component.Component)1 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 InterceptionAction (org.mule.runtime.api.interception.InterceptionAction)1 InterceptionEvent (org.mule.runtime.api.interception.InterceptionEvent)1 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)1 ProcessorInterceptorFactory (org.mule.runtime.api.interception.ProcessorInterceptorFactory)1 FlowExceptionHandler (org.mule.runtime.core.api.exception.FlowExceptionHandler)1 Processor (org.mule.runtime.core.api.processor.Processor)1 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)1 PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)1