Skip to content

Instantly share code, notes, and snippets.

View adrianhsieh's full-sized avatar

Adrian Hsieh adrianhsieh

  • Adaptive Connections
View GitHub Profile
<flow name="jms-demo-senderFlow1" doc:name="jms-demo-senderFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="start-demo" doc:name="HTTP"/>
<set-session-variable variableName="demo-session" value="#['this is session']" doc:name="Session Variable"/>
<set-property propertyName="demo-outbound" value="#['this is outbound']" doc:name="Property"/>
<set-variable variableName="demo-flowvar" value="#['this is flow variable']" doc:name="Variable"/>
<set-payload value="#['demo-message']" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint queue="blog-demo" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:context="http://www.springframework.org/schema/context" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:json="http://www.mulesoft.org/schema/mule/json" 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" version="EE-3.5.1"
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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mul
@adrianhsieh
adrianhsieh / munit-example.xml
Last active August 29, 2015 13:56
Munit example
<!--Beginning of First Test, Generally the Happy Path where payload values are expected / valid-->
<munit:test name="ValidateHappyPath" description="Test when input is as expected">
<!--Mock inbound endpoint since it is a unit test-->
<mock:when messageProcessor="http:inbound-endpoint"/>
<!--Now set the payload to have the valid value-->
<munit:set payload-ref="#['']">
<munit:inbound-properties>
<munit:inbound-property key="flag" value-ref="#['true']"/>
</munit:inbound-properties>
</munit:set>
@adrianhsieh
adrianhsieh / express_example.xml
Last active August 29, 2015 13:56
Expression Example
<choice doc:name="Choice">
<!-- <when expression="#[payload['goodguy']=true]"> -->
<when expression="#[payload['goodguy']==true]">
<set-payload value="#['All Good']" doc:name="set-valid-payload-response"/>
<http:response-builder status="200" contentType="text/plain" doc:name="HTTP Response 200"/>
</when>
<otherwise>
<set-payload value="#['Invalid Payload']" doc:name="invalid-payload-goes-here"/>
<http:response-builder status="400" contentType="text/plain" doc:name="HTTP Response 400"/>
</otherwise>
@adrianhsieh
adrianhsieh / error-handling-subflow.xml
Created January 17, 2014 08:09
Sub-flow example for handling excpetion
<catch-exception-strategy doc:name="Catch Exception Strategy">
<flow-ref name="set-errorresponse-subflow" doc:name="set-errorresponse-subflow"/>
</catch-exception-strategy>
<sub-flow name="set-errorresponse-subflow" doc:name="set-errorresponse-subflow">
<set-variable variableName="jsonpmsg" value="#[exception.cause.message]" doc:name="jsonpmsgError"/>
<scripting:transformer doc:name="json-map">
<scripting:script engine="Groovy"><![CDATA[def jsonpmsg = message.getInvocationProperty('jsonpmsg');
def estatus = 500;
@adrianhsieh
adrianhsieh / recursive-flow.xml
Created January 17, 2014 00:36
Recursive call to find the right number to increment against QuickBooks Online
<flow name="qb-findname-flow" doc:name="qb-findname-flow" processingStrategy="synchronous">
<vm:inbound-endpoint exchange-pattern="request-response" path="qb.findname" doc:name="qb.findname"/>
<enricher source="#[payload.size()]" target="#[variable:matched]" doc:name="Message Enricher">
<quickbooks:find-objects config-ref="quickbooks" queryFilter="name :EQUALS: #[payload.workingname]" accessTokenId="#[map-payload:realmid]" type="#[map-payload:synctype]" doc:name="Quickbooks Online"/>
</enricher>
<choice doc:name="Choice">
<when expression="#[matched > 0]">
<processor-chain>
<scripting:transformer doc:name="append-to-name">
<scripting:script engine="Groovy">
@adrianhsieh
adrianhsieh / handshake-to-quickbooks.js
Last active January 3, 2016 12:49
Sample mapping showing how to map from Handshake to QuickBooks
//#CTL2
// Transforms input record into output record.
function integer transform() {
if ($in.0.unitPrice != 0.0 && $in.0.qty != 0.0) {
$out.0.itemType = lookup(QBRefLookup).get($in.0.sku,dictionary.realmid,'ITEM').type;
$out.0.discountRatePercent = isnull($in.0.percentageDiscount) ? null : str2decimal($in.0.percentageDiscount);
$out.0.itemName = $in.0.sku;
$out.0.discountAmount = isnull($in.0.discount) ? null : str2decimal($in.0.discount);
$out.0.desc = $in.0.description + (isnull($in.0.notes) ? null : ' ' + $in.0.notes);
@adrianhsieh
adrianhsieh / paycheck.xml
Created November 20, 2012 00:28
show me the paycheck
<choice doc:name="Choice">
<when expression="payload.get('paycheckstyle') == 'Walmart Fozzy'">
<processor-chain>
<http:response-builder status="302" doc:name="HTTP Response Builder">
<http:location value="http://happyhour.atotis.com"/>
</http:response-builder>
</processor-chain>
</when>
<otherwise>
<processor-chain>
@adrianhsieh
adrianhsieh / sample_input.csv
Created September 22, 2012 21:31
sample csv input file
name externalid value lastmodified
order1 1 10 2012-09-22 13:40:00.00
order1 1 1 2012-09-22 10:00:00.00
order1 1 5 2012-09-22 11:00:00.00
@adrianhsieh
adrianhsieh / demo_flow.xml
Created September 22, 2012 21:26
Demo how to select records sorted
<flow name="mainFlow" doc:name="mainFlow" processingStrategy="synchronous">
<file:inbound-endpoint path="src/test/resources" moveToDirectory="src/test/archives" responseTimeout="10000" doc:name="Input File"/>
<jdbc-ee:csv-to-maps-transformer ignoreFirstRecord="true" doc:name="CSV to Maps" mappingFile="src/main/resources/mules-csv-format.xml"/>
<foreach doc:name="Foreach">
<logger message="#[payload]" level="INFO" doc:name="csv record" />
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryKey="insertRecord" queryTimeout="-1" connector-ref="apache-derby" doc:name="insert-record"/>
</foreach>
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryKey="selectRecord" queryTimeout="-1" connector-ref="apache-derby" doc:name="select records"/>
<sfdc:upsert config-ref="salesforce" externalIdFieldName="External_ID__c" type="Demo_Object__c" doc:name="upsert.record.in.salesforce">
<sfdc:objects ref="#[payload]"/>