panza
panza

Reputation: 1431

XML validation with Apache Validator Component in Camel

I am new to Camel and I am using uri:validator in order to validate an XML against a .XSD file. However, I am not sure I am actually pointing to the .xsd file correctly as I my gradle build fails with the following error:

Caused by: java.io.FileNotFoundException: mydirectory\anotherDirectory\myxsdFile-v1.0.xsd (The system cannot find the path specified)

In my common-routes.xml file, I have the following:

<route>
  <from uri="direct:util-xmltojson"/> 
    <log loggingLevel="INFO" message="XML Validation"/>
      <doTry>
         <to uri="validator:file:mydirectory\anotherDirectory\myxsdFile-v1.0.xsd"/>
         <doCatch> 
           <exception>org.apache.camel.ValidationException</exception>
         </doCatch>
       </doTry>
</route>

Is this the correct way to use the validator component?

Thank you for your help,

I.

Upvotes: 1

Views: 1670

Answers (1)

J&#233;r&#233;mie B
J&#233;r&#233;mie B

Reputation: 11022

The validator component take in the uri the location of the xsd file used for the validation.

This can be:

  • A file, with validator:file:_path_. This path is relative to the folder of the execution of your application
  • A classpath resources (it's, in my opinion, the preferred way): com/test/package/resource.xsd : the schema will be looked in the jar, under com/test/package
  • A remote resource, with validator:http://remotehost/path : camel will download the resource in order to validate the xml

In your example, camel is looking for the file mydirectory\anotherDirectory\myxsdFile-v1.0.xsd which it doesn't found. Check if this file exist, relatively to the execution folder of your application. If this resource is static, you should place it in your jar, and use the classpath lookup.

Upvotes: 1

Related Questions