Reputation: 143
What is the current best approach for checking that an incoming XML message is well formed in Mule?
For example if I send badly formed (or non) XML to this choice then Mule throws an error and the flow stops:
<choice>
<when expression="#[xpath('fn:count(//event/@publicID)') != 0]">
....
The error is like:
[Fatal Error] :1:1: Content is not allowed in prolog.
java.lang.RuntimeException: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "fn:count(//event/@publicID)"
at org.mule.module.xml.el.XPathFunction.call(XPathFunction.java:50)
And, alternatively, is there a way to catch and ignore this error in the flow? I've tried the exception strategies as per the docs and got no where.
Thanks, Geoff
Upvotes: 0
Views: 369
Reputation: 11606
You might have solved this by now, however there's a convenient filter in the mule xml module that may help:
<mulexml:is-xml-filter />
This filters out non/bad xml. You can use this with the message-filter to route to a dlq or throw an exception etc.
Also I can catch that exception as follows:
<choice-exception-strategy>
<catch-exception-strategy when="#[exception.causedBy(org.mule.api.MuleRuntimeException)]">
<logger level="ERROR" message="not xml" />
</catch-exception-strategy>
</choice-exception-strategy>
Upvotes: 1