How to create JavaScript Hello World in a Mule component

I am trying to create a simple script inside a Mule component, but I cannot find any documentation on how to start me.

The link to the JavaScript component does not contain ideas on how to get something simple to work with.

+4
source share
2 answers

Here is a simple example:

JavaScript in a Mule Component

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.

+8
source

Anypoint Studio now has a Script component:

https://docs.mulesoft.com/mule-user-guide/v/3.6/script-component-reference

... , javascript.

  • HTTP- GET
  • Script document.write " " /.
  • , .
0

Source: https://habr.com/ru/post/1543108/


All Articles