Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 77949 invoked from network); 21 Aug 2008 21:53:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Aug 2008 21:53:17 -0000 Received: (qmail 27699 invoked by uid 500); 21 Aug 2008 21:53:15 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 27685 invoked by uid 500); 21 Aug 2008 21:53:15 -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 27676 invoked by uid 99); 21 Aug 2008 21:53:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Aug 2008 14:53:15 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Aug 2008 21:52:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A29F623889A0; Thu, 21 Aug 2008 14:52:56 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r687873 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/processor/HandleFaultProcessor.java test/java/org/apache/camel/processor/FaultRetryRouteTest.java test/java/org/apache/camel/processor/FaultRouteTest.java Date: Thu, 21 Aug 2008 21:52:56 -0000 To: camel-commits@activemq.apache.org From: hadrian@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080821215256.A29F623889A0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hadrian Date: Thu Aug 21 14:52:56 2008 New Revision: 687873 URL: http://svn.apache.org/viewvc?rev=687873&view=rev Log: CAMEL-842. Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java?rev=687873&r1=687872&r2=687873&view=diff ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java (original) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/HandleFaultProcessor.java Thu Aug 21 14:52:56 2008 @@ -29,12 +29,12 @@ if (faultMessage != null) { final Object faultBody = faultMessage.getBody(); if (faultBody != null) { + faultMessage.setBody(null); // Reset it since we are handling it. if (faultBody instanceof Throwable) { exchange.setException((Throwable)faultBody); } else { exchange.setException(new CamelException("Message contains fault of type " - + faultBody.getClass().getName() + ":\n" - + faultBody)); + + faultBody.getClass().getName() + ":\n" + faultBody)); } } } Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java?rev=687873&view=auto ============================================================================== --- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java (added) +++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java Thu Aug 21 14:52:56 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.processor; + +import org.apache.camel.CamelException; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +public class FaultRetryRouteTest extends ContextTestSupport { + protected MockEndpoint a; + protected MockEndpoint b; + protected MockEndpoint error; + protected final Processor successOnRetryProcessor = new Processor() { + int count = 0; + public void process(Exchange exchange) throws CamelException { + if (count++ == 0) { + Message message = exchange.getFault(); + message.setBody(new CamelException("Failed the first time")); + } + } + }; + + public void testSuccessfulRetry() throws Exception { + a.expectedBodiesReceived("in"); + b.expectedBodiesReceived("in"); + error.expectedMessageCount(0); + + template.sendBody("direct:start", "in"); + + MockEndpoint.assertIsSatisfied(a, b, error); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + a = resolveMandatoryEndpoint("mock:a", MockEndpoint.class); + b = resolveMandatoryEndpoint("mock:b", MockEndpoint.class); + error = resolveMandatoryEndpoint("mock:error", MockEndpoint.class); + } + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:start").errorHandler( + deadLetterChannel("mock:error") + .maximumRedeliveries(4) + .loggingLevel(LoggingLevel.DEBUG)) + .to("mock:a").handleFault().process(successOnRetryProcessor).to("mock:b"); + } + }; + } +} \ No newline at end of file Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java?rev=687873&r1=687872&r2=687873&view=diff ============================================================================== --- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java (original) +++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java Thu Aug 21 14:52:56 2008 @@ -115,9 +115,17 @@ assertEquals("Fault message", "It makes no sense of business logic", ((IllegalStateException)(fault.getBody())).getMessage()); } else { // test for the throwFault with String - assertTrue("It should be the CamelException", fault.getBody() instanceof CamelException); - assertEquals("Fault message", "ExceptionMessage", ((CamelException)(fault.getBody())) - .getMessage()); + if (errors == 0) { + // fault *not* handled + assertTrue("It should be the CamelException", fault.getBody() instanceof CamelException); + assertEquals("Fault message", "ExceptionMessage", ((CamelException)(fault.getBody())).getMessage()); + } else { + // fault handled, exception should contain the fault + assertNull("Fault body should be null", fault.getBody()); + CamelException faultex = (CamelException)exchange.getException(); + assertNotNull("Exception body should contain the fault", faultex); + assertEquals("Fault message", "ExceptionMessage", faultex.getMessage()); + } } }