use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class AggregatorTestCase method testMessageAggregator.
@Test
public void testMessageAggregator() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
MuleSession session = new DefaultMuleSession();
TestEventAggregator router = new TestEventAggregator(3);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
assertNull(router.process(event1));
assertNull(router.process(event2));
CoreEvent result = router.process(event3);
assertNotNull(result);
PrivilegedEvent privilegedResult = (PrivilegedEvent) result;
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event A"));
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event B"));
assertTrue(privilegedResult.getMessageAsString(muleContext).contains("test event C"));
assertTrue(privilegedResult.getMessageAsString(muleContext).matches("test event [A,B,C] test event [A,B,C] test event [A,B,C] "));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class EventGroupTestCase method mergedSessions.
@Test
public void mergedSessions() throws Exception {
EventGroup eg = new EventGroup(UUID.getUUID(), muleContext);
eg.initEventsStore(objectStore);
assertFalse(eg.iterator().hasNext());
PrivilegedEvent event1 = (PrivilegedEvent) eventBuilder(muleContext).message(Message.of("foo1")).build();
PrivilegedEvent event2 = (PrivilegedEvent) eventBuilder(muleContext).message(Message.of("foo2")).build();
PrivilegedEvent event3 = (PrivilegedEvent) eventBuilder(muleContext).message(Message.of("foo3")).build();
event1.getSession().setProperty("key1", "value1");
event1.getSession().setProperty("key2", "value2");
event2.getSession().setProperty("KEY2", "value2NEW");
event2.getSession().setProperty("key3", "value3");
event3.getSession().setProperty("key4", "value4");
eg.addEvent(event1);
System.out.println(event1.getSession());
eg.addEvent(event2);
System.out.println(event2.getSession());
eg.addEvent(event3);
System.out.println(event3.getSession());
PrivilegedEvent result = (PrivilegedEvent) eg.getMessageCollectionEvent();
assertEquals("value1", result.getSession().getProperty("key1"));
// Cannot assert this because the ordering of events aren't ordered. See MULE-5998
// assertEquals("value2NEW", result.getSession().getProperty("key2"));
assertEquals("value3", result.getSession().getProperty("key3"));
assertEquals("value4", result.getSession().getProperty("key4"));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MVELExpressionLanguage method evaluate.
@Override
public TypedValue evaluate(String expression, CoreEvent event, CoreEvent.Builder eventBuilder, ComponentLocation componentLocation, BindingContext bindingContext) {
expression = removeExpressionMarker(expression);
Map<String, Object> bindingMap = bindingContext.identifiers().stream().collect(toMap(id -> id, id -> bindingContext.lookup(id).get().getValue()));
final Object value = evaluateUntyped(expression, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, componentLocation, bindingMap);
if (value instanceof TypedValue) {
return (TypedValue) value;
} else {
final Serializable compiledExpression = expressionExecutor.getCompiledExpression(expression);
DataType dataType = event != null ? dataTypeResolver.resolve(value, (PrivilegedEvent) event, compiledExpression) : OBJECT;
return new TypedValue(value, dataType);
}
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class OperationPolicyProcessor method executePolicyChain.
private Mono<PrivilegedEvent> executePolicyChain(PrivilegedEvent operationEvent, PolicyStateId policyStateId, PrivilegedEvent policyEvent) {
PolicyChain policyChain = policy.getPolicyChain();
policyChain.onChainError(t -> manageError(policyStateId, operationEvent, (MessagingException) t));
return just(policyEvent).doOnNext(event -> logPolicy(event.getContext().getCorrelationId(), policyStateId.getPolicyId(), getMessageAttributesAsString(event), "Before operation")).cast(CoreEvent.class).transform(policyChain).cast(PrivilegedEvent.class).doOnNext(policyChainResult -> policyStateHandler.updateState(policyStateId, policyChainResult)).map(policyChainResult -> policyEventConverter.createEvent(policyChainResult, operationEvent)).doOnNext(event -> logPolicy(event.getContext().getCorrelationId(), policyStateId.getPolicyId(), getMessageAttributesAsString(event), "After operation"));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class OperationPolicyProcessor method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).cast(PrivilegedEvent.class).flatMap(operationEvent -> {
PolicyStateId policyStateId = new PolicyStateId(operationEvent.getContext().getCorrelationId(), policy.getPolicyId());
Optional<CoreEvent> latestPolicyState = policyStateHandler.getLatestState(policyStateId);
PrivilegedEvent variablesProviderEvent = (PrivilegedEvent) latestPolicyState.orElseGet(() -> PrivilegedEvent.builder(operationEvent.getContext()).message(of(null)).build());
policyStateHandler.updateState(policyStateId, variablesProviderEvent);
PrivilegedEvent policyEvent = policyEventConverter.createEvent(operationEvent, variablesProviderEvent);
Processor operationCall = buildOperationExecutionWithPolicyFunction(nextProcessor, operationEvent, policyStateId);
policyStateHandler.updateNextOperation(policyStateId.getExecutionIdentifier(), operationCall);
return executePolicyChain(operationEvent, policyStateId, policyEvent);
});
}
Aggregations