use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class PropertyExpressionDataTypeResolverTestCase method returnsInlineFlowVarDataType.
@Test
public void returnsInlineFlowVarDataType() throws Exception {
final String expression = "foo";
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent testEvent = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(TEST_MESSAGE)).addVariable("foo", EXPRESSION_VALUE, expectedDataType).build();
assertThat(expressionDataTypeResolver.resolve(testEvent, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MessageEnricherTestCase method propagatesVariables.
@Test
public void propagatesVariables() throws Exception {
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("enriched").build()).build());
CoreEvent in = eventBuilder(muleContext).message(of("")).addVariable("flowFoo", "bar").build();
((PrivilegedEvent) in).getSession().setProperty("sessionFoo", "bar");
CoreEvent out = process(enricher, in);
assertEquals("bar", ((PrivilegedEvent) out).getSession().getProperty("sessionFoo"));
assertEquals("bar", out.getVariables().get("flowFoo").getValue());
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MessageEnricherTestCase method doNotImplicitlyEnrichSessionVariable.
@Test
public void doNotImplicitlyEnrichSessionVariable() throws Exception {
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:message.outboundProperties.myHeader]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> {
((PrivilegedEvent) event).getSession().setProperty("sessionFoo", "bar");
return event;
});
CoreEvent out = process(enricher, testEvent());
assertNull(((PrivilegedEvent) out).getSession().getProperty("sessionFoo"));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class MessageEnricherTestCase method enrichSessionVariable.
@Test
public void enrichSessionVariable() throws Exception {
MessageEnricher enricher = baseEnricher();
enricher.addEnrichExpressionPair(new EnrichExpressionPair("#[mel:sessionVars['foo']]"));
enricher.setEnrichmentMessageProcessor((InternalTestProcessor) event -> CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value("bar").build()).build());
CoreEvent out = process(enricher, testEvent());
assertEquals("bar", ((PrivilegedEvent) out).getSession().getProperty("foo"));
}
use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.
the class AbstractSystemExceptionStrategy method handleException.
@Override
public void handleException(Exception ex, RollbackSourceCallback rollbackMethod) {
fireNotification(ex, getCurrentEvent());
resolveAndLogException(ex);
logger.debug("Rolling back transaction");
rollback(ex, rollbackMethod);
ExceptionPayload exceptionPayload = new DefaultExceptionPayload(ex);
if (getCurrentEvent() != null) {
PrivilegedEvent currentEvent = getCurrentEvent();
currentEvent = PrivilegedEvent.builder(currentEvent).message(InternalMessage.builder(currentEvent.getMessage()).exceptionPayload(exceptionPayload).build()).build();
setCurrentEvent(currentEvent);
}
if (ex instanceof ConnectException) {
((ConnectException) ex).handleReconnection(retryScheduler);
}
}
Aggregations