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

svn commit: r762419 - in /camel/branches/camel-1.x/components/camel-spring/src: main/java/org/apache/camel/spring/ test/java/org/apache/camel/spring/interceptor/ test/resources/org/apache/camel/spring/interceptor/

Author: davsclaus
Date: Mon Apr  6 17:03:00 2009
New Revision: 762419

URL: http://svn.apache.org/viewvc?rev=762419&view=rev
Log:
CAMEL-1519: Fixed setting transaction policies with Spring DSL in a single tag just as its done in the Java DSL.

Modified:
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=762419&r1=762418&r2=762419&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Mon Apr  6 17:03:00 2009
@@ -37,6 +37,7 @@
 import org.apache.camel.model.ExceptionType;
 import org.apache.camel.model.IdentifiedType;
 import org.apache.camel.model.InterceptType;
+import org.apache.camel.model.PolicyRef;
 import org.apache.camel.model.ProceedType;
 import org.apache.camel.model.ProcessorType;
 import org.apache.camel.model.RouteBuilderRef;
@@ -199,40 +200,10 @@
             }
         }
 
-        // setup the intercepts
+        // do special preparation for some concepts such as interceptors and policies
         for (RouteType route : routes) {
-
-            for (InterceptType intercept : intercepts) {
-                List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
-                List<ProcessorType<?>> exceptionHandlers = new ArrayList<ProcessorType<?>>();
-                for (ProcessorType output : route.getOutputs()) {
-                    if (output instanceof ExceptionType) {
-                        exceptionHandlers.add(output);
-                    } else {
-                        outputs.add(output);
-                    }
-                }
-
-                // clearing the outputs
-                route.clearOutput();
-
-                // add exception handlers as top children
-                route.getOutputs().addAll(exceptionHandlers);
-
-                // add the interceptor but we must do some pre configuration beforehand
-                intercept.afterPropertiesSet();
-                InterceptType proxy = intercept.createProxy();
-                route.addOutput(proxy);
-                route.pushBlock(proxy.getProceed());
-
-                // if there is a proceed in the interceptor proxy then we should add
-                // the current outputs to out route so we will proceed and continue to route to them
-                ProceedType proceed = ProcessorTypeHelper.findFirstTypeInOutputs(proxy.getOutputs(), ProceedType.class);
-                if (proceed != null) {
-                    proceed.getOutputs().addAll(outputs);
-                }
-            }
-
+            initInterceptors(route);
+            initPolicies(route);
         }
 
         if (dataFormats != null) {
@@ -271,6 +242,59 @@
         installRoutes();
     }
 
+    private void initInterceptors(RouteType route) {
+        // setup the intercepts correctly as the JAXB have not properly setup our routes
+        for (InterceptType intercept : intercepts) {
+            List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
+            List<ProcessorType<?>> exceptionHandlers = new ArrayList<ProcessorType<?>>();
+            for (ProcessorType output : route.getOutputs()) {
+                if (output instanceof ExceptionType) {
+                    exceptionHandlers.add(output);
+                } else {
+                    outputs.add(output);
+                }
+            }
+
+            // clearing the outputs
+            route.clearOutput();
+
+            // add exception handlers as top children
+            route.getOutputs().addAll(exceptionHandlers);
+
+            // add the interceptor but we must do some pre configuration beforehand
+            intercept.afterPropertiesSet();
+            InterceptType proxy = intercept.createProxy();
+            route.addOutput(proxy);
+            route.pushBlock(proxy.getProceed());
+
+            // if there is a proceed in the interceptor proxy then we should add
+            // the current outputs to out route so we will proceed and continue to route to them
+            ProceedType proceed = ProcessorTypeHelper.findFirstTypeInOutputs(proxy.getOutputs(), ProceedType.class);
+            if (proceed != null) {
+                proceed.getOutputs().addAll(outputs);
+            }
+        }
+    }
+
+    private void initPolicies(RouteType route) {
+        // setup the policies as JAXB yet again have not created a correct model for us
+        List<ProcessorType<?>> types = route.getOutputs();
+        PolicyRef policy = null;
+        for (ProcessorType<?> type : types) {
+            if (type instanceof PolicyRef) {
+                policy = (PolicyRef) type;
+            } else if (policy != null) {
+                // the outputs should be moved to the policy
+                policy.addOutput(type);
+            }
+        }
+        // did we find a policy if so add replace it as the only output on the route
+        if (policy != null) {
+            route.clearOutput();
+            route.addOutput(policy);
+        }
+    }
+
     private <T> T getBeanForType(Class<T> clazz) {
         T bean = null;
         String[] names = getApplicationContext().getBeanNamesForType(clazz, true, true);

Modified: camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java?rev=762419&r1=762418&r2=762419&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java (original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTest.java Mon Apr  6 17:03:00 2009
@@ -70,8 +70,7 @@
         }
 
         int count = jdbc.queryForInt("select count(*) from books");
-        // TODO: Fix this bug with Spring DSL not working with TX policies
-        // assertEquals("Number of books", 1, count);
+        assertEquals("Number of books", 1, count);
     }
 
 }
\ No newline at end of file

Modified: camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml?rev=762419&r1=762418&r2=762419&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml (original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/springTransactionalClientDataSource.xml Mon Apr  6 17:03:00 2009
@@ -48,14 +48,6 @@
         <route>
             <from uri="direct:fail"/>
             <policy ref="PROPAGATION_REQUIRED"/>
-            <setBody>
-                <constant>Tiger in Action</constant>
-            </setBody>
-            <bean ref="bookService"/>
-            <setBody>
-                <constant>Donkey in Action</constant>
-            </setBody>
-            <bean ref="bookService"/>
         </route>
     </camelContext>