Here is a simple example:

You send the encoded JSON array, and the script returns you the amount. Plain!
There is a stream:
<flow name="calculateFlow1" doc:name="calculateFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8089" doc:name="HTTP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<scripting:component doc:name="JavaScript">
<scripting:script engine="JavaScript">
<scripting:text><![CDATA[
var a = eval('(' + payload + ')');
for (var i = 0, sum = 0; i < a.length; sum += a[i++]);
message.setPayload(sum + "");
result = message;
]]></scripting:text>
</scripting:script>
</scripting:component>
</flow>
Variables already defined by Mule: message, payload.
source
share