Search in sources :

Example 26 with PrivilegedEvent

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) Test(org.junit.Test)

Example 27 with PrivilegedEvent

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());
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Example 28 with PrivilegedEvent

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"));
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Example 29 with PrivilegedEvent

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"));
}
Also used : CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) JSON(org.mule.runtime.api.metadata.MediaType.JSON) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DataTypeMatcher.like(org.mule.tck.junit4.matcher.DataTypeMatcher.like) ExpectedException.none(org.junit.rules.ExpectedException.none) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) UTF_16(java.nio.charset.StandardCharsets.UTF_16) Test(org.junit.Test) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Message.of(org.mule.runtime.api.message.Message.of) Assert.assertNull(org.junit.Assert.assertNull) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Assert.assertEquals(org.junit.Assert.assertEquals) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) EnrichExpressionPair(org.mule.runtime.core.internal.enricher.MessageEnricher.EnrichExpressionPair) Test(org.junit.Test)

Example 30 with PrivilegedEvent

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);
    }
}
Also used : DefaultExceptionPayload(org.mule.runtime.core.internal.message.DefaultExceptionPayload) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DefaultExceptionPayload(org.mule.runtime.core.internal.message.DefaultExceptionPayload) ExceptionPayload(org.mule.runtime.core.api.message.ExceptionPayload) ConnectException(org.mule.runtime.core.api.connector.ConnectException)

Aggregations

PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)56 Test (org.junit.Test)35 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)22 DataType (org.mule.runtime.api.metadata.DataType)17 Message (org.mule.runtime.api.message.Message)15 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)13 ParserContext (org.mule.mvel2.ParserContext)10 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)9 MuleException (org.mule.runtime.api.exception.MuleException)7 UTF_16 (java.nio.charset.StandardCharsets.UTF_16)6 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)6 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)6 TypedValue (org.mule.runtime.api.metadata.TypedValue)6 Processor (org.mule.runtime.core.api.processor.Processor)6 Serializable (java.io.Serializable)5 HashMap (java.util.HashMap)5 Message.of (org.mule.runtime.api.message.Message.of)5 IOException (java.io.IOException)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4