use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class PolicyNextActionMessageProcessor method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).doOnNext(coreEvent -> logExecuteNextEvent("Before execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId())).flatMap(event -> {
Processor nextOperation = policyStateHandler.retrieveNextOperation(event.getContext().getCorrelationId());
if (nextOperation == null) {
return error(new MuleRuntimeException(createStaticMessage("There's no next operation configured for event context id " + event.getContext().getCorrelationId())));
}
popBeforeNextFlowFlowStackElement().accept(event);
notificationHelper.notification(BEFORE_NEXT).accept(event);
return from(processWithChildContext(event, nextOperation, ofNullable(getLocation()))).doOnSuccessOrError(notificationHelper.successOrErrorNotification(AFTER_NEXT).andThen((ev, t) -> pushAfterNextFlowStackElement().accept(event))).onErrorResume(MessagingException.class, t -> {
PolicyStateId policyStateId = new PolicyStateId(event.getContext().getCorrelationId(), muleContext.getConfiguration().getId());
policyStateHandler.getLatestState(policyStateId).ifPresent(latestStateEvent -> t.setProcessedEvent(policyEventConverter.createEvent((PrivilegedEvent) t.getEvent(), (PrivilegedEvent) latestStateEvent)));
// Given we've used child context to ensure AFTER_NEXT notifications are fired at exactly the right time we need
// to propagate the error to parent context manually.
((BaseEventContext) event.getContext()).error(resolveMessagingException(t.getFailingComponent(), muleContext).apply(t));
return empty();
}).doOnNext(coreEvent -> logExecuteNextEvent("After execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId()));
});
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class AbstractReplyToPropertyRequestReplyReplier method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
CoreEvent resultEvent;
PrivilegedEvent privilegedEvent = (PrivilegedEvent) event;
if (shouldProcessEvent(privilegedEvent)) {
Object replyTo = privilegedEvent.getReplyToDestination();
ReplyToHandler replyToHandler = privilegedEvent.getReplyToHandler();
resultEvent = processNext(event, empty());
// Allow components to stop processing of the ReplyTo property (e.g. CXF)
if (resultEvent != null) {
// reply-to processing should not resurrect a dead event
event = processReplyTo(event, resultEvent, replyToHandler, replyTo);
}
} else {
resultEvent = processNext(event, empty());
}
return resultEvent;
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MuleEventTestCase method serialization.
@Test
public void serialization() throws Exception {
Transformer transformer = createSerializableToByteArrayTransformer();
transformer.setMuleContext(muleContext);
Serializable serialized = (Serializable) createSerializableToByteArrayTransformer().transform(testEvent());
assertNotNull(serialized);
ByteArrayToObject trans = new ByteArrayToObject();
trans.setMuleContext(muleContext);
PrivilegedEvent deserialized = (PrivilegedEvent) trans.transform(serialized);
// Assert that deserialized event is not null
assertNotNull(deserialized);
// Assert that deserialized event has session with same id
assertNotNull(deserialized.getSession());
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent 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"));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedSessionProperty.
@Test
public void propagatesDataTypeForInlinedSessionProperty() throws Exception {
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression("foo = 'unused'", new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent event = (PrivilegedEvent) testEvent();
event.getSession().setProperty("foo", "bar");
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue(TEST_MESSAGE, expectedDataType), compiledExpression);
assertThat(builder.build().getSession().getPropertyDataType("foo"), like(String.class, JSON, CUSTOM_ENCODING));
}
Aggregations