Nilotpol Nilotpol - 1 year ago 338
Groovy Question

Mule ESB set payload from groovy

I have manipulated data in Groovy script. I want to output of the variable of string type to be the payload. Directly from Groovy can I set the payload? If yes how. An example would help.

Answer Source

To set the payload from Groovy, we can just directly assign it, e.g.: payload = theVariable

For testing purpose we can try the following simple flow:

<flow name="simpleFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <scripting:component doc:name="Groovy">
        <scripting:script engine="Groovy"><![CDATA[int a = 1;
int b = a + 1;
String c = "Result: " + b;

payload = c;]]></scripting:script>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download