Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:17:46+00:00 2026-05-30T02:17:46+00:00

I am trying to build a application with several camel routes which re use

  • 0

I am trying to build a application with several camel routes which re use many common routes internally.
Hence, I am trying to segregate the routes in several different Route Builder classes and then connecting the routes where needed.

For eg, all routes pertaining to sending emails go into a EmailRouteBuilder class and all routes dealing with a particular JMS Queue go into MyQueueRouteBuilder class.
I suppose this should be alright since Camel doesnt not distinguish between classes and only looks for routes defininition.

In addition, I am also grouping several exception handling routes into a separate ExceptionHandlingRouteBuilder.

I am also connecting all the different classes together by defining the camel context in Spring like so –

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder id="properties" location="classpath:${env}/autoimport.properties"/>
    <!-- Common Routes -->
    <routeBuilder ref="emailRouteBuilder" />
    <routeBuilder ref="myQueueRouteBuilder" />
  <routeBuilder ref="httpRouteBuilder" />
    <routeBuilder ref="exceptionsRouteBuilder" />
    <routeBuilder ref="customer1RouteBuilder" />
    <routeBuilder ref="customer2RouteBuilder" />

</camelContext>

My exceptionsRouteBuilder contains many exception clauses like –

onException(ConnectException.class)
            .routeId("connectExceptionEP")
            .handled(true)
            .log("Caught Exception: ")
            .to("direct:gracefulExit");

..
..
..

However, it looks like there is a problem with the exceptions being defined in another class, or for that matter, defined separately out of the main route definition.

I verified this in the logs by looking for the routes being booted ( by routeId ) and also checking when an exception is thrown.

Additionally, to further confirm, I took the http Connect Exception handling route and put that directly in the httpRouteBuilder and lo..! , the exception handling now kicks in just fine for this exception..

Am I missing something here to get all exceptions to work while being nicely defined in its own class. ?

I am using Apache Camel 2.9.0 , but I verified the same behavior also in 2.8.3.

Thanks,
Anand

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:17:48+00:00Added an answer on May 30, 2026 at 2:17 am

    correct, the onException() clauses only apply to the current RouteBuilder’s route definitions…

    that said, you can reuse these definitions by having all your RouteBuilders extend the ExceptionRouteBuilder and call super.configure()…something like this

    public class MyRouteBuilder extends ExceptionRouteBuilder {
        @Override
        public void configure() throws Exception {
            super.configure();
            from("direct:start").throwException(new Exception("error"));
        }
    }
    ...
    public class ExceptionRouteBuilder implements RouteBuilder {
        @Override
        public void configure() throws Exception {
            onException(Exception.class).handled(true).to("mock:error");
        }
    }
    

    or even just have a static method in an ExceptionBuilder class to setup the clauses for a given RouteBuilder instance

    public class MyRouteBuilder extends RouteBuilder {
        @Override
        public void configure() throws Exception {
            ExceptionBuilder.setup(this);
            from("direct:start").throwException(new Exception("error"));
        }
    }
    ...
    public class ExceptionBuilder {
        public static void setup(RouteBuilder routeBuilder) {
            routeBuilder.onException(Exception.class).handled(true).to("mock:error");
        }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a application that has different kinds of users, I'm using
im trying to build an application like a book, with so many custom views
I am trying to build an application to simulate some basic spheres moving around.
I'm trying to build an application starting from an Appfuse Archetype, but I get
I'm trying to build an application from source in windows that requires some Unix
I'm trying to build an application that builds a resource file into a jar,
I'm trying to build my application for GoogleAppEngine using maven. I've added the following
I'm currently trying to build an application that inherently needs good time synchronization across
Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I am trying to build an Eclipse application that would work with a linux/motif

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.