Jack Zach Tibbles
Jack Zach Tibbles

Reputation: 800

Mule ESB: How to use MEL expression in Message Properties Key?

I'm using the message-properties component in mule. I need to set a dynamic key name as this is used to add custom headers to a http-request.

<message-properties-transformer doc:name="Message Properties" scope="session">
    <add-message-property key="#[flowVars.name]" value="#[payload.split(&quot;:&quot;)[1]]"/>
</message-properties-transformer>

When logging the output, it shows that the key has not evaluated the MEL expression contained inside:

SESSION scoped properties: #[flowVars.name]=Basic pokpogytg788t878

Is there any way of setting a dynamic key name for a property in this component?

Upvotes: 0

Views: 832

Answers (1)

Mahesh_Loya
Mahesh_Loya

Reputation: 2832

I have faced similar situation,where I had to set dynamic message properties. I tried several things to set it with message-properties-transformer , but to no luck.

There is some bug filed for similar issue,below is the link

Cannot use MEL expression as key in Message Properties transformer

After trying for sometime I got that working with some workaround.

You can try working it around with Expression component.

        <expression-component doc:name="Expression">
        <![CDATA[message.outboundProperties[flowVars.name]=payload.split(':')1];]]>
        </expression-component>

Not only you can read dynamic values from payload/variables.But you can also call your custom java/groovy methods in it.

Try below code snippet,and let us know if that works for you.

    <flow name="testFlow">
        <http:listener config-ref="HTTP_Listener_Configuration"
            path="/test" doc:name="HTTP" allowedMethods="POST" />
        <set-variable variableName="name" value="#[&quot;test&quot;]"
            doc:name="name" />
        <expression-component doc:name="Expression">
        <![CDATA[message.outboundProperties[flowVars.name]=payload.split(':')1];]]>
        </expression-component>
    </flow>

Upvotes: 1

Related Questions