use of org.mule.runtime.api.interception.InterceptionEvent 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.interception.InterceptionEvent 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.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method firstInterceptorFailsAround.
@Test
public void firstInterceptorFailsAround() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
return action.fail(expectedException);
}
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
});
startFlowWithInterceptors(interceptor1, interceptor2);
expected.expectCause(sameInstance(expectedException));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor1, interceptor2);
inOrder.verify(interceptor1).before(any(), any(), any());
inOrder.verify(interceptor2).before(any(), any(), any());
inOrder.verify(interceptor1).around(any(), any(), any(), any());
inOrder.verify(interceptor2, never()).around(any(), any(), any(), any());
inOrder.verify(processor, never()).process(any());
inOrder.verify(interceptor2).after(any(), any(), eq(of(expectedException)));
inOrder.verify(interceptor1).after(any(), any(), eq(of(expectedException)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
use of org.mule.runtime.api.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method firstInterceptorThrowsExceptionAroundAfterProceed.
@Test
public void firstInterceptorThrowsExceptionAroundAfterProceed() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
action.proceed();
throw expectedException;
}
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
});
startFlowWithInterceptors(interceptor1, interceptor2);
expected.expectCause(sameInstance(expectedException));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor1, interceptor2);
inOrder.verify(interceptor1).before(any(), any(), any());
inOrder.verify(interceptor2).before(any(), any(), any());
inOrder.verify(interceptor1).around(any(), any(), any(), any());
inOrder.verify(interceptor2).around(any(), any(), any(), any());
inOrder.verify(processor).process(any());
inOrder.verify(interceptor2, never()).after(any(), any(), eq(empty()));
inOrder.verify(interceptor1).after(any(), any(), eq(of(expectedException)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
use of org.mule.runtime.api.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorThrowsExceptionAroundAfterSkipInCallbackChained.
@Test
public void interceptorThrowsExceptionAroundAfterSkipInCallbackChained() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
return action.skip().thenApplyAsync(e -> {
throw expectedException;
});
}
});
startFlowWithInterceptors(interceptor);
expected.expect(MessagingException.class);
expected.expect(withEventThat(hasErrorType(UNKNOWN.getNamespace(), UNKNOWN.getName())));
expected.expectCause(sameInstance(expectedException));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor);
inOrder.verify(interceptor).before(any(), any(), any());
inOrder.verify(interceptor).around(any(), any(), any(), any());
inOrder.verify(processor, never()).process(any());
inOrder.verify(interceptor).after(any(), any(), eq(of(expectedException)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
Aggregations