<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2018 Red Hat, Inc. and/or its affiliates.
  ~
  ~ 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.
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:cxf="http://camel.apache.org/schema/cxf"
       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xmlns:kie="http://drools.org/schema/kie-spring"
       xsi:schemaLocation="
       http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
       http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">

  <kie:kmodule id="CxfRsSpring">
    <kie:kbase name="test1" packages="test1">
      <kie:ksession name="ksession1">
        <kie:batch>
          <kie:set-global identifier="list" >
            <bean class="java.util.ArrayList" />
          </kie:set-global>
        </kie:batch>
      </kie:ksession>
      <kie:ksession name="ksession2"/>
    </kie:kbase>
  </kie:kmodule>

  <bean id="kieSpringPostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>

  <!-- Defined the server endpoint to create the cxf-rs consumer -->
  <cxf:rsServer id="rsServer" 
          address="http://localhost:58001/rest"
                serviceClass="org.kie.jax.rs.CommandExecutorImpl">
       <cxf:providers>
           <bean class="org.kie.jax.rs.CommandMessageBodyReader"/>
       </cxf:providers>
  </cxf:rsServer>  
  
  <bean id="kiePolicy" class="org.kie.camel.embedded.component.KiePolicy" />
    
  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    
    <route>
       <from uri="cxfrs://bean://rsServer"/>
       <policy ref="kiePolicy">
         <unmarshal ref="xstream" />
         <to uri="kie-local:ksession1" />
         <marshal ref="xstream" />
       </policy>
    </route>
    
    <route id="x1">
       <from uri="direct://http"/>
       <policy ref="kiePolicy">
         <to uri="cxfrs://http://localhost:58001/rest"/>
       </policy> 
    </route> 
        
  </camelContext>
  
</beans>
