Xml 如何使用ApacheCamel验证xsd?

Xml 如何使用ApacheCamel验证xsd?,xml,validation,xsd,apache-camel,apache-karaf,Xml,Validation,Xsd,Apache Camel,Apache Karaf,我正在使用apacheservicemix,并尝试使用ApacheCamel验证xml文档。我有一条叫做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:schemaL

我正在使用apacheservicemix,并尝试使用ApacheCamel验证xml文档。我有一条叫做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>

org.apache.camel.ValidationException
我创建了3个目录:valid、invalid和finally。 在我运行karaf“start students\u route.xml”之后,什么都没有发生。当我查看日志时,我没有收到任何错误,只收到一些类似这样的消息:“路由:route2已启动并从:Endpoint消费[file://project/students.xml]“。我认为不管xml文件是否有效,都应该在有效/无效目录下创建一个文件


我对这项技术还不熟悉,我不知道如何让它工作。我非常感谢你的帮助。提前谢谢你

下面是一个工作示例:

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

org.apache.camel.ValidationException

玩得开心

我正在使用blueprint从mysql服务器获取数据,告诉我如何用json验证输入数据是否正确

代码如下所示---

--> 任何OSGi Blueprint文件的根元素都是“Blueprint”-您还可以看到Blueprint和Blueprint的命名空间定义 和骆驼名称空间。 --> https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd "> https://camel.apache.org/schema/blueprint"此外,, 我们还可以在CBR的XPath表达式中定义要使用的名称空间前缀

  While it is not required to assign id's to the <camelContext/> and <route/> elements, it is a good idea
  to set those for runtime management purposes (logging, JMX MBeans, ...)
-->
<bean
    class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="DBSource1">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/student_db"/>
    <property name="username" value="root"/>
    <property name="password" value="123"/>
</bean>
<camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
    <dataFormats>
        <json id="jackson" library="Jackson"/>
    </dataFormats>
    <route autoStartup="true" id="_route1">
        <!-- <log id="_log4" message="Recieve data from json Request : ${body}"/> -->
        <from id="_from1" uri="restlet:http://0.0.0.0:8090/api/testDB?restletMethod=POST"/>
        <unmarshal id="_unmarshal1" ref="jackson"/>
        <!-- <bean ref="testDB1" method="processDbData"/> -->
        <log id="_log5" message="Convert the data  : ${body}"/>
        <log id="_log1" message="all headers is : ${headers}"/>
        <setBody id="_setBody1">
            <simple>select * from student_db_dtl where Course_id = ${body[Course_id]} and   Phone_NO=${body["Phone_NO"]}    ;</simple>
            <!-- <log id="_log6" message="print the query : ${body}"/> -->
        </setBody>
        <log id="_log6" message="print the query : ${body}"/>
        <to id="_to1" uri="jdbc:DBSource1"/>
        <marshal id="_marshal1" ref="jackson"/>
        <log id="_log2" message="Response from db : ${body}"/>
        <log id="_log3" message="data after method is : ${body}"/>
    </route>
</camelContext>
虽然不需要为和元素分配id,但这是一个好主意
为运行时管理目的(日志记录、JMX MBeans等)设置
-->
从学生数据库dtl中选择*,其中课程id=${body[课程id]}和电话号码=${body[“电话号码”]};

在我改为感谢你@emmerich之后,它起了作用
  While it is not required to assign id's to the <camelContext/> and <route/> elements, it is a good idea
  to set those for runtime management purposes (logging, JMX MBeans, ...)
-->
<bean
    class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="DBSource1">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/student_db"/>
    <property name="username" value="root"/>
    <property name="password" value="123"/>
</bean>
<camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
    <dataFormats>
        <json id="jackson" library="Jackson"/>
    </dataFormats>
    <route autoStartup="true" id="_route1">
        <!-- <log id="_log4" message="Recieve data from json Request : ${body}"/> -->
        <from id="_from1" uri="restlet:http://0.0.0.0:8090/api/testDB?restletMethod=POST"/>
        <unmarshal id="_unmarshal1" ref="jackson"/>
        <!-- <bean ref="testDB1" method="processDbData"/> -->
        <log id="_log5" message="Convert the data  : ${body}"/>
        <log id="_log1" message="all headers is : ${headers}"/>
        <setBody id="_setBody1">
            <simple>select * from student_db_dtl where Course_id = ${body[Course_id]} and   Phone_NO=${body["Phone_NO"]}    ;</simple>
            <!-- <log id="_log6" message="print the query : ${body}"/> -->
        </setBody>
        <log id="_log6" message="print the query : ${body}"/>
        <to id="_to1" uri="jdbc:DBSource1"/>
        <marshal id="_marshal1" ref="jackson"/>
        <log id="_log2" message="Response from db : ${body}"/>
        <log id="_log3" message="data after method is : ${body}"/>
    </route>
</camelContext>