Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 62825 invoked from network); 1 Oct 2007 14:11:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Oct 2007 14:11:53 -0000 Received: (qmail 26233 invoked by uid 500); 1 Oct 2007 14:11:43 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 26219 invoked by uid 500); 1 Oct 2007 14:11:43 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 26210 invoked by uid 99); 1 Oct 2007 14:11:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Oct 2007 07:11:43 -0700 X-ASF-Spam-Status: No, hits=-98.8 required=10.0 tests=ALL_TRUSTED,DNS_FROM_DOB,RCVD_IN_DOB X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Oct 2007 14:11:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5120F1A9832; Mon, 1 Oct 2007 07:11:02 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r580969 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/processor/ test/java/org/apache/camel/processor/ Date: Mon, 01 Oct 2007 14:11:01 -0000 To: camel-commits@activemq.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071001141102.5120F1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jstrachan Date: Mon Oct 1 07:11:00 2007 New Revision: 580969 URL: http://svn.apache.org/viewvc?rev=580969&view=rev Log: applied patch from Nicky Sandhu for https://issues.apache.org/activemq/browse/CAMEL-160 Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllNoCatchTest.java (with props) activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllTest.java (with props) Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?rev=580969&r1=580968&r2=580969&view=diff ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java (original) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java Mon Oct 1 07:11:00 2007 @@ -35,7 +35,9 @@ private static final Log LOG = LogFactory.getLog(TryProcessor.class); private final Processor tryProcessor; + private final List catchClauses; + private final Processor finallyProcessor; public TryProcessor(Processor tryProcessor, List catchClauses, Processor finallyProcessor) { @@ -54,7 +56,7 @@ try { tryProcessor.process(exchange); e = exchange.getException(); - + // Ignore it if it was handled by the dead letter channel. if (e != null && DeadLetterChannel.isFailureHandled(exchange)) { e = null; @@ -63,7 +65,7 @@ e = ex; exchange.setException(e); } - + if (e != null) { try { DeadLetterChannel.setFailureHandled(exchange, true); @@ -72,13 +74,23 @@ throw ex; } catch (Throwable ex) { throw new RuntimeCamelException(ex); + } finally { + handleAll(exchange); } + } else { + handleAll(exchange); } - - try { - finallyProcessor.process(exchange); - } catch (Exception e2) { - LOG.warn("Caught exception in finally block while handling other exception: " + e2, e2); + + } + + private void handleAll(Exchange exchange) { + if (finallyProcessor != null) { + DeadLetterChannel.setFailureHandled(exchange, true); + try { + finallyProcessor.process(exchange); + } catch (Exception e2) { + LOG.warn("Caught exception in finally block while handling other exception: " + e2, e2); + } } } @@ -106,6 +118,8 @@ } // unhandled exception - throw e; + if (finallyProcessor == null) { + throw e; + } } } Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllNoCatchTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllNoCatchTest.java?rev=580969&view=auto ============================================================================== --- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllNoCatchTest.java (added) +++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllNoCatchTest.java Mon Oct 1 07:11:00 2007 @@ -0,0 +1,58 @@ +/** + * + */ +package org.apache.camel.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.TryType; + +/** + * No catch blocks but handle all should work + * + * @author nsandhu + */ +public class ValidationHandleAllNoCatchTest extends ContextTestSupport { + protected Processor validator = new MyValidator(); + protected MockEndpoint validEndpoint; + protected MockEndpoint allEndpoint; + + public void testValidMessage() throws Exception { + validEndpoint.expectedMessageCount(1); + allEndpoint.expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "", "foo", "bar"); + + MockEndpoint.assertIsSatisfied(validEndpoint, allEndpoint); + } + + public void testInvalidMessage() throws Exception { + validEndpoint.expectedMessageCount(0); + allEndpoint.expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "", "foo", "notMatchedHeaderValue"); + + MockEndpoint.assertIsSatisfied(validEndpoint, allEndpoint); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class); + allEndpoint = resolveMandatoryEndpoint("mock:all", MockEndpoint.class); + } + + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + TryType tryType = from("direct:start").tryBlock(). + process(validator). + to("mock:valid"); + tryType.handleAll().to("mock:all"); + } + }; + } +} Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllNoCatchTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllTest.java?rev=580969&view=auto ============================================================================== --- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllTest.java (added) +++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllTest.java Mon Oct 1 07:11:00 2007 @@ -0,0 +1,64 @@ +/** + * + */ +package org.apache.camel.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Processor; +import org.apache.camel.ValidationException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.TryType; + +/** + * Test handleAll + * + * @author nsandhu + */ +public class ValidationHandleAllTest extends ContextTestSupport { + protected Processor validator = new MyValidator(); + protected MockEndpoint validEndpoint; + protected MockEndpoint invalidEndpoint; + protected MockEndpoint allEndpoint; + + public void testValidMessage() throws Exception { + validEndpoint.expectedMessageCount(1); + invalidEndpoint.expectedMessageCount(0); + allEndpoint.expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "", "foo", "bar"); + + MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, allEndpoint); + } + + public void testInvalidMessage() throws Exception { + invalidEndpoint.expectedMessageCount(1); + validEndpoint.expectedMessageCount(0); + allEndpoint.expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "", "foo", "notMatchedHeaderValue"); + + MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, allEndpoint); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class); + invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class); + allEndpoint = resolveMandatoryEndpoint("mock:all", MockEndpoint.class); + } + + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + TryType tryType = from("direct:start").tryBlock(). + process(validator). + to("mock:valid"); + tryType.handle(ValidationException.class).to("mock:invalid"); + tryType.handleAll().to("mock:all"); + } + }; + } +} Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationHandleAllTest.java ------------------------------------------------------------------------------ svn:eol-style = native