Author: davsclaus
Date: Thu Dec 4 05:38:05 2008
New Revision: 723319
URL: http://svn.apache.org/viewvc?rev=723319&view=rev
Log:
Merged revisions 723314 via svnmerge from
https://svn.apache.org/repos/asf/activemq/camel/trunk
........
r723314 | davsclaus | 2008-12-04 14:27:12 +0100 (to, 04 dec 2008) | 1 line
CAMEL-1144: DefaultExceptionPolicyStrategy now tests caused by exceptions
(using bottom to top exception hieracy iterator)
........
Modified:
activemq/camel/branches/camel-1.x/ (props changed)
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaInOutRouteTextLineDelimiterTest.java
(props changed)
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaNoResponseFromServerTest.java
(props changed)
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpLineDelimiterUsingPlainSocketTest.java
(props changed)
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTextlineDelimiterTest.java
(props changed)
Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 4 05:38:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264
+/activemq/camel/trunk:709850,711200,711206,711219-711220,711523,711531,711756,711784,711859,711874,711962,711971,712064,712119,712148,712662,712692,712925,713013,713107,713136,713273,713290,713292,713295,713314,713475,713625,713932,713944,714032,717965,717989,718242,718273,718312-718515,719163-719184,719334,719339,719524,719662,719848,719851,719855,719864,719978-719979,720207,720435-720437,720806,721272,721331,721333-721334,721360,721669,721764,721813,721985,722005,722070,722110,722415,722438,722726,722845,722878,723264,723314
Propchange: activemq/camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java
URL:
http://svn.apache.org/viewvc/activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java?rev=723319&r1=723318&r2=723319&view=diff
==============================================================================
---
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java
(original)
+++
activemq/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java
Thu Dec 4 05:38:05 2008
@@ -16,6 +16,10 @@
*/
package org.apache.camel.processor.exceptionpolicy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,11 +35,13 @@
* <b>Selection strategy:</b>
* <br/>This strategy applies the following rules:
* <ul>
- * <li>The exception type must be configured with an Exception that is an
instance of the thrown exception, this
- * is tested using the [EMAIL PROTECTED]
#filter(org.apache.camel.model.ExceptionType, Class, Throwable)} method. </li>
- * <li>If the exception type has exactly the thrown exception then its
selected as its an exact match</li>
- * <li>Otherwise the type that has an exception that is the closests super
of the thrown exception is selected
- * (recurring up the exception hierarchy)</li>
+ * <li>Will walk the exception hieracy from bottom upwards till the thrown
exception, meaning that the most outer caused
+ * by is selected first, ending with the thrown exception itself</li>
+ * <li>The exception type must be configured with an Exception that is an
instance of the thrown exception, this
+ * is tested using the [EMAIL PROTECTED]
#filter(org.apache.camel.model.ExceptionType, Class, Throwable)} method. </li>
+ * <li>If the exception type has exactly the thrown exception then its
selected as its an exact match</li>
+ * <li>Otherwise the type that has an exception that is the closests super of
the thrown exception is selected
+ * (recurring up the exception hierarchy)</li>
* </ul>
* <p/>
* <b>Fine grained matching:</b>
@@ -50,6 +56,22 @@
public ExceptionType getExceptionPolicy(Map<ExceptionPolicyKey,
ExceptionType> exceptionPolicices, Exchange exchange,
Throwable exception) {
+
+ // recursive up the tree using the iterator
+ Iterator<Throwable> it = new ExceptionIterator(exception);
+ while (it.hasNext()) {
+ ExceptionType type = doGetExceptionPolicy(exceptionPolicices,
exchange, it.next());
+ if (type != null) {
+ return type;
+ }
+ }
+
+ // no type found
+ return null;
+ }
+
+ private ExceptionType doGetExceptionPolicy(Map<ExceptionPolicyKey,
ExceptionType> exceptionPolicices, Exchange exchange,
+ Throwable exception) {
if (LOG.isDebugEnabled()) {
LOG.debug("Finding best suited exception policy for thrown
exception " + exception.getClass().getName());
}
@@ -109,10 +131,10 @@
/**
* Strategy to filter the given type exception class with the thrown
exception
*
- * @param type the exception type
- * @param exceptionClass the current exception class for testing
- * @param exception the thrown exception
- * @return <tt>true</tt> if the to current exception class is a candidate,
<tt>false</tt> to skip it.
+ * @param type the exception type
+ * @param exceptionClass the current exception class for testing
+ * @param exception the thrown exception
+ * @return <tt>true</tt> if the to current exception class is a candidate,
<tt>false</tt> to skip it.
*/
protected boolean filter(ExceptionType type, Class exceptionClass,
Throwable exception) {
// must be instance of check to ensure that the exceptionClass is one
type of the thrown exception
@@ -124,12 +146,12 @@
* <p/>
* This default implementation will match as:
* <ul>
- * <li>Always true if no when predicate on the exception type
- * <li>Otherwise the when predicate is matches against the current
exchange
+ * <li>Always true if no when predicate on the exception type
+ * <li>Otherwise the when predicate is matches against the current exchange
* </ul>
*
- * @param type the exception type
- * @param exchange the current [EMAIL PROTECTED] Exchange}
+ * @param type the exception type
+ * @param exchange the current [EMAIL PROTECTED] Exchange}
* @return <tt>true</tt> if matched, <tt>false</tt> otherwise.
*/
protected boolean matchesWhen(ExceptionType type, Exchange exchange) {
@@ -147,4 +169,40 @@
return 1 + getInheritanceLevel(clazz.getSuperclass());
}
+ /**
+ * Iterator that walks the exception hieracy in the order we should match.
+ * <p/>
+ * Will default walk from bottom upwards to the root exception
+ */
+ protected class ExceptionIterator implements Iterator<Throwable> {
+ private List<Throwable> tree = new ArrayList<Throwable>();
+ private Iterator<Throwable> it;
+
+ public ExceptionIterator(Throwable exception) {
+ Throwable current = exception;
+ // spool to the bottom of the caused by tree
+ while (current != null) {
+ tree.add(current);
+ current = current.getCause();
+ }
+
+ // reverse tree so we go from bottom to top
+ Collections.reverse(tree);
+ it = tree.iterator();
+ }
+
+ public boolean hasNext() {
+ return it.hasNext();
+ }
+
+ public Throwable next() {
+ return it.next();
+ }
+
+ public void remove() {
+ it.remove();
+ }
+ }
+
+
}
Propchange:
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaInOutRouteTextLineDelimiterTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 4 05:38:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaInOutRouteTextLineDelimiterTest.java:722878,723264
+/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaInOutRouteTextLineDelimiterTest.java:722878,723264,723314
Propchange:
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaNoResponseFromServerTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 4 05:38:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaNoResponseFromServerTest.java:723264
+/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaNoResponseFromServerTest.java:723264,723314
Propchange:
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpLineDelimiterUsingPlainSocketTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 4 05:38:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpLineDelimiterUsingPlainSocketTest.java:722878,723264
+/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpLineDelimiterUsingPlainSocketTest.java:722878,723264,723314
Propchange:
activemq/camel/branches/camel-1.x/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTextlineDelimiterTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 4 05:38:05 2008
@@ -1 +1 @@
-/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTextlineDelimiterTest.java:722878,723264
+/activemq/camel/trunk/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaTcpTextlineDelimiterTest.java:722878,723264,723314