Author: davsclaus Date: Mon Apr 20 08:04:41 2009 New Revision: 766610 URL: http://svn.apache.org/viewvc?rev=766610&view=rev Log: CAMEL-1540: Added handled to the try .. catch DSL. Fixed some other sonartype reportings.
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandledTest.java - copied, changed from r766593, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorOnWhenTest.java camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java (contents, props changed) - copied, changed from r766593, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandleTest.java camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.java - copied, changed from r766593, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.java camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.xml - copied, changed from r766593, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.xml Removed: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandleTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java camel/trunk/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/DefaultParameterMappingStrategy.java Mon Apr 20 08:04:41 2009 @@ -31,15 +31,14 @@ * @version $Revision$ */ public class DefaultParameterMappingStrategy implements ParameterMappingStrategy { - private Map<Class, Expression> parameterTypeToExpressionMap = new ConcurrentHashMap<Class, Expression>(); + private final Map<Class, Expression> parameterTypeToExpressionMap = new ConcurrentHashMap<Class, Expression>(); public DefaultParameterMappingStrategy() { loadDefaultRegistry(); } public Expression getDefaultParameterTypeExpression(Class parameterType) { - Expression expression = parameterTypeToExpressionMap.get(parameterType); - return expression; + return parameterTypeToExpressionMap.get(parameterType); } /** Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Mon Apr 20 08:04:41 2009 @@ -613,8 +613,7 @@ } public TransformerFactory createTransformerFactory() { - TransformerFactory answer = TransformerFactory.newInstance(); - return answer; + return TransformerFactory.newInstance(); } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/CatchDefinition.java Mon Apr 20 08:04:41 2009 @@ -26,12 +26,15 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.apache.camel.Expression; import org.apache.camel.Predicate; import org.apache.camel.Processor; +import org.apache.camel.builder.ExpressionBuilder; import org.apache.camel.builder.ExpressionClause; import org.apache.camel.processor.CatchProcessor; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.ObjectHelper; +import static org.apache.camel.builder.PredicateBuilder.toPredicate; /** * Represents an XML <catch/> element @@ -45,10 +48,14 @@ private List<String> exceptions = new ArrayList<String>(); @XmlElement(name = "onWhen", required = false) private WhenDefinition onWhen; + @XmlElement(name = "handled", required = false) + private ExpressionSubElementDefinition handled; @XmlElementRef private List<ProcessorDefinition> outputs = new ArrayList<ProcessorDefinition>(); @XmlTransient private List<Class> exceptionClasses; + @XmlTransient + private Predicate handledPolicy; public CatchDefinition() { } @@ -86,7 +93,12 @@ when = onWhen.getExpression().createPredicate(routeContext); } - return new CatchProcessor(getExceptionClasses(), childProcessor, when); + Predicate handle = handledPolicy; + if (handled != null) { + handle = handled.createPredicate(routeContext); + } + + return new CatchProcessor(getExceptionClasses(), childProcessor, when, handle); } public List<ProcessorDefinition> getOutputs() { @@ -152,6 +164,39 @@ } /** + * Sets whether the exchange should be marked as handled or not. + * + * @param handled handled or not + * @return the builder + */ + public CatchDefinition handled(boolean handled) { + Expression expression = ExpressionBuilder.constantExpression(Boolean.toString(handled)); + return handled(expression); + } + + /** + * Sets whether the exchange should be marked as handled or not. + * + * @param handled predicate that determines true or false + * @return the builder + */ + public CatchDefinition handled(Predicate handled) { + setHandledPolicy(handled); + return this; + } + + /** + * Sets whether the exchange should be marked as handled or not. + * + * @param handled expression that determines true or false + * @return the builder + */ + public CatchDefinition handled(Expression handled) { + setHandledPolicy(toPredicate(handled)); + return this; + } + + /** * Sets the exception class that the CatchType want to catch * * @param exception the exception of class @@ -179,6 +224,14 @@ this.onWhen = onWhen; } + public Predicate getHandledPolicy() { + return handledPolicy; + } + + public void setHandledPolicy(Predicate handledPolicy) { + this.handledPolicy = handledPolicy; + } + protected List<Class> createExceptionClasses() { List<String> list = getExceptions(); List<Class> answer = new ArrayList<Class>(list.size()); Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java Mon Apr 20 08:04:41 2009 @@ -136,7 +136,18 @@ @Override public CatchProcessor createProcessor(RouteContext routeContext) throws Exception { Processor childProcessor = routeContext.createProcessor(this); - return new CatchProcessor(getExceptionClasses(), childProcessor, null); + + Predicate when = null; + if (onWhen != null) { + when = onWhen.getExpression().createPredicate(routeContext); + } + + Predicate handle = null; + if (handled != null) { + handle = handled.createPredicate(routeContext); + } + + return new CatchProcessor(getExceptionClasses(), childProcessor, when, handle); } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/TryDefinition.java Mon Apr 20 08:04:41 2009 @@ -26,13 +26,16 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.apache.camel.Expression; import org.apache.camel.Predicate; import org.apache.camel.Processor; +import org.apache.camel.builder.ExpressionBuilder; import org.apache.camel.builder.ExpressionClause; import org.apache.camel.processor.CatchProcessor; import org.apache.camel.processor.TryProcessor; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.ProcessorDefinitionHelper; +import static org.apache.camel.builder.PredicateBuilder.toPredicate; /** * Represents an XML <try/> element @@ -108,6 +111,8 @@ * @return the builder */ public TryDefinition onWhen(Predicate predicate) { + // we must use a delegate so we can use the fluent builder based on TryDefinition + // to configure all with try .. catch .. finally // set the onWhen predicate on all the catch definitions Iterator<CatchDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(getOutputs(), CatchDefinition.class); while (it.hasNext()) { @@ -127,6 +132,8 @@ * @return the expression clause to configure */ public ExpressionClause<TryDefinition> onWhen() { + // we must use a delegate so we can use the fluent builder based on TryDefinition + // to configure all with try .. catch .. finally WhenDefinition answer = new WhenDefinition(); // set the onWhen definition on all the catch definitions Iterator<CatchDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(getOutputs(), CatchDefinition.class); @@ -141,6 +148,45 @@ } /** + * Sets whether the exchange should be marked as handled or not. + * + * @param handled handled or not + * @return the builder + */ + public TryDefinition handled(boolean handled) { + Expression expression = ExpressionBuilder.constantExpression(Boolean.toString(handled)); + return handled(expression); + } + + /** + * Sets whether the exchange should be marked as handled or not. + * + * @param handled predicate that determines true or false + * @return the builder + */ + public TryDefinition handled(Predicate handled) { + // we must use a delegate so we can use the fluent builder based on TryDefinition + // to configure all with try .. catch .. finally + // set the handled on all the catch definitions + Iterator<CatchDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(getOutputs(), CatchDefinition.class); + while (it.hasNext()) { + CatchDefinition doCatch = it.next(); + doCatch.setHandledPolicy(handled); + } + return this; + } + + /** + * Sets whether the exchange should be marked as handled or not. + * + * @param handled expression that determines true or false + * @return the builder + */ + public TryDefinition handled(Expression handled) { + return handled(toPredicate(handled)); + } + + /** * The finally block for a given handle * * @return the try builder Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/CatchProcessor.java Mon Apr 20 08:04:41 2009 @@ -32,11 +32,13 @@ public class CatchProcessor extends DelegateProcessor { private final List<Class> exceptions; private final Predicate onWhen; + private final Predicate handled; - public CatchProcessor(List<Class> exceptions, Processor processor, Predicate onWhen) { + public CatchProcessor(List<Class> exceptions, Processor processor, Predicate onWhen, Predicate handled) { super(processor); this.exceptions = exceptions; this.onWhen = onWhen; + this.handled = handled; } @Override @@ -44,6 +46,13 @@ return "Catch[" + exceptions + " -> " + getProcessor() + "]"; } + /** + * Whether this catch processor catch the given thrown exception + * + * @param exchange the current exchange + * @param exception the thrown exception + * @return <tt>true</tt> if this processor catches it, <tt>false</tt> otherwise. + */ public boolean catches(Exchange exchange, Throwable exception) { // use the exception iterator to walk the caused by hierachy Iterator<Throwable> it = ObjectHelper.createExceptionIterator(exception); @@ -61,6 +70,22 @@ return false; } + + /** + * Whether this catch processor handles the exception it have caught + * + * @param exchange the current exchange + * @return <tt>true</tt> if this processor handles it, <tt>false</tt> otherwise. + */ + public boolean handles(Exchange exchange) { + if (handled == null) { + // handle by default + return true; + } + + return handled.matches(exchange); + } + public List<Class> getExceptions() { return exceptions; } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java Mon Apr 20 08:04:41 2009 @@ -89,8 +89,8 @@ protected void handleException(Exchange exchange, Throwable e) throws Exception { for (CatchProcessor catchClause : catchClauses) { if (catchClause.catches(exchange, e)) { - if (LOG.isDebugEnabled()) { - LOG.debug("This TryProcessor handles the exception: " + e.getClass().getName() + " caused by: " + e.getMessage()); + if (LOG.isTraceEnabled()) { + LOG.trace("This TryProcessor catches the exception: " + e.getClass().getName() + " caused by: " + e.getMessage()); } // lets attach the exception to the exchange @@ -102,13 +102,31 @@ // do not catch any exception here, let it propagate up catchClause.process(localExchange); - localExchange.removeProperty(Exchange.EXCEPTION_CAUGHT); + + boolean handled = catchClause.handles(exchange); + + if (LOG.isDebugEnabled()) { + LOG.debug("The exception is handled: " + handled + " for the exception: " + e.getClass().getName() + + " caused by: " + e.getMessage()); + } + + if (handled) { + localExchange.removeProperty(Exchange.EXCEPTION_CAUGHT); + } else { + // put exception back as it was not handled + if (localExchange.getException() == null) { + localExchange.setException(localExchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class)); + } + } + + // copy result back to the original exchange ExchangeHelper.copyResults(exchange, localExchange); return; } } - if (LOG.isDebugEnabled()) { - LOG.debug("This TryProcessor does not handle the exception: " + e.getClass().getName() + " caused by: " + e.getMessage()); + + if (LOG.isTraceEnabled()) { + LOG.trace("This TryProcessor does not catch the exception: " + e.getClass().getName() + " caused by: " + e.getMessage()); } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/exceptionpolicy/DefaultExceptionPolicyStrategy.java Mon Apr 20 08:04:41 2009 @@ -54,8 +54,8 @@ private static final transient Log LOG = LogFactory.getLog(DefaultExceptionPolicyStrategy.class); - public OnExceptionDefinition getExceptionPolicy(Map<ExceptionPolicyKey, OnExceptionDefinition> exceptionPolicices, Exchange exchange, - Throwable exception) { + public OnExceptionDefinition getExceptionPolicy(Map<ExceptionPolicyKey, OnExceptionDefinition> exceptionPolicices, + Exchange exchange, Throwable exception) { // recursive up the tree using the iterator Iterator<Throwable> it = createExceptionIterator(exception); @@ -71,8 +71,8 @@ } - private OnExceptionDefinition findMatchedExceptionPolicy(Map<ExceptionPolicyKey, OnExceptionDefinition> exceptionPolicices, Exchange exchange, - Throwable exception) { + private OnExceptionDefinition findMatchedExceptionPolicy(Map<ExceptionPolicyKey, OnExceptionDefinition> exceptionPolicices, + Exchange exchange, Throwable exception) { if (LOG.isTraceEnabled()) { LOG.trace("Finding best suited exception policy for thrown exception " + exception.getClass().getName()); } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java Mon Apr 20 08:04:41 2009 @@ -16,7 +16,6 @@ */ package org.apache.camel.util.jndi; - import java.util.Hashtable; import javax.naming.Context; @@ -41,9 +40,10 @@ public Context getInitialContext(Hashtable environment) throws NamingException { try { return new JndiContext(environment); - } catch (NamingException e) { - throw e; } catch (Exception e) { + if (e instanceof NamingException) { + throw (NamingException) e; + } NamingException exception = new NamingException(e.getMessage()); exception.initCause(e); throw exception; Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java?rev=766610&r1=766609&r2=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/view/ModelFileGenerator.java Mon Apr 20 08:04:41 2009 @@ -94,7 +94,7 @@ private XmlConverter converter() { XmlConverter converter = new XmlConverter(); TransformerFactory transformerFactory = converter.getTransformerFactory(); - transformerFactory.setAttribute("indent-number", new Integer(2)); + transformerFactory.setAttribute("indent-number", 2); return converter; } Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandledTest.java (from r766593, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorOnWhenTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandledTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandledTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorOnWhenTest.java&r1=766593&r2=766610&rev=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorOnWhenTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandledTest.java Mon Apr 20 08:04:41 2009 @@ -18,7 +18,6 @@ import java.io.IOException; -import org.apache.camel.CamelExchangeException; import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.Processor; @@ -26,70 +25,43 @@ import org.apache.camel.builder.RouteBuilder; /** - * Unit test for try .. handle with onWhen. + * Unit test for try .. catch with handled false. */ -public class TryProcessorOnWhenTest extends ContextTestSupport { +public class TryProcessorHandledTest extends ContextTestSupport { - public void testIOException() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:catch").expectedMessageCount(1); - getMockEndpoint("mock:catchCamel").expectedMessageCount(0); - getMockEndpoint("mock:finally").expectedMessageCount(1); + public void testOk() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:error").expectedMessageCount(0); - template.sendBody("direct:start", "Damn IO"); + sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); } public void testIllegalStateException() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:catch").expectedMessageCount(1); - getMockEndpoint("mock:catchCamel").expectedMessageCount(0); - getMockEndpoint("mock:finally").expectedMessageCount(1); + getMockEndpoint("mock:error").expectedMessageCount(1); template.sendBody("direct:start", "Damn State"); assertMockEndpointsSatisfied(); } - public void testCamelException() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:catch").expectedMessageCount(0); - getMockEndpoint("mock:catchCamel").expectedMessageCount(1); - getMockEndpoint("mock:finally").expectedMessageCount(1); - - template.sendBody("direct:start", "Camel"); - - assertMockEndpointsSatisfied(); - } - - public void testOtherBug() throws Exception { + public void testIOException() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(0); - getMockEndpoint("mock:catch").expectedMessageCount(0); - getMockEndpoint("mock:catchCamel").expectedMessageCount(0); - getMockEndpoint("mock:finally").expectedMessageCount(1); + getMockEndpoint("mock:io").expectedMessageCount(1); try { - template.sendBody("direct:start", "Other Bug"); + template.sendBody("direct:start", "Damn IO"); fail("Should have thrown a RuntimeCamelException"); } catch (RuntimeCamelException e) { - assertIsInstanceOf(IllegalStateException.class, e.getCause()); - assertEquals("Other Bug", e.getCause().getMessage()); + assertIsInstanceOf(IOException.class, e.getCause()); + assertEquals("Damn IO", e.getCause().getMessage()); } assertMockEndpointsSatisfied(); } - public void testOk() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(1); - getMockEndpoint("mock:catch").expectedMessageCount(0); - getMockEndpoint("mock:finally").expectedMessageCount(1); - - sendBody("direct:start", "Hello World"); - - assertMockEndpointsSatisfied(); - } - protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { @@ -100,18 +72,15 @@ .doTry() .process(new ProcessorFail()) .to("mock:result") - // here we catch the following 2 exceptions but only if - // the onWhen predicate matches, eg if the exception messsage - // conatins the string word Damn - .doCatch(IOException.class, IllegalStateException.class) - .onWhen(exceptionMessage().contains("Damn")) - .to("mock:catch") - // another catch for CamelExchangeException that does not have any onWhen predicate - .doCatch(CamelExchangeException.class) - .to("mock:catchCamel") - // and the finally that is always processed - .doFinally() - .to("mock:finally") + // catch IOExcption that we do not want to handle, eg the caller should get the error back + .doCatch(IOException.class) + // mark this as NOT handled, eg the caller will also get the exception + .handled(false) + .to("mock:io") + .doCatch(Exception.class) + // and catch all other exceptions + // they are handled by default (ie handled = true) + .to("mock:error") // here the try block ends .end(); // END SNIPPET: e1 @@ -126,10 +95,6 @@ throw new IOException("Damn IO"); } else if ("Damn State".equals(body)) { throw new IllegalStateException("Damn State"); - } else if ("Other Bug".equals(body)) { - throw new IllegalStateException("Other Bug"); - } else if ("Camel".equals(body)) { - throw new CamelExchangeException("Sorry old Camel", exchange); } } } Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java (from r766593, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandleTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandleTest.java&r1=766593&r2=766610&rev=766610&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorHandleTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java Mon Apr 20 08:04:41 2009 @@ -25,7 +25,7 @@ /** * Unit test for try .. handle routing (CAMEL-564). */ -public class TryProcessorHandleTest extends ContextTestSupport { +public class TryProcessorTest extends ContextTestSupport { private boolean handled; Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TryProcessorTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.java (from r766593, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.java&r1=766593&r2=766610&rev=766610&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.java (original) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.java Mon Apr 20 08:04:41 2009 @@ -17,13 +17,13 @@ package org.apache.camel.spring.processor; import org.apache.camel.CamelContext; -import org.apache.camel.processor.TryProcessorOnWhenTest; +import org.apache.camel.processor.TryProcessorHandledTest; import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; -public class SpringTryProcessorOnWhenTest extends TryProcessorOnWhenTest { +public class SpringTryProcessorHandledTest extends TryProcessorHandledTest { protected CamelContext createCamelContext() throws Exception { - return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.xml"); + return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringTryProcessorHandledTest.xml"); } } \ No newline at end of file Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.xml (from r766593, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.xml) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.xml&r1=766593&r2=766610&rev=766610&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorOnWhenTest.xml (original) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTryProcessorHandledTest.xml Mon Apr 20 08:04:41 2009 @@ -30,30 +30,25 @@ <doTry> <process ref="processorFail"/> <to uri="mock:result"/> - <!-- here we catch the below 2 kind of exceptions but ONLY if the onWhen predicate matches - that means that the exception message should contain the string word 'Damn' --> <doCatch> + <!-- catch IOExcption that we do not want to handle, eg the caller should get the error back --> <exception>java.io.IOException</exception> - <exception>java.lang.IllegalStateException</exception> - <onWhen> - <simple>${exception.message} contains 'Damn'</simple> - </onWhen> - <to uri="mock:catch"/> + <!-- mark this as NOT handled, eg the caller will also get the exception --> + <handled> + <constant>false</constant> + </handled> + <to uri="mock:io"/> </doCatch> - <!-- we can have multiple catch blocks for different exception and with their own onWhen --> <doCatch> - <exception>org.apache.camel.CamelExchangeException</exception> - <to uri="mock:catchCamel"/> + <!-- and catch all other exceptions they are handled by default (ie handled = true) --> + <exception>java.lang.Exception</exception> + <to uri="mock:error"/> </doCatch> - <!-- the finally is always processed --> - <doFinally> - <to uri="mock:finally"/> - </doFinally> </doTry> </route> <!-- END SNIPPET: e1 --> </camelContext> - <bean id="processorFail" class="org.apache.camel.processor.TryProcessorOnWhenTest$ProcessorFail"/> + <bean id="processorFail" class="org.apache.camel.processor.TryProcessorHandledTest$ProcessorFail"/> </beans>