Execute Component in Mule 4 | Scripting in Mule 4


Execute Component in Mule 4


Execute in mule 4 is used to execute scripts. It supports 4 scripting language:

1. groovy
2. Ruby
3. Python
4. Javascript

Flow:


Execute settings:


In above settings I selected engine as groovy and just printing Hello world in output.

Method: GET

Output:

HelloWorld



XML project code:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:http="http://www.mulesoft.org/schema/mule/http"
     xmlns="http://www.mulesoft.org/schema/mule/core"
     xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
     <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="1f81cd2d-ef49-4f90-9c88-0091a3f615e2" >
          <http:listener-connection host="0.0.0.0" port="8085" />
     </http:listener-config>
     <flow name="test_executeFlow" doc:id="65e94b63-4f93-45e3-818b-4d2b385bc487" >
          <http:listener doc:name="Listener" doc:id="e400a1a6-6ebf-40d4-9ae9-e6b3d8b82194" config-ref="HTTP_Listener_config" path="/execute"/>
          <scripting:execute doc:name="Execute" doc:id="755182a6-3b14-4b4b-996c-2f6c3c69ef7a" engine="groovy">
              <scripting:code >&quot;Hello&quot; + &quot;World&quot;</scripting:code>
          </scripting:execute>
     </flow>
</mule>