camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raul Kripalani <r...@evosent.com>
Subject Re: Validate Xml
Date Tue, 30 Jul 2013 19:40:26 GMT
Try converting the body to a Document.class explicitly (before calling the
validator) and handling the InvalidPayloadException.
For example:

onException(InvalidPayloadException.class)

    .bean(new MyExceptionBean());        // or process(Processor p)

 from("cxf:bean:name")
   .convertBodyTo(Document.class)
   .to("validator:xmlschema.xsd");


The same can be expressed in XML DSL.

Does this help?

Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Jul 30, 2013 at 3:15 PM, bocamel <johnzyin@gmail.com> wrote:

> 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.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message