How can I validate xsd using apache camel?

丶灬走出姿态 提交于 2019-12-03 03:48:31

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!

i am using blueprint for data fatching from mysql server, tale me how to validate my input data is correct or not in json .

the code is given below ---

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.

-->

The root element for any OSGi Blueprint file is 'blueprint' - you also see the namespace definitions for both the Blueprint and the Camel namespaces. --> 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'. Additionally, we can also define namespace prefixes we want to use them in the XPath expressions in our CBR.

  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>

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