Author: davsclaus
Date: Fri Aug 19 07:52:45 2011
New Revision: 1159528

URL: http://svn.apache.org/viewvc?rev=1159528&view=rev
Log:
CAMEL-4353: Improved error message if using transacted in the DSL and TX 
manager could not be found. Now we fail fast with detailed exception.

Added:
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransactedDefinition.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java?rev=1159528&r1=1159527&r2=1159528&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/NoSuchBeanException.java 
Fri Aug 19 07:52:45 2011
@@ -31,7 +31,7 @@ public class NoSuchBeanException extends
     }
 
     public NoSuchBeanException(String name, String type) {
-        super("No bean could be found in the registry for: " + name + " of 
type: " + type);
+        super("No bean could be found in the registry" + (name != null ? " 
for: " + name : "") + " of type: " + type);
         this.name = name;
     }
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransactedDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransactedDefinition.java?rev=1159528&r1=1159527&r2=1159528&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransactedDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/TransactedDefinition.java
 Fri Aug 19 07:52:45 2011
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlAttr
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.processor.WrapProcessor;
@@ -187,6 +188,7 @@ public class TransactedDefinition extend
             answer = routeContext.lookup(PROPAGATION_REQUIRED, 
TransactedPolicy.class);
         }
 
+        // this logic only applies if we are a transacted policy
         // still no policy found then try lookup the platform transaction 
manager and use it as policy
         if (answer == null && type == TransactedPolicy.class) {
             Class tmClazz = 
routeContext.getCamelContext().getClassResolver().resolveClass("org.springframework.transaction.PlatformTransactionManager");
@@ -216,16 +218,15 @@ public class TransactedDefinition extend
                         ObjectHelper.invokeMethod(method, txPolicy, 
transactionManager);
                         return txPolicy;
                     } else {
-                        LOG.warn("Cannot create a transacted policy as 
camel-spring.jar is not on the classpath!");
+                        // camel-spring is missing on the classpath
+                        throw new RuntimeCamelException("Cannot create a 
transacted policy as camel-spring.jar is not on the classpath!");
                     }
                 } else {
-                    if (LOG.isDebugEnabled()) {
-                        if (maps.isEmpty()) {
-                            LOG.debug("No PlatformTransactionManager found in 
registry.");
-                        } else {
-                            LOG.debug("Found {} PlatformTransactionManager in 
registry. "
-                                    + "Cannot determine which one to use. 
Please configure a TransactionTemplate on the policy", maps.size());
-                        }
+                    if (maps.isEmpty()) {
+                        throw new NoSuchBeanException(null, 
"PlatformTransactionManager");
+                    } else {
+                        throw new IllegalArgumentException("Found " + 
maps.size() + " PlatformTransactionManager in registry. "
+                                + "Cannot determine which one to use. Please 
configure a TransactionTemplate on the transacted policy.");
                     }
                 }
             }

Added: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java?rev=1159528&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
 Fri Aug 19 07:52:45 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.NoSuchBeanException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class JavaDslTransactedNoTXManagerTest extends ContextTestSupport {
+
+    public void testTransactedNoTXManager() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .transacted()
+                    .to("mock:result");
+            }
+        });
+        try {
+            context.start();
+            fail("Should have thrown an exception");
+        } catch (FailedToCreateRouteException e) {
+            NoSuchBeanException cause = 
assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
+            assertEquals("No bean could be found in the registry of type: 
PlatformTransactionManager", cause.getMessage());
+        }
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+}


Reply via email to