<?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.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
    xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
    xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
    xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/cxf/camel-cxf-blueprint.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <!-- Rest Converter. Convert object extends by org.kie.api.command.Command 
        to string -->
    <bean id="resultMessageProvider"
        class="org.apache.servicemix.examples.drools.camel.cxf.server.osgi.CommandMessageBodyRW" />

    <!-- Camel REST Client -->
    <cxf:rsClient id="droolsRestClient" address="http://localhost:8181/cxf/rest"
        serviceClass="org.kie.jax.rs.CommandExecutorImpl">
        <cxf:providers>
            <ref component-id="resultMessageProvider" />
        </cxf:providers>
    </cxf:rsClient>

    <!-- Utils. -->
    <bean id="customerUtil"
        class="org.apache.servicemix.examples.drools.camel.cxf.server.osgi.Utils" />

    <!-- Bean insert to Camel message configuration parameters
        for cxf camel component -->
    <bean id="preCxfrs" class="org.kie.camel.component.PreCxfrs" />

    <!-- Bean trim response and convert request from InputStream to String -->
    <bean id="postCxfrs" class="org.kie.camel.component.PostCxfrs" />

    <!-- CAMEL -->
    <camelContext id="camel-client"
        xmlns="http://camel.apache.org/schema/blueprint">

        <route id="route-to-rest">
            <!-- Self-Timer -->
            <from
                uri="timer:restClientMock?fixedRate=true&amp;period=30s&amp;delay=5000" />
            <process ref="preCxfrs" />
            <!-- Create Customer with random salary -->
            <bean method="customer" ref="customerUtil" />
            <!-- Create KIE Commands -->
            <bean method="insertAndFireAll" ref="customerUtil" />
            <!-- Run CXF Rest client -->
            <to uri="cxfrs:bean:droolsRestClient" />
            <process ref="postCxfrs" />
            <!-- The result it's printed in the logs. -->
            <to uri="log:DroolsRestResult" />
        </route>


    </camelContext>

</blueprint>