Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5463511C6A for ; Wed, 2 Apr 2014 10:28:27 +0000 (UTC) Received: (qmail 64218 invoked by uid 500); 2 Apr 2014 10:28:26 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 63971 invoked by uid 500); 2 Apr 2014 10:28:24 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 63959 invoked by uid 99); 2 Apr 2014 10:28:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2014 10:28:21 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of raul@evosent.com designates 209.85.160.53 as permitted sender) Received: from [209.85.160.53] (HELO mail-pb0-f53.google.com) (209.85.160.53) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2014 10:28:16 +0000 Received: by mail-pb0-f53.google.com with SMTP id rp16so11264060pbb.40 for ; Wed, 02 Apr 2014 03:27:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=9vzt2F1cwIzHe3m+XkDVDMsAaFgNSNGn584hlfJFexA=; b=L38qPfYrS4kKYg8hvkzZl3Y1y4MxOylBaWdx9yfWIWAlM59hTWeG6a9EkyDZcJ9Fz0 uC8PZac/RI0mV3uwnxVw9TQ8YwaBHFMmZM5ZBZ5qSwnLI8v2YMZWLyWm4V83RCzlh5ed ZP8cFaQt/KeLZ7QqfzR7aZ5lMNFIcPVwX6vHEkTrTSKMouqAqaFKfpjXh7WP0YuNGrMK nuXdLLrj88RC+CyKRq3zbDxS2EES3HSitkmQyPfX65EHfxfkaFOR1yV8oBdsDohVkLYw n6+XGhmCxg7YGUabbEDfvDozrYf0o9b6ljr511jAVFgtyCLoteAhperP+0HOcF6xIDog nupA== X-Gm-Message-State: ALoCoQnQSRClAL7iPYKpd3XUxEmuw5dqgo7AA5ergDmf0BPZ2U+YMT+1g6db68vDdn4VG/X0mFU/ X-Received: by 10.68.178.162 with SMTP id cz2mr336459pbc.51.1396434473370; Wed, 02 Apr 2014 03:27:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.70.11.133 with HTTP; Wed, 2 Apr 2014 03:27:33 -0700 (PDT) X-Originating-IP: [85.155.61.72] In-Reply-To: References: From: Raul Kripalani Date: Wed, 2 Apr 2014 11:27:33 +0100 Message-ID: Subject: Re: Looking for ideas to reduce code volume and duplication To: "users@camel.apache.org" Content-Type: multipart/alternative; boundary=047d7b86f4e6bcdbe804f60cbcbf X-Virus-Checked: Checked by ClamAV on apache.org --047d7b86f4e6bcdbe804f60cbcbf Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Try this technique. Nothing fancy, just a plain old Java static helper method. It relies on Camel being able to configure exception handlers if placed at the end of the route definition, which I think is possible. Please give it a spin and report back to the community! public class RouteExceptionHandlerEnhancer { public static void enhance(RouteDefinition def) { def.onException(Exception.class).useOriginalMessage().handled(true) // catch exceptions .setHeader(Exchange.FAILURE_ROUTE_ID, property(Exchange.FAILURE_ROUTE_ID)) // set route that errored .setHeader(Exchange.EXCEPTION_CAUGHT, simple("${exception.stacktrace}")) // Store reason for error .to(ExchangePattern.InOnly, endpointAMQ(config. queueCaseAutomationDead())) .end(); } } public class MyRoute extends RouteBuilder() { @Override public void configure() throws Exception { RouteDefinition route =3D from("direct:myendpoint") .log("Hello ${body") .to("activemq:queue:foo"); RouteExceptionHandlerEnhancer.enhance(route); } } Regards, *Ra=FAl Kripalani* Apache Camel PMC Member & Committer | Enterprise Architect, Open Source Integration specialist http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani http://blog.raulkr.net | twitter: @raulvk On Tue, Apr 1, 2014 at 3:51 PM, kraythe . wrote: > Greetings: > > I have dozens of routes currently in our system and they have one of two > variants of the following code: > > .onException(Exception.class).useOriginalMessage().handled(true) = // > catch exceptions > .setHeader(Exchange.FAILURE_ROUTE_ID, property(Exchange.FAILURE_ROUTE_ID)= ) > // set route that errored > .setHeader(Exchange.EXCEPTION_CAUGHT, simple("${exception.stacktrace}")) = // > Store reason for error > .to(ExchangePattern.InOnly, > endpointAMQ(config.queueCaseAutomationDead())).end() // to DLQ > > The problem is I am getting more than annoyed at having to copy paste thi= s > all over the place but since there are a couple of variants, I cant decla= re > a global handler. Making a direct is all well and good but doesnt really > buy me much as I still have half the handler on every route. > > Any ideas how I could reduce code volume here ? > > *Robert Simmons Jr. MSc. - Lead Java Architect @ EA* > *Author of: Hardcore Java (2003) and Maintainable Java (2012)* > *LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39 > * > --047d7b86f4e6bcdbe804f60cbcbf--