groovy demo
TRANSCRIPT
Groovy Introduction and how to use in Mule
Groovy Connector Demo
Apache Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax.Apache Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk.
Groovy Features
Click on File NEW Mule project Project name Groovy Demo Drag Http connector from Mule palette Add http global end point like following
image Drag the Groovy component and add the
following script. Println('demo payload');
Create project on AnyPoint Studio
Http connector properties
Groovy component properties
<?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:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd 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_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener
Configuration"/> <flow name="groovydemoFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/demo" doc:name="HTTP"/> <scripting:component doc:name="Groovy"> <scripting:script engine="Groovy"><![CDATA[println('demo payload');]]></scripting:script> </scripting:component> </flow> </mule>
XML code here
Click on Run as mule application
After deploying the application successfully
http://localhost:8081/demo
We can see the payload on console as “demo payload”
Out put: