I recently ran into this scenario. My Camel route acts as a web services
server that receives an XML message in PAYLOAD format. The very next step
in the route after receiving the message is to validate the message using
<to uri="validator:xxxxxxxx.xsd"/>. However, if the input XML message is
not well formed, Camel generates a CamelRuntimeException before passing it
to the validator. I ended up having to parse this CamelRuntimeException.
In the case of ill-formed XML, the exception always contains "Problem
converting content to Element". I used the following exception handling to
send back a soap fault to the web services client:
<camel:onException>
<camel:exception>java.lang.RuntimeException</camel:exception>
<camel:handled>
<camel:constant>true</camel:constant>
</camel:handled>
<camel:filter>
<camel:spel>#{properties['CamelExceptionCaught'] matches
'.*Problem
converting content to Element.*'}</camel:spel>
<camel:process ref="throwExceptionProcessor" />
</camel:filter>
</camel:onException>
The throwExceptionProcess bean builds a SOAP fault message and sets the HTTP
code to 400.
If there is a better way to do this, I would like to know.
--
View this message in context:
http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736492.html
Sent from the Camel - Users mailing list archive at Nabble.com.