You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/03/06 04:44:58 UTC

svn commit: r750761 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/ test/java/org/apache/camel/spring/interceptor/ test/java/org/apache/camel/spring/interceptor/route/ test/resources/org/apache/camel/spring/interceptor/

Author: ningjiang
Date: Fri Mar  6 03:44:57 2009
New Revision: 750761

URL: http://svn.apache.org/viewvc?rev=750761&view=rev
Log:
CAMEL-1426 Fixed the issue of SpringRouteBuilder loading from Spring configuration

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java   (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml   (with props)
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java?rev=750761&r1=750760&r2=750761&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/SpringRouteBuilder.java Fri Mar  6 03:44:57 2009
@@ -17,11 +17,13 @@
 package org.apache.camel.spring;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.spring.spi.SpringTransactionPolicy;
 import org.apache.camel.spring.spi.TransactionErrorHandlerBuilder;
 import org.apache.camel.spring.spi.TransactionInterceptor;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
 import org.springframework.transaction.support.TransactionTemplate;
 
 /**
@@ -30,7 +32,7 @@
  *
  * @version $Revision$
  */
-public abstract class SpringRouteBuilder extends RouteBuilder {
+public abstract class SpringRouteBuilder extends RouteBuilder implements ApplicationContextAware {
     private ApplicationContext applicationContext;
 
     public TransactionInterceptor transactionInterceptor() {
@@ -97,7 +99,7 @@
     /**
      * Sets the application context to use to lookup beans
      */
-    public void setApplicationContext(ApplicationContext applicationContext) {
+    public void setApplicationContext(ApplicationContext applicationContext) {        
         this.applicationContext = applicationContext;
     }
 

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java?rev=750761&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java Fri Mar  6 03:44:57 2009
@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+package org.apache.camel.spring.interceptor;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class TransactionalClientDataSourceWithSpringRouteBuilderTest extends TransactionalClientDataSourceTest {
+    
+    @Override
+    protected void setUp() throws Exception {
+        setUseRouteBuilder(false);
+        super.setUp();        
+    }
+    
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext(
+            "/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml");
+    }
+
+    @Override
+    protected int getExpectedRouteCount() {
+        return 1;
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceWithSpringRouteBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java?rev=750761&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java Fri Mar  6 03:44:57 2009
@@ -0,0 +1,52 @@
+/**
+ * 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.
+ */
+package org.apache.camel.spring.interceptor.route;
+
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.apache.camel.spring.spi.SpringTransactionPolicy;
+
+public class DataSourceSpringRouteBuilder extends SpringRouteBuilder {
+    
+    public void configure() throws Exception {
+        
+        SpringTransactionPolicy required = bean(SpringTransactionPolicy.class, "PROPAGATION_REQUIRED");
+
+        
+        // useTransactionErrorHandler is only used for unit testing to reuse code
+        // for doing a 2nd test without this transaction error handler, so ignore
+        // this. For spring based transaction, end users are encouraged to use the
+        // transaction error handler instead of the default DeadLetterChannel.
+        errorHandler(transactionErrorHandler(required).
+            // notice that the builder has builder methods for chained configuration
+            delay(5 * 1000L));
+        
+
+       
+        // set the required policy for this route
+        from("direct:okay").policy(required).
+            setBody(constant("Tiger in Action")).beanRef("bookService").
+            setBody(constant("Elephant in Action")).beanRef("bookService");
+
+        // set the required policy for this route
+        from("direct:fail").policy(required).
+            setBody(constant("Tiger in Action")).beanRef("bookService").
+            setBody(constant("Donkey in Action")).beanRef("bookService");
+        
+    }
+}
+
+

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/route/DataSourceSpringRouteBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml?rev=750761&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml Fri Mar  6 03:44:57 2009
@@ -0,0 +1,30 @@
+<?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-2.5.xsd
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+   <import resource="transactionalClientDataSource.xml"/>
+   
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+      <package>org.apache.camel.spring.interceptor.route</package>
+   </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/transactionalClientDataSourceWithSpringRouteBuilder.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml