Skip to content

Instantly share code, notes, and snippets.

View dfeist's full-sized avatar

Daniel Feist dfeist

  • MuleSoft
  • Wokingham, UK
View GitHub Profile
package org.mule.message;
import com.eaio.uuid.UUID;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class GenericMessage<T> implements MuleMessage, Serializable
{
<choice-exception-strategy name="myReusableES">
<catch-exception-strategy when="#[exception.causedBy(org.my.BusinessException)]">
<set-payload message="Error occurred processing order: #[exception.message]"/>
</catch-exception-strategy>
<rollback-exception-strategy maxRedeliveryAttempts="3">
<logger level="DEBUG" message="Message rolled back"/>
<on-redelivery-attempts-exceeded>
<jms:outbound-endpoint queue="DLQ"/>
</on-redelivery-attempts-exceeded>
</catch-exception-strategy>
@dfeist
dfeist / el-config.xml
Created June 26, 2012 19:07
Extend Expression Language
<mule>
<configuration>
<expression-language autoResolveVariables="false">
<import name="loc" class="java.util.Locale" />
<alias name="appName" expression="app.name" />
<global-functions file="org/mule/test/el/functions.txt">
def hello() {'Hello '+appName+'!'}
</global-functions>
</expression-language>
</configuration>
@dfeist
dfeist / manage-payload.xml
Created April 4, 2012 15:41
Replace payload with value or parsed template
<set-payload value="Order: #[message.inboundProperties['id']] Created"/>
<parse-template file="emailTemplate.txt" />
@dfeist
dfeist / manage-properties.xml
Created April 4, 2012 15:37
Manage Message Properties
<set-property propertyName="Content-Type" value="test/html" />
<remove-property propertyName="MULE_*" />
<copy-property propertyName="*" />
@dfeist
dfeist / manage-variables.xml
Created April 4, 2012 15:35
Manage Flow Variables
<set-variable variableName="tzString" value="Timezone is #[server.timeZone]" />
<remove-variable variableName="tzString" />
<flow name="createOrder" >
<http:inbound-endpoint address="http://localhost/api/order" />
<component class="org.my.CreateOrderComponent" />
<http:response-builder status="201" contentType="text/plain">
<http:location value="#[http.context.uri]/#[orderID]"/>
<set-payload value="Order #[orderID] added."/>
</http:response-builder>
<flow>
<configuration>
<expression-language>
<import class="org.mule.util.StringUtils" />
<alias name="in" expression="message.inboundProperties" />
<global-functions file="shared-functions.txt">
def reverse() {StringUtils.reverse(payload)}
</global-functions>
</expression-language>
</configuration>
<enricher target="payload.customer" >
<mongodb:find-one-object collection="customers" query="#[message.inboundProperties['http.query.params']['customerId']" />
</enricher>
<choice>
<when expression="#[server.locale.country=='UK' and message.inboundProperty['fileSize'] < 1024">
<set-variable variableName="priority" value="1"/>
</when>
<when expression="#[server.locale.country=='US' and xpath('count(/order/items)') > 1">
<set-variable variableName="priority" value="2"/>
</when>
</choice>