Author: hadrian
Date: Thu Oct  9 18:06:09 2008
New Revision: 703304

URL: http://svn.apache.org/viewvc?rev=703304&view=rev
Log:
CAMEL-961

Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?rev=703304&r1=703303&r2=703304&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
 Thu Oct  9 18:06:09 2008
@@ -138,6 +138,17 @@
     }
 
     /**
+     * Adds an exception handler route for the given exception types
+     */
+    public ExceptionType onException(Class... exceptions) {
+        ExceptionType last = null;
+        for (Class ex : exceptions) {
+            last = last == null? onException(ex) : last.onException(ex);
+        }
+        return last != null ? last : onException(Exception.class);
+    }
+
+    /**
      * Adds an exception handler route for the given exception type
      *
      * @deprecated Please use [EMAIL PROTECTED] #onException(Class)} instead. 
Will be removed in Camel 2.0.

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java?rev=703304&r1=703303&r2=703304&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
 Thu Oct  9 18:06:09 2008
@@ -71,7 +71,16 @@
     public String toString() {
         return "Exception[ " + getExceptionClasses() + " -> " + getOutputs() + 
"]";
     }
-
+    
+    /**
+     * Catches an exception type.
+     */
+    @Override
+    public ExceptionType onException(Class exceptionType) {
+        getExceptionClasses().add(exceptionType);
+        return this;
+    }
+    
     /**
      * Allows an exception handler to create a new redelivery policy for this 
exception type
      * @param parentPolicy the current redelivery policy

Modified: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java?rev=703304&r1=703303&r2=703304&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
 Thu Oct  9 18:06:09 2008
@@ -120,6 +120,23 @@
         mock.assertIsSatisfied();
     }
 
+    public void testSecurityConfiguredWithExceptionList() throws Exception {
+        // test that we also handles a configuration with a list of exceptions
+        MockEndpoint mock = getMockEndpoint(ERROR_QUEUE);
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived(MESSAGE_INFO, "Damm some access error");
+
+        try {
+            template.sendBody("direct:a", "I am not allowed to access this");
+            fail("Should have thrown a GeneralSecurityException");
+        } catch (RuntimeCamelException e) {
+            assertTrue(e.getCause() instanceof IllegalAccessException);
+            // expected
+        }
+
+        mock.assertIsSatisfied();
+    }
+
     public static class MyBaseBusinessException extends Exception {
     }
 
@@ -130,12 +147,12 @@
         return new RouteBuilder() {
             public void configure() throws Exception {
                 // START SNIPPET: exceptionBuilder1
-                exception(NullPointerException.class)
-                    .maximumRedeliveries(1)
+                onException(NullPointerException.class)
+                    .maximumRedeliveries(0)
                     .setHeader(MESSAGE_INFO, constant("Damm a NPE"))
                     .to(ERROR_QUEUE);
 
-                exception(IOException.class)
+                onException(IOException.class)
                     .initialRedeliveryDelay(5000L)
                     .maximumRedeliveries(3)
                     .maximumRedeliveryDelay(30000L)
@@ -144,24 +161,28 @@
                     .setHeader(MESSAGE_INFO, constant("Damm somekind of IO 
exception"))
                     .to(ERROR_QUEUE);
 
-                exception(Exception.class)
+                onException(Exception.class)
                     .initialRedeliveryDelay(1000L)
                     .maximumRedeliveries(2)
                     .setHeader(MESSAGE_INFO, constant("Damm just exception"))
                     .to(ERROR_QUEUE);
-                // END SNIPPET: exceptionBuilder1
 
-                exception(MyBaseBusinessException.class)
+                onException(MyBaseBusinessException.class)
                     .initialRedeliveryDelay(1000L)
                     .maximumRedeliveries(3)
                     .setHeader(MESSAGE_INFO, constant("Damm my business is not 
going to well"))
                     .to(BUSINESS_ERROR_QUEUE);
 
-                
exception(GeneralSecurityException.class).exception(KeyException.class)
+                
onException(GeneralSecurityException.class).onException(KeyException.class)
                     .maximumRedeliveries(1)
                     .setHeader(MESSAGE_INFO, constant("Damm some security 
error"))
                     .to(SECURITY_ERROR_QUEUE);
 
+                onException(InstantiationException.class, 
IllegalAccessException.class, ClassNotFoundException.class)
+                    .maximumRedeliveries(0)
+                    .setHeader(MESSAGE_INFO, constant("Damm some access 
error"))
+                    .to(ERROR_QUEUE);
+                // END SNIPPET: exceptionBuilder1
 
                 from("direct:a").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
@@ -176,6 +197,8 @@
                             throw new MyBusinessException();
                         } else if ("I am not allowed to do this".equals(s)) {
                             throw new KeyManagementException();
+                        } else if ("I am not allowed to access 
this".equals(s)) {
+                            throw new IllegalAccessException();
                         }
                         exchange.getOut().setBody("Hello World");
                     }
@@ -183,7 +206,6 @@
             }
         };
     }
-
 }
 
 


Reply via email to