vincentlowe

sampleMuleConfig

Apr 20th, 2021
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 9.85 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
  4.     xmlns:http="http://www.mulesoft.org/schema/mule/http"
  5.     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
  6. http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
  7. http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
  8. http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
  9.     <flow name="testObjectModule" doc:id="1cd56ec4-a96a-47d6-a127-bba078006d15" >
  10.         <ee:transform doc:name="Transform Message" doc:id="31f0a6d3-e241-462b-80f1-1a39a52eab45" >
  11.             <ee:message >
  12.                 <ee:set-payload ><![CDATA[%dw 2.0
  13. output application/dw
  14.  
  15. ns localnames http://dwtraining.mulesoft.com
  16.  
  17. var object1 = {
  18.     users: {
  19.         user1 @(name: "Annie", lastname: "Point"): "AP",
  20.         user2 @(name: "Connie", lastname: "Hector"): "CH"
  21.     }
  22. }
  23.  
  24. ---
  25. {
  26.     internals: object1.users,
  27.     justvalues: valuesOf(object1.users),
  28.     justnames: namesOf(object1.users),
  29.     justKeys: keysOf(object1.users),
  30.     //justNS: keysOf(object1.users) map (user) -> (user.#),
  31.     keytypes: keysOf(object1.users) map (u) -> "index$$": typeOf(u)
  32.    
  33. }]]></ee:set-payload>
  34.             </ee:message>
  35.         </ee:transform>
  36.     </flow>
  37.     <flow name="testArraysModule" doc:id="3e4e1d11-de4e-4c24-a7a0-f34dbf5f26e3" >
  38.         <ee:transform doc:name="Transform Message" doc:id="d086179e-b3d0-4584-9233-698fbeabc5d1" >
  39.             <ee:message >
  40.                 <ee:set-payload ><![CDATA[%dw 2.0
  41. output application/dw
  42. import dw::core::Arrays
  43.  
  44. var flights = readUrl("classpath://examples/extra/americanFlightsResponse.json")
  45. ---
  46. {
  47. //  alldata: flights,
  48. //  bigflights: Arrays::some(flights..totalSeats, (ts) -> (ts > 200)),
  49. //  allbig: Arrays::every(flights..totalSeats, (ts) -> (ts < 400)),
  50. //  countem: sizeOf(flights),
  51. //  allseats: flights..totalSeats,
  52. //  smallcraftseats: flights..totalSeats Arrays::sumBy (a) -> (if (a<200) a else 0),
  53.     seatmates: flights..totalSeats Arrays::divideBy 2,
  54.     triplets: 1 to 17 Arrays::divideBy 3
  55. }]]></ee:set-payload>
  56.             </ee:message>
  57.         </ee:transform>
  58.     </flow>
  59.     <flow name="constructAnObject" doc:id="2ee0df40-dc46-4b05-9c0f-1216419ed40e">
  60.         <ee:transform doc:name="Transform Message" doc:id="afe470dd-4bec-46f2-a53b-aa0e4c50ee57">
  61.             <ee:message>
  62.                 <ee:set-payload><![CDATA[%dw 2.0
  63. output application/dw
  64.  
  65. var a1 = [1,"a",true]
  66. var o1 = {one:1,two:2,three:3}
  67.  
  68. ---
  69. {
  70.     object1: {(o1),four:4}
  71. }]]></ee:set-payload>
  72.             </ee:message>
  73.         </ee:transform>
  74.     </flow>
  75.     <flow name="addAndConcat" doc:id="49491bb6-5a07-43a1-b577-5efebc961f5d" >
  76.         <ee:transform doc:name="Transform Message" doc:id="fc25fac2-5e94-42c6-9b23-6802f012415a" >
  77.             <ee:message >
  78.                 <ee:set-payload ><![CDATA[%dw 2.0
  79. output application/dw
  80.  
  81. var a1 = [1,"a",true]
  82. var o1 = {one:1,two:2}
  83.  
  84. ---
  85. {
  86. //  arrayadd: a1 + a1,
  87. //  arrayconcat: a1 ++ a1,
  88. //  arrayplusobject: a1 + o1,
  89. //  objectplusarray: o1 + a1, // error
  90. //  arrayconcatobject: a1 ++ o1, // error
  91.     objectconcatobject: o1 ++ o1,
  92. //  concatminus: o1 ++ o1 - "one", // operator before function
  93. //  concatstripped: (o1 ++ o1) - "one", // force order of precedence
  94.     concatandremove: (o1 ++ o1) -- two:2
  95. }]]></ee:set-payload>
  96.             </ee:message>
  97.         </ee:transform>
  98.     </flow>
  99.     <flow name="passFunctions" doc:id="f4e6f1e8-a529-49a0-8de8-77b9e80b8450" >
  100.         <ee:transform doc:name="Transform Message" doc:id="6cca493b-ce66-40ea-90c5-84abb5017e5f" >
  101.             <ee:message >
  102.                 <ee:set-payload ><![CDATA[%dw 2.0
  103. output application/json
  104.  
  105. fun formatString( anInputString : String, formatter : (String) -> String ) =
  106. formatter( anInputString )
  107.  
  108.  
  109. ---
  110. "helloWorld" formatString
  111. (inStr) -> lower( inStr replace "World" with " There" )
  112.  
  113. ]]></ee:set-payload>
  114.             </ee:message>
  115.         </ee:transform>
  116.     </flow>
  117.     <flow name="chainableTest" doc:id="79891967-98f7-422f-afa2-551ace08d5b2" >
  118.         <ee:transform doc:name="Transform Message" doc:id="c16daf5b-fe55-4bb0-8efe-33de633d9dcb" >
  119.             <ee:message >
  120.                 <ee:set-payload ><![CDATA[%dw 2.0
  121. output application/json
  122.  
  123. fun chain(anInput, expression) =
  124. expression(anInput)
  125.  
  126.  
  127. ---
  128. //[1,5,3,2]
  129. //filter ($ mod 2) == 1
  130. ////orderBy $
  131. //orderBy -$
  132.  
  133. //{one:"One", two:"Two"}
  134. // chain (x) -> (x.one ++ ' ' ++ x.two)
  135.  
  136. //upper( {one:"One", two:"Two"} chain (x) -> (x.one ++ ' ' ++ x.two) )
  137. //
  138. //chain (x) -> (x.one ++ ' ' ++ x.two)
  139. //chain upper
  140.  
  141. chain(
  142.  chain( {one:"One", two:"Two"}, (x) -> (x.one ++ ' ' ++ x.two) ),
  143.  //upper
  144.  lower
  145. )
  146. ]]></ee:set-payload>
  147.             </ee:message>
  148.         </ee:transform>
  149.     </flow>
  150.     <flow name="customMapping" doc:id="88c7422e-d668-42b0-bebe-d9a10a57b7b9" >
  151.         <ee:transform doc:name="Transform Message" doc:id="1b83ec5d-744c-45c2-9039-3abbafb7d3d3" >
  152.             <ee:message >
  153.                 <ee:set-payload ><![CDATA[%dw 2.0
  154. output application/json
  155. import dw::mappings::MyMapping
  156.  
  157. ---
  158. //MyMapping::main( {someElement: ["order", "1001"]} )
  159.  
  160. //MyMapping::main( {someElement: ["order", "1001"], formatter: (k)->k } )
  161.  
  162. MyMapping::main( {someElement: ["order", "1001"], formatter: lower } )
  163.  
  164. //MyMapping::main( { incorrect: ["order", "1001"], formatter: lower } )
  165.  
  166.  
  167. ]]></ee:set-payload>
  168.             </ee:message>
  169.         </ee:transform>
  170.     </flow>
  171.     <flow name="matchOperatorTest" doc:id="bd9e2b8e-5637-40a9-869d-91d6eb33acba">
  172.         <ee:transform doc:name="Transform Message" doc:id="7b9b9a41-7682-42c7-b5c6-a2a291a395ec">
  173.             <ee:message>
  174.                 <ee:set-payload><![CDATA[%dw 2.0
  175. output application/json
  176.  
  177. var americanFlights =
  178. [
  179.  {
  180.    "ID": 5,
  181.    "code": "rree1093",
  182.    "price": 142,
  183.    "departureDate": "2018-02-11T00:00:00",
  184.    "origin": "MUA",
  185.    "destination": "SFO",
  186.    "emptySeats": 1,
  187.    "plane": {
  188.      "type": "Boeing 737",
  189.      "totalSeats": 150
  190.    }
  191.  },
  192.  {
  193.    "ID": 7,
  194.    "code": "eefd1994",
  195.    "price": 676,
  196.    "departureDate": "2018-01-01T00:00:00",
  197.    "origin": "MUA",
  198.    "destination": "SFO",
  199.    "emptySeats": 0,
  200.    "plane": {
  201.      "type": "Boeing 777",
  202.      "totalSeats": 300
  203.    }
  204.  },
  205.  {
  206.    "ID": 8,
  207.    "code": "ffee2000",
  208.    "price": 300,
  209.    "departureDate": "2018-02-20T00:00:00",
  210.    "origin": "MUA",
  211.    "destination": "SFO",
  212.    "emptySeats": 30,
  213.    "plane": {
  214.      "type": "Boeing 737",
  215.      "totalSeats": 150
  216.    }
  217.  },
  218.  {
  219.    "ID": 9,
  220.    "code": "eefd3000",
  221.    "price": 900,
  222.    "departureDate": "2018-02-01T00:00:00",
  223.    "origin": "MUA",
  224.    "destination": "SFO",
  225.    "emptySeats": 0,
  226.    "plane": {
  227.      "type": "Boeing 737",
  228.      "totalSeats": 150
  229.    }
  230.  }
  231.  ]
  232.  
  233. fun overloaded ( anInput : Array) =
  234. "input is an Array of size $(sizeOf(anInput))"
  235.  
  236. fun overloaded ( anInput : Object) =
  237. "input is an Object of size $(sizeOf(anInput))"
  238.  
  239. fun overloaded ( anInput : Null) =
  240. "input is Null"
  241.  
  242. //fun processByType( anInput ) =
  243. //anInput match {
  244. //  else -> anInput
  245. //}
  246.  
  247. fun processByType( anInput ) =
  248. anInput match {
  249.    //case a if( a is Array ) -> "input is an Array of size $(sizeOf(a))"
  250.    case is Array -> "input is an Array of size $(sizeOf(anInput))"
  251.    //case "SFO" -> "San Francisco"
  252.    case is Object -> (inputType: "Object") ++ anInput
  253. //    case is Number -> ($ * dw::modules::FlightsLib::exchangeRate)
  254. //          as String {format: "#,###.00"} as Number
  255.    case is Number -> ($ * dw::modules::FlightsLib::exchangeRate)
  256.             as String {format: "#,###.00"} as Number
  257.  
  258.   // else -> anInput
  259.   //else -> typeOf( anInput )
  260.    else -> "input " ++ anInput ++ " is of type " ++ typeOf( anInput )
  261.    
  262.  
  263. }
  264.  
  265. ---
  266. //americanFlights
  267.  
  268.  
  269. //overloaded( [1,2])
  270.  
  271.  
  272. //overloaded( {one: "One", two: "Two", three: "Three"} )
  273.  
  274. //overloaded( null )
  275.  
  276.  
  277. //processByType( americanFlights )
  278.  
  279. //processByType( americanFlights[0] )
  280.  
  281. //processByType(americanFlights[0].ID)
  282.  
  283. processByType("SFO")
  284.  
  285.  
  286.  
  287.  
  288.  
  289. ]]></ee:set-payload>
  290.             </ee:message>
  291.         </ee:transform>
  292.     </flow>
  293.     <flow name="tryAndFailTest" doc:id="98ca015f-be0f-4d36-b94f-5604c238da21" >
  294.         <http:listener doc:name="Listener" doc:id="3e7bc53c-45d1-46f6-a6c4-cee11a9cf70c" config-ref="HTTP_Listener_config" path="load"/>
  295.         <ee:transform doc:name="Transform Message" doc:id="0b539deb-fb6f-4ce9-9c4e-3b7d12ce52f8" >
  296.             <ee:message >
  297.                 <ee:set-payload ><![CDATA[%dw 2.0
  298. output application/json
  299.  
  300. import * from dw::Runtime
  301.  
  302. //
  303. //fun readInput( anInputFile ) =
  304. //readUrl("classpath://" ++ anInputFile)
  305.  
  306. //fun readInput(anInputFile) =
  307. //try (
  308. //  () -> readUrl("classpath://" ++ anInputFile )
  309. //)
  310. //orElseTry(
  311. //  () -> readUrl("classpath://examples/" ++ anInputFile )
  312. //)
  313. //orElse(
  314. //    fail("Can't find the file: " ++ anInputFile ++
  315. //    " nor /examples/" ++ anInputFile)
  316. //)
  317.  
  318.  
  319. fun readInput(anInputFile) =
  320. try (
  321.    log( "Could not read in the file, will try in the examples sub-folder",
  322.     () -> readUrl("classpath://" ++ anInputFile )
  323.    )
  324. )
  325. orElseTry(
  326.     () -> readUrl("classpath://examples/" ++ anInputFile )
  327. )
  328. orElse(
  329.    fail("Can't find the file: " ++ anInputFile ++
  330.    " nor /examples/" ++ anInputFile)
  331. )
  332.  
  333. ---
  334. //dw::Runtime::try (
  335. //  //readInput("flightsToLAX.json")
  336. //  () -> readInput("flightsToLAX.json")
  337. //)
  338.  
  339.  
  340. //readInput("flightsToLAX.json")
  341.  
  342. //readInput("noGood.json")
  343.  
  344. readInput(attributes.queryParams.filename default "flightsToLAX.json")]]></ee:set-payload>
  345.             </ee:message>
  346.         </ee:transform>
  347.         <error-handler >
  348.             <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="556f9947-0a11-4293-921d-b233fa6bb2c2" >
  349.                 <set-payload value="#[output application/json --- myError: error]" doc:name="Set Payload" doc:id="c5a8b8e0-ece8-444e-a963-dad2f104d271" />
  350.             </on-error-continue>
  351.         </error-handler>
  352.     </flow>
  353. </mule>
  354.  
Advertisement
Add Comment
Please, Sign In to add comment