blob: d9cef3eee11876218b45a4a68cb61a1cefaeb1ba [file] [log] [blame]
<?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"
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
">
<!-- the data source -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:camel"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<!-- spring transaction manager -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- the bean which inserts data in the database -->
<bean id="bookService" class="org.apache.camel.spring.interceptor.BookService">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- spring template is requires new -->
<bean id="PROPAGATION_REQUIRES_NEW_TEMPLATE"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="txManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
</bean>
<!-- the error handler we use which is transactional -->
<bean id="myErrorHandler" class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
<property name="transactionTemplate" ref="PROPAGATION_REQUIRES_NEW_TEMPLATE"/>
</bean>
<!-- use the error handler -->
<camelContext errorHandlerRef="myErrorHandler" xmlns="http://camel.apache.org/schema/spring">
<!-- define a global on exception to log the exception -->
<onException>
<exception>java.lang.Exception</exception>
<log loggingLevel="ERROR" message="Damn this failed because of: ${exception.message}"/>
<to uri="mock:onException"/>
</onException>
<!-- the route which is transacted -->
<route>
<from uri="direct:start"/>
<transacted/>
<!-- if fail then this bean will thrown an exception -->
<bean ref="bookService"/>
<to uri="mock:result"/>
</route>
</camelContext>
</beans>