How can I validate xsd using apache camel?

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

I'm using apacheservicemix and I try to validate a xml document with apache camel. I have this route called students_route.xml :

<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="   http://www.osgi.org/xmlns/blueprint/v1.0.0   http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route>     <from uri="file:project/students.xml"/>     <doTry>     <to uri="validator:file:project/students.xsd"/>     <to uri="file:valid"/>     <doCatch>         <exception>org.apache.camel.ValidationException</exception>         <to uri="file:invalid"/>     </doCatch>     <doFinally>         <to uri="file:finally"/>     </doFinally>     </doTry> </route> </camelContext> </blueprint> 

I created 3 directories called: valid, invalid and finally. After I run in karaf "start students_route.xml" nothing happens. When I look into logs I get no errors just some messages like this: "Route: route2 started and consuming from: Endpoint[file://project/students.xml]".I imagine that a file should be created under valid/invalid directories whether the xml file is valid or not.

I'm new to this technologies and I have no idea how to make this work. I would really appreciate your help. Thank you in advance!

回答1:

Here's a working example:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:camel="http://camel.apache.org/schema/blueprint"        xsi:schemaLocation="        http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd        http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/spring/camel-blueprint.xsd">    <camelContext xmlns="http://camel.apache.org/schema/blueprint">       <route>           <from uri="file:flights/data-in?noop=false"/>           <doTry>               <to uri="validator:file:flights/schema/flight.xsd"/>               <to uri="file:flights/data-valid"/>               <doCatch>                   <exception>org.apache.camel.ValidationException</exception>                   <to uri="file:flights/data-invalid"/>               </doCatch>               <!--               <doFinally>                   <to uri="file:test/src/data/finally"/>               </doFinally>               -->           </doTry>       </route>    </camelContext>  </blueprint> 

Have fun!



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!