Studio Visual Editor
-
Search for "choice" and drag and drop the choice exception strategy icon into the footer bar of a flow.
-
Click the title bar of the exception strategy to open its Properties Editor, then enter a name for your choice exception strategy in the Display Name field.
-
Search for "rollback" and drag and drop one or more catch or rollback exception strategy icons into the choice exception strategy box.
Keep in mind that the choice exception strategy checks the expression attribute of each of its exception strategies one by one, serially, to see which one should handle the error; it then routes the message to the first exception strategy that evaluates to true
. Therefore, organize your exception strategies keeping in mind that the top-most evaluates first, then the one below it, and so on. You cannot rearrange the exception strategies once they have been placed inside the choice exception strategy. You can always resort to the XML view of your project to rearrange their order if necessary. -
Follow the instructions to define and configure each catch exception strategy and rollback exception strategy. Be sure to enter a Mule expression in the Execute When field or the XML when parameter of each catch or rollback (respectively) exception strategy that you put into the choice exception strategy. The contents of Execute When or when determine what kind of errors the exception strategy accepts and processes.
You can leave the Execute When field blank in the last exception strategy configured inside your choice exception strategy. An exception strategy with a blank Execute When field accepts and processes any and all kinds of exceptions that messages throw in the parent flow. -
Search for and drag processors from the palette into each catch exception strategy and rollback exception strategy box to build flows to process messages with errors. Each catch and rollback exception strategy can contain any number of message processors.
XML Editor or Standalone
-
In your flow, below all the message processors, add a
choice-exception-strategy
element. Refer to code below. -
Configure attributes of the exception strategy according to the table below.
Attribute Req’d Value doc:name
x
A unique name for the rollback exception strategy in your application.
Not required in Standalone.<choice-exception-strategy doc:name="Choice Exception Strategy"/>
-
As child elements, add one or more catch or rollback exception strategy icons to your choice exception strategy.
Keep in mind that the choice exception strategy checks the expression attribute of each of its exception strategies one by one, serially, to see which one of them should handle the error; it then routes the message to the first exception strategy that evaluates to true
. Therefore, organize your exception strategies keeping in mind that the top-most evaluates first, then the one below it, and so on.<flow name="Sample_Flow"> ... <choice-exception-strategy doc:name="Choice Exception Strategy"> <catch-exception-strategy doc:name="Catch Exception Strategy"/> <rollback-exception-strategy doc:name="Rollback Exception Strategy"/> </choice-exception-strategy> </flow>
-
Follow the instructions to define and configure each catch exception strategy and rollback exception strategy. Be sure to define a Mule expression as the value of the
when
attribute of each catch or rollback (respectively) exception strategy that you have put into the choice exception strategy. The value of thewhen
attributes determine what kind of errors the exception strategy accepts and processes.You can leave the value of the when
attribute empty in the last exception strategy configured inside your choice exception strategy. An exception strategy with an emptywhen
attribute accepts and processes any and all kinds of exceptions that messages throw in the parent flow. -
Add message processors as child elements in each catch exception strategy and rollback exception strategy to build exception strategy flows to process messages with errors. Each catch and rollback exception strategy can contain any number of message processors.
<flow name="Sample_Flow"> ... <choice-exception-strategy doc:name="Choice Exception Strategy"> <catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causedBy(org.mule.api.routing.filter.FilterUnacceptedException)]"> <set-variable variableName="errorStatusCode" value="404" doc:name="Set status code"/> <set-variable variableName="errorReasonPhrase" value="Not Found" doc:name="Set reason phrase"/> </catch-exception-strategy> <rollback-exception-strategy doc:name="Rollback Exception Strategy"> <logger level="INFO" doc:name="Logger" message="Unknown error"/> </rollback-exception-strategy> </choice-exception-strategy> </flow>