All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.spring.camel-context.xml Maven / Gradle / Ivy

Go to download

An example demonstrating declarative transformation and validation along data type declaration using Spring DSL

The newest version!
<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You 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.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <!-- START SNIPPET: e1 -->
    <bean id="orderProcessor" class="org.apache.camel.example.transformer.demo.OrderProcessor"/>
    <!-- END SNIPPET: e1 -->

    <camel:camelContext id="order">

        <!-- START SNIPPET: e2 -->
        <camel:dataFormats>
            <camel:json id="jsondf" library="Jackson" unmarshalTypeName="org.apache.camel.example.transformer.demo.Order"/>
        </camel:dataFormats>
        <!-- END SNIPPET: e2 -->

        <!-- START SNIPPET: e3 -->
        <camel:transformers>
            <!-- specifying from&to data type for the Java-CSV transformation -->
            <camel:dataFormatTransformer fromType="java:org.apache.camel.example.transformer.demo.Order" toType="csv:CSVOrder">
                <camel:bindy id="csvdf" type="Csv" classType="org.apache.camel.example.transformer.demo.Order"/>
            </camel:dataFormatTransformer>
            <!-- instead of exact from&to type, scheme name can be specified to apply for all the Java-XML transformation -->
            <camel:dataFormatTransformer scheme="xml">
                <camel:jaxb id="xmldf" contextPath="org.apache.camel.example.transformer.demo"/>
            </camel:dataFormatTransformer>
            <!--  for all the Java-JSON transformation, referring to already defined DataFormat -->
            <camel:dataFormatTransformer ref="jsondf" scheme="json"/>
        </camel:transformers>
        <!-- END SNIPPET: e3 -->
        <!-- START SNIPPET: e8 -->
        <camel:validators>
            <camel:endpointValidator type="xml" uri="validator:xsd/schema.xsd"/>
            <camel:predicateValidator type="json">
                <camel:simple>${body} contains 'orderId' and ${body} not contains 'accepted'</camel:simple>
            </camel:predicateValidator>
            <camel:customValidator type="java:org.apache.camel.example.transformer.demo.OrderResponse"
            className="org.apache.camel.example.transformer.demo.OrderResponseValidator"/>
        </camel:validators>
        <!-- END SNIPPET: e8 -->

        <!-- START SNIPPET: e4 -->
        <camel:route id="xml">
            <camel:from uri="direct:xml"/>
            <!--  This route expects XML as an input/output type -->
            <camel:inputType urn="xml:XMLOrder" validate="true"/>
            <camel:outputType urn="xml:XMLOrderResponse" validate="true"/>
            <camel:to uri="direct:java"/>
        </camel:route>
        <!-- END SNIPPET: e4 -->

        <!-- START SNIPPET: e5 -->
        <camel:route id="json">
            <camel:from uri="direct:json"/>
            <!--  This route expects JSON as an input/output type -->
            <!--  Only scheme 'json' is specified for the type, which means it handles arbitrary JSON content -->
            <camel:inputType urn="json" validate="true"/>
            <camel:outputType urn="json"/>
            <camel:to uri="direct:java"/>
        </camel:route>
        <!-- END SNIPPET: e5 -->

        <!-- START SNIPPET: e6 -->
        <camel:route id="java">
            <camel:from uri="direct:java"/>
            <!-- This route expects Java object as an input/output type. -->
            <!--  If the request comes from xml route, the XML-Java transformer is applied. -->
            <!--  If it comes from json route, the JSON-Java transformer is applied. -->
            <!--  If it's sent via ProducerTemplate directly without specifying input/output type, no transformer is applied. -->
            <camel:inputType urn="java:org.apache.camel.example.transformer.demo.Order"/>
            <camel:outputType urn="java:org.apache.camel.example.transformer.demo.OrderResponse" validate="true"/>
            <camel:wireTap uri="direct:csv"/>
            <camel:process ref="orderProcessor"/>
        </camel:route>
        <!-- END SNIPPET: e6 -->

        <!-- START SNIPPET: e7 -->
        <camel:route id="csv">
            <camel:from uri="direct:csv"/>
            <!-- This route expects CSV as an input type, therefore Java-CSV transformation is triggered -->
            <camel:inputType urn="csv:CSVOrder"/>
            <camel:to uri="file:target/output?fileExist=Append&amp;fileName=orders.csv"/>
        </camel:route>
        <!-- END SNIPPET: e7 -->
    </camel:camelContext>

</beans>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy