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

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

There is a newer version: 2.25.2
Show newest version
<?xml version="1.0" encoding="UTF-8"?>
<!--
    http://code.google.com/a/apache-extras.org/p/camel-extra

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.


    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.

    http://www.gnu.org/licenses/gpl-2.0-standalone.html
-->

<!-- Configures the Camel Context-->

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

  <!-- this is the JDBC data source which uses an in-memory only Apache Derby database -->
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
    <property name="url" value="jdbc:derby:memory:orders;create=true"/>
    <property name="username" value=""/>
    <property name="password" value=""/>
  </bean>

  <!-- order bean is our business logic bean that creates new orders -->
  <bean id="orderBean" class="org.apacheextras.camel.examples.hibernate.OrderBean"/>

  <camelContext xmlns="http://camel.apache.org/schema/spring">

    <!-- route that generate new orders and insert them in the database -->
    <route id="generateOrder-route">
      <from uri="timer:foo?period=5s"/>
      <transform>
        <method ref="orderBean" method="generateOrder"/>
      </transform>
      <to uri="hibernate:org.apacheextras.camel.examples.hibernate.Order"/>
      <log message="Inserted new order ${body.id}"/>
    </route>


    <!-- route that process the orders by picking up new rows from the database
         and when done processing then update the row to mark it as processed -->
    <route id="processOrder-route">
      <from uri="hibernate:org.apacheextras.camel.examples.hibernate.Order?delay=1s"/>
      <to uri="bean:orderBean?method=processOrder"/>
      <log message="${body}"/>
    </route>

  </camelContext>

  <!-- setup the Camel hibernate component -->
  <bean id="hibernate" class="org.apacheextras.camel.component.hibernate.HibernateComponent">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="transactionStrategy" ref="springTransactionStrategy"/>
  </bean>

  <!-- setup hibernate and spring to use transaction -->
  <bean id="springTransactionStrategy" class="org.apacheextras.camel.component.hibernate.SpringTransactionStrategy">
    <constructor-arg ref="sessionFactory"/>
    <constructor-arg ref="transactionTemplate"/>
  </bean>
  <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
  </bean>
  <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
    <property name="transactionManager" ref="transactionManager"/>
  </bean>

  <!-- setup Hibernate session factory -->
  <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <!-- here we define the hibernate mapping files we use -->
    <property name="mappingResources">
      <list>
        <value>Order.hbm.xml</value>
      </list>
    </property>
    <!-- and here we have additional hibernate options -->
    <property name="hibernateProperties">
      <value>
        hibernate.dialect=org.hibernate.dialect.DerbyTenSevenDialect
        hibernate.hbm2ddl.auto=create
      </value>
    </property>
  </bean>

</beans>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy