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