Raul,

 

Thanks for the suggestion.  But unfortunately, it did not help.  Camel throws 
the CamelRuntimeException immediately after (if not part of) the from 
statement.  I do not think the convertBodyTo even had a chance to receive the 
exchange.  So the onException for org.apache.camel.InvalidPayloadException does 
not get executed.

 

I believe that because this is a CXF Web Services consumer using PAYLOAD 
format, CXF tries to convert the payload into CxfPayload class, which might 
assume that the content must be XML.

 

Thanks!

John

From: Raul Kripalani [via Camel] 
[mailto:ml-node+s465427n5736507...@n5.nabble.com] 
Sent: Tuesday, July 30, 2013 3:42 PM
To: bocamel
Subject: Re: Validate Xml

 

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 <[hidden email]> 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. 
> 

 

  _____  

If you reply to this email, your message will be added to the discussion below:

http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736507.html 

To unsubscribe from Validate Xml, click here 
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=472122&code=am9obnp5aW5AZ21haWwuY29tfDQ3MjEyMnwyOTcyNzcxNDg=>
 .
 
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
 NAML 





--
View this message in context: 
http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736518.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to