Skip to content

Instantly share code, notes, and snippets.

View fganora's full-sized avatar

Francesco Ganora fganora

View GitHub Profile
@fganora
fganora / WorldCities.json
Last active May 19, 2020 15:36
Test JSON document for Mule DataWeave testing (World Cities)
{
"countries": [
{
"name": "Netherlands",
"continent": "Europe",
"cities": [
{
"name": "Amsterdam",
"population": "0.821",
"isCapital": true
@fganora
fganora / WorldCities.xml
Last active May 15, 2020 15:34
Test XML document for Mule DataWeave testing (World Cities)
<?xml version="1.0" encoding="UTF-8"?>
<fg:Countries xmlns:fg="http://examples.fganora.com">
<fg:Country>
<fg:Name>Netherlands</fg:Name>
<fg:Continent>Europe</fg:Continent>
<fg:Cities>
<fg:City capital="YES">
<fg:Name>Amsterdam</fg:Name>
<fg:Population>0.821</fg:Population>
</fg:City>
@fganora
fganora / gist:4194fb8289db4a540e8a8072737ffddc
Created November 16, 2016 08:33
Mule: parsing a JSON document to a Java object with the json-to-object-transformer
<flow name="testJSONtoObject">
<http:listener config-ref="HTTP_Listener_Configuration" path="/jsontoobj" allowedMethods="POST" doc:name="HTTP"/>
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object" />
<set-payload value="#[message.payload.countries[2].capital + ', ' + message.payload.continent]" doc:name="Set Payload"/>
</flow>
@fganora
fganora / gist:33d19d787874dab81378dfd1d2283740
Created November 2, 2016 08:08
Mule: DataWeave example with filter operator
%dw 1.0
%output application/json
---
payload.jobs map {
name : $.name,
url : $.url,
status : $.statusCode
} filter ((job) -> job.statusCode == "0")
@fganora
fganora / gist:d7c4187d4ef8f7506b3bd066f6fbf8d4
Last active April 25, 2017 07:25
Mule: use DataWeave variable for simple translation
%dw 1.0
%output application/json
%var statusCodeToStatusDescription = {
0 : "Success",
1 : "Warning",
2 : "Error"
}
---
payload.jobs map {
name : $.name,
@fganora
fganora / gist:d6df61ebb0fb490b8822ba86d7fe1d54
Created October 22, 2016 19:35
Mule: example register object into Mule registry and access it
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.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
@fganora
fganora / gist:5edf9aea69e18ba38e3a33c53be6ef55
Created October 21, 2016 09:20
Groovy: simple example of parsing and processing an XML document with XmlSlurper
def menu = new XmlSlurper().parseText(payload)
def totalPrice = 0.0
(menu.food).each {
menuItem ->
totalPrice += Double.parseDouble(menuItem.price.text())
}
totalPrice
@fganora
fganora / gist:b7f5cb85c8e981641b6a50359ecc16fe
Created October 21, 2016 08:13
Mule: MEL utiity global function to improve Logger entries
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def logMessage(loggerName, messageToLog) {
return "[" + flow.name + ":" + loggerName + "]: " + messageToLog;
}
</global-functions>
</expression-language>
</configuration>
@fganora
fganora / gist:d17ce5a7969116076842b5345d848a6c
Created October 21, 2016 07:19
Mule: using MEL to send a payload to a VM endpoint
import org.mule.DefaultMuleMessage;
import org.mule.module.client.MuleClient;
request = new DefaultMuleMessage(payload, app.registry['_muleContext']);
MuleClient client = new MuleClient(app.registry['_muleContext']);
client.send("vm://myqueue", request);
@fganora
fganora / gist:59c4b079b8283b2d1009ad931c43c4f3
Last active October 20, 2016 14:21
Mule flow with Groovy transformer (which creates a local class and instantiates / maps an object of that class)
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 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"/>