This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Let's see if anyone can answer this question before I do it myself (no, I do not have a good answer as of now):
Using Mule 3.10 I had a private flow that passed the message through a number of filters. If no filter matched, an exception was thrown.
The exception was propagated to the invoking flow. However, in Mule 3.20 this behaviour with exceptions propagating out of private flows has been fixed, since it was considered to be a bug.
Thus, I now need my private flow to produce two different results, lets say "true" or "false", depending on whether any filter matched or no filter matched. I also need to keep the message being processed intact, that is not replaced by a NullPayload or such.
This has proved less simple than it sounds, so I ask if anyone has any hints.
Thanks in advance!
Funny, once the question has been asked, the answer is not far away.
Solved this issue as described below. Perhaps not the most elegant way - suggestions as how to improve are very welcome!
- Mule 3.2.0 community edition.
- Use flows (not services - that is the Mule 2.x version).
- Have a private flow that is responsible for validation.
- Invoke the private flow from another flow.
- Use only Mule standard components, filters, routers etc.
- Retain the message payload, regardless of whether it is valid or invalid, after validation.
In the private flow I use a <message-filter> with the throwOnUnaccepted attribute set to false.
I do not want the <message-filter> to throw an exception when encountering messages that do not pass validation since this would cause the message payload to be set to null.
After the <message-filter>, I set a message property indicating validation success.
Note that nothing done in the private flow will have any effect if the message does not pass validation - i.e. I cannot set a default, false, value of the message property indicating validation success, since it will be removed if the message does not pass validation.
In the flow invoking the private flow, I use a <choice> element with a <when> and an <otherwise> element.
The <when> element inspects the message for the property indicating validation success:
The <otherwise> element catches all other conditions, that is the message not passing validation.
The complete example will be made available in my upcoming book.