svn commit: r690965 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/ main/scala/org/apache/camel/scala/dsl/builder/ test/scala/org/apache/camel/scala/dsl/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r690965 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/dsl/ main/scala/org/apache/camel/scala/dsl/builder/ test/scala/org/apache/camel/scala/dsl/

gertv-2
Author: gertv
Date: Mon Sep  1 06:10:38 2008
New Revision: 690965

URL: http://svn.apache.org/viewvc?rev=690965&view=rev
Log:
CAMEL-463: Adding support for handling exceptions in the RouteBuilder

Added:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SExceptionType.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ExceptionHandlerTest.scala
Modified:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STryType.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest.scala

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SExceptionType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SExceptionType.scala?rev=690965&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SExceptionType.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SExceptionType.scala Mon Sep  1 06:10:38 2008
@@ -0,0 +1,29 @@
+/**
+ * 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 org.apache.camel.model.ExceptionType
+import org.apache.camel.scala.dsl.builder.RouteBuilder
+
+/**
+ * Scala enrichment for Camel's ExceptionType
+ */
+class SExceptionType(val target: ExceptionType)(implicit val builder: RouteBuilder) extends SAbstractType with Wrapper[ExceptionType] {
+  
+  val unwrap = target
+  
+}
\ No newline at end of file

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STryType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STryType.scala?rev=690965&r1=690964&r2=690965&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STryType.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/STryType.scala Mon Sep  1 06:10:38 2008
@@ -20,7 +20,7 @@
 import org.apache.camel.scala.dsl.builder.RouteBuilder
 
 /**
- * Scala enrichment for Camel's DelayerType
+ * Scala enrichment for Camel's TryType
  */
 class STryType(val target: TryType)(implicit val builder: RouteBuilder) extends SAbstractType with Wrapper[TryType] {
   

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala?rev=690965&r1=690964&r2=690965&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/builder/RouteBuilder.scala Mon Sep  1 06:10:38 2008
@@ -49,6 +49,8 @@
   }
 
   def from(uri: String) = new SRouteType(builder.from(uri), this)
+  def handle[Target](exception: Class[Target]) = new SExceptionType(builder.exception(exception))(this)
+  
 
   def attempt = stack.top.attempt
   def bean(bean: Any) = stack.top.bean(bean)

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ExceptionHandlerTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ExceptionHandlerTest.scala?rev=690965&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ExceptionHandlerTest.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ExceptionHandlerTest.scala Mon Sep  1 06:10:38 2008
@@ -0,0 +1,71 @@
+/**
+ * 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 org.w3c.dom.Document
+import scala.dsl.builder.RouteBuilder
+import junit.framework.Assert._
+
+/**
+ * Test case for exception handler
+ */
+class ExceptionHandlerTest extends ScalaTestSupport {
+  
+  var handled = false;
+  
+  def testTryCatchFinally = {
+    "mock:a" expect { _.count = 1 }
+    "mock:b" expect { _.count = 1 }
+    "mock:c" expect { _.count = 1 }
+    test {
+       "direct:a" ! ("any given message", 'Symbol, 256)
+    }
+  }
+    
+  val builder =
+    new RouteBuilder {
+       def failingProcessor(exchange: Exchange) = {
+         exchange.in match {
+           case text: String => //graciously do nothing
+           case symbol: Symbol => throw new UnsupportedOperationException("We don't know how to deal with this symbolically correct")
+           case _ => throw new RuntimeException("Strings are good, the rest is bad")
+         }
+       }
+      
+       def catchProcessor(exchange: Exchange) = {
+          // we shouldn't get any Strings here
+          assertFalse(exchange.getIn().getBody().getClass().equals(classOf[String]))
+          // the exchange shouldn't have been marked failed
+          assertFalse(exchange.isFailed)
+       }
+      
+       //START SNIPPET: simple
+       handle(classOf[UnsupportedOperationException]) to "mock:c"
+       //END SNIPPET: simple
+      
+       //START SNIPPET: block
+       handle(classOf[RuntimeException]) {
+           process(catchProcessor)
+           to ("mock:b")
+       }
+       //END SNIPPET: block
+      
+       "direct:a" process(failingProcessor) to ("mock:a")
+      
+    }
+
+}

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest.scala?rev=690965&r1=690964&r2=690965&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/TryCatchFinallyTest.scala Mon Sep  1 06:10:38 2008
@@ -21,7 +21,7 @@
 import junit.framework.Assert._
 
 /**
- * Test case for try (monitor) - catch (handle) - finally (always)
+ * Test case for try (attempt) - catch (handle) - finally (ensure)
  */
 class TryCatchFinallyTest extends ScalaTestSupport {