Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 25843 invoked from network); 10 Feb 2009 12:43:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Feb 2009 12:43:19 -0000 Received: (qmail 25221 invoked by uid 500); 10 Feb 2009 12:43:18 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 25201 invoked by uid 500); 10 Feb 2009 12:43:18 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 25192 invoked by uid 99); 10 Feb 2009 12:43:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Feb 2009 04:43:18 -0800 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; Tue, 10 Feb 2009 12:43:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7B2552388A50; Tue, 10 Feb 2009 12:42:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r742953 - /camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java Date: Tue, 10 Feb 2009 12:42:51 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090210124257.7B2552388A50@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davsclaus Date: Tue Feb 10 12:42:42 2009 New Revision: 742953 URL: http://svn.apache.org/viewvc?rev=742953&view=rev Log: CAMEL-699: Added example for traceable unit of work Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java (contents, props changed) - copied, changed from r742867, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java (from r742867, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java&r1=742867&r2=742953&rev=742953&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java Tue Feb 10 12:42:42 2009 @@ -16,46 +16,80 @@ */ package org.apache.camel.processor; +import java.util.List; + import org.apache.camel.ContextTestSupport; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.model.ProcessorType; import org.apache.camel.processor.interceptor.Tracer; +import org.apache.camel.spi.TraceableUnitOfWork; /** * @version $Revision$ */ -public class TraceInterceptorTest extends ContextTestSupport { +public class TraceableUnitOfWorkTest extends ContextTestSupport { - // START SNIPPET: e1 public void testSendingSomeMessages() throws Exception { - template.sendBodyAndHeader("direct:start", "Hello London", "to", "James"); - template.sendBodyAndHeader("direct:start", "This is Copenhagen calling", "from", "Claus"); + Object out = template.requestBody("direct:start", "Hello London"); + assertEquals("Failed at: bean:bar", out); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("foo", new MyFooBean()); + jndi.bind("bar", new MyBarBean()); + return jndi; } + // START SNIPPET: e1 protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - // add tracer as an interceptor so it will log the exchange executions at runtime - // this can aid us to understand/see how the exchanges is routed etc. - getContext().addInterceptStrategy(new Tracer()); - - from("direct:start"). - process(new Processor() { - public void process(Exchange exchange) throws Exception { - // do nothing - } - - @Override - public String toString() { - return "MyProcessor"; - } - }). - to("mock:a"). - to("mock:b"); + // must enable tracer to trace the route path taken during runtime + context.addInterceptStrategy(new Tracer()); + + // let our my error processor handle all exceptions + onException(Exception.class).handled(true).process(new MyErrorProcessor()); + + // our route where an exception can be thrown from either foo or bar bean + // so we have enable tracing so we can check it at runtime to get the actual + // node path taken + from("direct:start").to("bean:foo").to("bean:bar"); } }; } // END SNIPPET: e1 -} + // START SNIPPET: e2 + private class MyErrorProcessor implements Processor { + public void process(Exchange exchange) throws Exception { + // cast to TraceableUnitOfWork so we can work on the intercepted node path + TraceableUnitOfWork tuow = (TraceableUnitOfWork) exchange.getUnitOfWork(); + + // get the list of intercepted nodes + List list = tuow.getInterceptedNodes(); + // get the 2nd last as the last is me (MyErrorProcessor) + ProcessorType last = list.get(list.size() - 2); + + // set error message + exchange.getFault().setBody("Failed at: " + last.getLabel()); + } + } + // END SNIPPET: e2 + + public class MyFooBean { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody("Foo okay"); + } + } + + public class MyBarBean { + public void process(Exchange exchange) throws Exception { + throw new IllegalArgumentException("Damm Bar"); + } + } +} \ No newline at end of file Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java ------------------------------------------------------------------------------ svn:mergeinfo =