use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class SourceAdapter method getNonCallbackParameterValue.
private <T> Optional<T> getNonCallbackParameterValue(String fieldName, Class<T> type) {
ValueResolver<T> valueResolver = (ValueResolver<T>) nonCallbackParameters.getResolvers().get(fieldName);
if (valueResolver == null) {
return empty();
}
T object;
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent(muleContext);
object = valueResolver.resolve(from(initialiserEvent));
} catch (MuleException e) {
throw new MuleRuntimeException(createStaticMessage("Unable to get the " + type.getSimpleName() + " value for Message Source"), e);
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
if (!(type.isInstance(object))) {
throw new IllegalStateException("The resolved value is not a " + type.getSimpleName());
}
return of(object);
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class TestLegacyEventUtils method getEffectiveExceptionHandler.
/**
* @return the {@link FlowExceptionHandler} to be applied if an exception is unhandled during the processing of the given
* event.
*/
public static FlowExceptionHandler getEffectiveExceptionHandler(CoreEvent event) {
Field exceptionHandlerField;
try {
exceptionHandlerField = event.getContext().getClass().getSuperclass().getDeclaredField("exceptionHandler");
} catch (Exception e) {
throw new RuntimeException(e);
}
exceptionHandlerField.setAccessible(true);
try {
BaseEventContext eventContext = (BaseEventContext) event.getContext();
FlowExceptionHandler effectiveMessagingExceptionHandler = (FlowExceptionHandler) exceptionHandlerField.get(eventContext);
while (eventContext.getParentContext().isPresent() && effectiveMessagingExceptionHandler == HANDLER) {
eventContext = eventContext.getParentContext().get();
effectiveMessagingExceptionHandler = (FlowExceptionHandler) exceptionHandlerField.get(eventContext);
}
return effectiveMessagingExceptionHandler;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
exceptionHandlerField.setAccessible(false);
}
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorErrorResumeAround.
@Test
@io.qameta.allure.Description("Simulates the error handling scenario for XML SDK operations")
public void interceptorErrorResumeAround() throws Exception {
Exception thrown = new Exception();
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
Mono<InterceptionEvent> errorMono = Mono.error(thrown);
return Mono.from(((BaseEventContext) event.getContext()).error(thrown)).then(errorMono).toFuture();
}
@Override
public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
}
});
startFlowWithInterceptors(interceptor);
expected.expectCause(sameInstance(thrown));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
new PollingProber().probe(() -> {
verify(interceptor).after(any(), any(), eq(Optional.of(thrown)));
return true;
});
}
}
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class AsyncDelegateMessageProcessorTestCase method process.
@Test
public void process() throws Exception {
CoreEvent request = testEvent();
CoreEvent result = process(messageProcessor, request);
// Complete parent context so we can assert event context completion based on async completion.
((BaseEventContext) request.getContext()).success(result);
assertThat(((BaseEventContext) request.getContext()).isTerminated(), is(false));
// Permit async processing now we have already asserted that response alone is not enough to complete event context.
asyncEntryLatch.countDown();
assertThat(latch.await(LOCK_TIMEOUT, MILLISECONDS), is(true));
// Block until async completes, not just target processor.
while (!((BaseEventContext) target.sensedEvent.getContext()).isTerminated()) {
park100ns();
}
assertThat(target.sensedEvent, notNullValue());
// Block to ensure async fully completes before testing state
while (!((BaseEventContext) request.getContext()).isTerminated()) {
park100ns();
}
assertThat(((BaseEventContext) target.sensedEvent.getContext()).isTerminated(), is(true));
assertThat(((BaseEventContext) request.getContext()).isTerminated(), is(true));
assertTargetEvent(request);
assertResponse(result);
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class IdempotentMessageValidatorTestCase method testIdCheckWithDW.
@Test
public void testIdCheckWithDW() throws Exception {
String dwExpression = "%dw 2.0\n" + "output application/text\n" + "---\n" + "payload ++ ' World'";
final BaseEventContext context = mock(BaseEventContext.class);
when(context.getCorrelationId()).thenReturn("1");
Message okMessage = of("Hello");
CoreEvent event = CoreEvent.builder(context).message(okMessage).build();
// Set DW expression to hash value
idempotent.setIdExpression(dwExpression);
// This one will process the event on the target endpoint
CoreEvent processedEvent = idempotent.process(event);
assertNotNull(processedEvent);
assertEquals(idempotent.getObjectStore().retrieve("Hello World"), "1");
// This will not process, because the message is a duplicate
okMessage = of("Hello");
event = CoreEvent.builder(context).message(okMessage).build();
expected.expect(ValidationException.class);
processedEvent = idempotent.process(event);
}
Aggregations