Reference Exception Strategy in Mule

Reference Exception Strategy in Mule

This is to refer to a common exception strategy which you can define in a separate configuration file. You can create one or more global exception strategies to reuse in flows throughout your entire Mule application.

You can create one or more global exception strategies in your Mule application to reuse in your flows. First, create a global exception strategy, then add a reference strategy exception to the flow to apply the error-handling behavior of your new global catch exception strategy.

For this, add a Reference Exception Strategy to a flow to refer the error handling the behavior of a specific global exception strategy.

For this we need to create two exception files :

1. flow.xml
2. global.xml

flow of reference exception strategy :

flow of global.xml :

Configuration of reference exception strategy

We need to give flow name present in global.xml

URL : http://localhost:8085/api/ex/{id}
Method :POST

Input :

Output :

XML project code :


<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:metadata="" xmlns:tracking="" xmlns:dw="" xmlns:json="" xmlns:http="" xmlns="" xmlns:doc="" xmlns:spring="" xmlns:xsi="" xsi:schemaLocation=""> <http:listener-config name="HTTP_Listener_Configuration" host="" port="8085" doc:name="HTTP Listener Configuration" basePath="/api"/> <flow name="ref_exceptionFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/ex/{id}" doc:name="HTTP" /> <set-variable variableName="var1" value="#[message.inboundProperties.'http.uri.params'.id]" doc:name="Variable" /> <dw:transform-message doc:name="Transform Message"> <dw:set-payload><![CDATA[%dw 1.0 %output application/xml --- { id : }]]></dw:set-payload> </dw:transform-message> <set-payload value="#[payload]" doc:name="Set Payload" /> <exception-strategy ref="exception_demoChoice_Exception_Strategy" doc:name="Reference Exception Strategy"/> </flow> </mule>

global.xml :

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:cluster="" xmlns:http="" xmlns="" xmlns:doc=""
    <configuration defaultExceptionStrategy-ref="exception_demoChoice_Exception_Strategy" doc:name="Configuration">
        <http:config useTransportForUris="false"/>
 <choice-exception-strategy name="exception_demoChoice_Exception_Strategy">
<catch-exception-strategy doc:name="choiceexceptionhandling" when="#[exception.causeMatches('com.mulesoft.weave.*')]">
<set-property propertyName="http.status" value="400"
doc:name="Property" />
<set-payload value="input is not correct" doc:name="Set Payload" />
<catch-exception-strategy doc:name="choiceexceptionhandling1">
<set-property propertyName="http.status" value="500"
doc:name="Property" />
<set-payload value="internal server error" doc:name="Set Payload" />

© 2020

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave