如何使用 apache camel 验证 xsd?
How can I validate xsd using apache camel?
我正在使用 apacheservicemix 并尝试使用 apache camel 验证 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>
我创建了 3 个目录:valid、invalid 和 finally。
在我 运行 在 karaf "start students_route.xml" 之后没有任何反应。当我查看日志时,我没有得到任何错误,只是一些像这样的消息:"Route: route2 started and consuming from: Endpoint[file://project/students.xml]"。我想应该在 valid/invalid 目录下创建一个文件,无论 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>
玩得开心!
我正在使用蓝图从 mysql 服务器获取数据,告诉我如何在 json 中验证我的输入数据是否正确。
代码如下---
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
任何 OSGi 蓝图文件的根元素都是 'blueprint' - 您还会看到两个蓝图的名称空间定义
和 Camel 命名空间。
-->
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-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>
我正在使用 apacheservicemix 并尝试使用 apache camel 验证 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>
我创建了 3 个目录:valid、invalid 和 finally。 在我 运行 在 karaf "start students_route.xml" 之后没有任何反应。当我查看日志时,我没有得到任何错误,只是一些像这样的消息:"Route: route2 started and consuming from: Endpoint[file://project/students.xml]"。我想应该在 valid/invalid 目录下创建一个文件,无论 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>
玩得开心!
我正在使用蓝图从 mysql 服务器获取数据,告诉我如何在 json 中验证我的输入数据是否正确。
代码如下---
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
任何 OSGi 蓝图文件的根元素都是 'blueprint' - 您还会看到两个蓝图的名称空间定义 和 Camel 命名空间。 --> https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-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>