0
votes

In trying to restore the original payload in a message, I ran into this issue that confused me regarding the scope of a mule message. Given the mule config below, I initially assumed that the payload received at the test.Name vm endpoint was going to be restored at the end of the flow (see 1. and 2. in the config):

<mule  ...>     
    <vm:endpoint name="replacePayloadWithFoo.Name"
            path="replacePayloadWithFoo.Path" />

    <flow name="test">
        <vm:inbound-endpoint name="test.Name" path="test.Path"
            exchange-pattern="request-response" />

        <!-- 1. Down below, I wanted to restore the payload at this point -->

        <expression-transformer evaluator="string"
            expression="bar" />

        <outbound-endpoint ref="replacePayloadWithFoo.Name"
            exchange-pattern="request-response" />

        <!-- 2. The transformer below does not restore the payload at 1. -->            

        <expression-transformer evaluator="groovy"
                expression="message.originalPayload" />
    </flow>

    <flow name="replacePayloadWithFoo">
        <inbound-endpoint ref="replacePayloadWithFoo.Name"
            exchange-pattern="request-response" />

        <expression-transformer evaluator="string"
            expression="foo" />

    </flow>

</mule>

However, it seemed as though the message that entered the test flow ended at the replacePayloadWithFoo outbound endpoint. The transformer at 2. leaves "foo" as the payload.

What's the scope of the mule message?

In passing, the scripting reference documentation indicates that there is a binding for originalPayload in groovy scripts. However, if the transformer at 2. is replaced with

<expression-transformer evaluator="groovy" expression="originalPayload" />

I get an exception:

org.mule.api.expression.RequiredValueException: Expression Evaluator "groovy"
with expression "originalPayload" returned null but a value was required.

What could be the issue?

Thanks

1

1 Answers

1
votes

Any outbound interaction, unless performed through an enricher, will affect the current in-flight message. This is why the call to replacePayloadWithFoo replaces the original message with the result of the outbound interaction.

This said, I can not explain the discrepancy between:

<expression-transformer evaluator="groovy" expression="message.originalPayload" />

and:

<expression-transformer evaluator="groovy" expression="originalPayload" />

because they both rely on:

event.getMessage().getPayload()