Search code examples
groovymuleresponseanypoint-studiohttplistener

how to get response data of http listener in groovy file


Response is in JSON:

{
   "msisdn": "123",
   "starttime": "2.11",
   "endtime": "7.10",
   "type": "simple"                        
}

I want to access this data in groovy file for further processing, which function or method is used to access this data.

I'm using mule anypoint studio.


Solution

  • It's simply called "payload" in your groovy script. This simply returns the json that you receive from the HTTP Listener.

    <flow name="test">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[return payload]]></scripting:script>
        </scripting:component>
    </flow>
    

    Here are some other examples: https://docs.mulesoft.com/mule-runtime/3.8/scripting-module-reference