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 2010/02/19 11:44:39 UTC

svn commit: r911778 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/language/bean/BeanExpression.java main/java/org/apache/camel/model/RouteDefinition.java test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java

Author: davsclaus
Date: Fri Feb 19 10:44:38 2010
New Revision: 911778

URL: http://svn.apache.org/viewvc?rev=911778&view=rev
Log:
CAMEL-2486: Fail to start route if route has no processor outputs, eg its just a plain from(foo)

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java?rev=911778&r1=911777&r2=911778&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java Fri Feb 19 10:44:38 2010
@@ -66,7 +66,7 @@
         }
         try {
             Exchange newExchange = exchange.copy();
-            // The BeanExperession always has a result regardless of the ExchangePattern,
+            // The BeanExpression always has a result regardless of the ExchangePattern,
             // so I add a checker here to make sure we can get the result.
             if (!newExchange.getPattern().isOutCapable()) {
                 newExchange.setPattern(ExchangePattern.InOut);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java?rev=911778&r1=911777&r2=911778&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java Fri Feb 19 10:44:38 2010
@@ -684,6 +684,15 @@
             }
         }
 
+        // validate route has output processors
+        if (outputs.isEmpty()) {
+            RouteDefinition route = routeContext.getRoute();
+            String at = fromType.toString();
+            Exception cause = new IllegalArgumentException("Route " + route.getId() + " has no output processors."
+                    + " You need to add outputs to the route such as to(\"log:foo\").");
+            throw new FailedToCreateRouteException(route.getId(), route.toString(), at, cause);
+        }
+
         List<ProcessorDefinition> list = new ArrayList<ProcessorDefinition>(outputs);
         for (ProcessorDefinition output : list) {
             try {

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java?rev=911778&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java Fri Feb 19 10:44:38 2010
@@ -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.impl;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class FromHasNoOutputRouteTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testFromHasNoOutputRoute() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // has no output which is a mis configuration
+                from("direct:start");
+            }
+        });
+        try {
+            context.start();
+            fail("Should throw exception");
+        } catch (FailedToCreateRouteException e) {
+            assertEquals("route1", e.getRouteId());
+            IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Route route1 has no output processors. You need to add outputs to the route such as to(\"log:foo\").", cause.getMessage());
+        }
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/FromHasNoOutputRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date