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 2011/11/21 04:21:15 UTC

svn commit: r1204338 - in /camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/SRouteDefinition.scala test/scala/org/apache/camel/scala/dsl/RouteErrorHandlerTest.scala

Author: ningjiang
Date: Mon Nov 21 03:21:15 2011
New Revision: 1204338

URL: http://svn.apache.org/viewvc?rev=1204338&view=rev
Log:
CAMEL-4698 Added support of defining route-scoped error handlers in Scala DSL

Added:
    camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RouteErrorHandlerTest.scala
Modified:
    camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SRouteDefinition.scala

Modified: camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SRouteDefinition.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SRouteDefinition.scala?rev=1204338&r1=1204337&r2=1204338&view=diff
==============================================================================
--- camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SRouteDefinition.scala (original)
+++ camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SRouteDefinition.scala Mon Nov 21 03:21:15 2011
@@ -18,6 +18,7 @@ package org.apache.camel.scala.dsl;
 
 import org.apache.camel.model.RouteDefinition
 import org.apache.camel.scala.dsl.builder.RouteBuilder
+import org.apache.camel.builder.ErrorHandlerBuilder
 
 case class SRouteDefinition(override val target: RouteDefinition, val builder: RouteBuilder) extends SAbstractDefinition[RouteDefinition] {
  
@@ -28,4 +29,8 @@ case class SRouteDefinition(override val
     this
   }
 
+  def errorHandler(handler: ErrorHandlerBuilder): SRouteDefinition = {
+    target.errorHandler(handler)
+    this
+  }
 }

Added: camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RouteErrorHandlerTest.scala
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RouteErrorHandlerTest.scala?rev=1204338&view=auto
==============================================================================
--- camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RouteErrorHandlerTest.scala (added)
+++ camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/RouteErrorHandlerTest.scala Mon Nov 21 03:21:15 2011
@@ -0,0 +1,54 @@
+/**
+ * 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.scala.dsl
+
+import builder.RouteBuilder
+import org.apache.camel.Exchange
+import org.junit.Assert._
+
+class RouteErrorHandlerTest extends ScalaTestSupport {
+
+  def testRouteHandlerActive {
+    "mock:deadLetter" expect {
+      _.expectedMessageCount(1)
+    }
+
+    test {
+      "direct:hasHandler" ! "hello world"
+    }
+
+  }
+
+  def testContextHandlerStillActive {
+    try {
+      test {
+        "direct:noHandler" ! "hello world"
+        fail("Default error handler not used.")
+      }
+    } catch {
+      case _:Exception => {} // pass
+    }
+  }
+
+  val builder = new RouteBuilder {
+    "direct:noHandler" process (causeError _) to "mock:noHandler"
+
+    "direct:hasHandler" errorHandler (deadLetterChannel("mock:deadLetter")) process (causeError _) to "mock:hasHandler"
+  }
+
+  def causeError(exch: Exchange) = throw new Exception("Error in route.")
+}
\ No newline at end of file