Search in sources :

Example 41 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class VariablesTestCase method sessionVariable.

@Test
public void sessionVariable() throws Exception {
    Message message = of("");
    PrivilegedEvent event = (PrivilegedEvent) InternalEvent.builder(context).message(message).build();
    event.getSession().setProperty("foo", "bar");
    assertEquals(event.getSession().getProperty("foo"), evaluate("sessionVars['foo']", event));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Example 42 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method testResponseEventsCleanedUp.

@Test
public void testResponseEventsCleanedUp() throws Exception {
    RelaxedAsyncReplyMP mp = new RelaxedAsyncReplyMP(muleContext);
    try {
        CoreEvent event = eventBuilder(muleContext).message(of("message1")).groupCorrelation(Optional.of(GroupCorrelation.of(0, 3))).build();
        SensingNullMessageProcessor listener = getSensingNullMessageProcessor();
        mp.setListener(listener);
        mp.setReplySource(listener.getMessageSource());
        mp.process(event);
        Map<String, PrivilegedEvent> responseEvents = mp.getResponseEvents();
        assertThat(responseEvents.entrySet(), empty());
    } finally {
        mp.stop();
    }
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 43 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class MessageEnricher method enrich.

protected PrivilegedEvent enrich(PrivilegedEvent currentEvent, PrivilegedEvent enrichmentEvent, String sourceExpressionArg, String targetExpressionArg, ExtendedExpressionManager expressionManager) {
    if (StringUtils.isEmpty(sourceExpressionArg)) {
        sourceExpressionArg = "#[mel:payload:]";
    }
    TypedValue typedValue = expressionManager.evaluate(sourceExpressionArg, enrichmentEvent, getLocation());
    if (typedValue.getValue() instanceof Message) {
        Message muleMessage = (Message) typedValue.getValue();
        typedValue = new TypedValue(muleMessage.getPayload().getValue(), muleMessage.getPayload().getDataType());
    }
    if (!StringUtils.isEmpty(targetExpressionArg)) {
        PrivilegedEvent.Builder eventBuilder = PrivilegedEvent.builder(currentEvent);
        expressionManager.enrich(targetExpressionArg, currentEvent, eventBuilder, getLocation(), typedValue);
        return eventBuilder.build();
    } else {
        return PrivilegedEvent.builder(currentEvent).message(Message.builder(currentEvent.getMessage()).value(typedValue.getValue()).mediaType(typedValue.getDataType().getMediaType()).build()).build();
    }
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) TypedValue(org.mule.runtime.api.metadata.TypedValue)

Example 44 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class MVELExpressionLanguage method enrich.

@Override
public void enrich(String expression, CoreEvent event, CoreEvent.Builder eventBuilder, ComponentLocation componentLocation, TypedValue typedValue) {
    expression = removeExpressionMarker(expression);
    expression = createEnrichmentExpression(expression);
    evaluateUntyped(expression, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, componentLocation, singletonMap(OBJECT_FOR_ENRICHMENT, typedValue.getValue()));
    final Serializable compiledExpression = expressionExecutor.getCompiledExpression(expression);
    event = eventBuilder.build();
    dataTypePropagator.propagate(typedValue, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, compiledExpression);
}
Also used : Serializable(java.io.Serializable) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent)

Example 45 with PrivilegedEvent

use of org.mule.runtime.core.privileged.event.PrivilegedEvent in project mule by mulesoft.

the class OperationPolicyProcessor method manageError.

private void manageError(PolicyStateId policyStateId, PrivilegedEvent operationEvent, MessagingException messagingException) {
    policyStateHandler.updateState(policyStateId, messagingException.getEvent());
    PrivilegedEvent newEvent = policyEventConverter.createEvent((PrivilegedEvent) messagingException.getEvent(), operationEvent);
    messagingException.setProcessedEvent(newEvent);
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent)

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