Hi,

I looked at your at your code and the idea and code looks just fine (thus
the new approach with routeConfiguration).

I would suggest to test this code on the latest version (3.17.0) and if
this still gives the same results, create a Jira ticket for it (including
your example):

https://issues.apache.org/jira/projects/CAMEL/issues


That said there maybe other ways to work around this. I started
implementing routes in Camel 2, so there weren't route templates yet and
used alternative approaches. Here are some ways I handled errors:


1) Custom error class

I created a custom error class "ErrorHandler".

Example code to call the errorhandler from a route:

@Override
public void configure() {

  routeErrorHandler = deadLetterChannel(errorUri);
  ErrorHandler errorHandler = new ErrorHandler(routeErrorHandler, props);
  routeErrorHandler = errorHandler.configure();

  from(fromUri)
    .errorHandler(routeErrorHandler)
    .log("someLog");

}

Here is my errorhandler implementation:

https://github.com/assimbly/modules/blob/develop/integrationModule/src/main/java/org/assimbly/integration/routes/errorhandler/ErrorHandler.java


2) Generate a route with the XML DSL:

Generate a route as XML (You may use a template engine like FreeMarker,
VeloCity or Mustache). The result of the template could look like this:

<routeConfiguration id="xmlError">
    <onException>
        <exception>java.lang.Exception</exception>
        <handled><constant>true</constant></handled>
        <log message="XML WARN: ${exception.message}"/>
    </onException></routeConfiguration>


And then add the routeConfiguration (can also be templated):

<route routeConfigurationId="xmlError">
    <from uri="timer:xml?period=5s"/>
    <log message="I am XML"/>
    <throwException exceptionType="java.lang.Exception" message="Some
kind of XML error"/></route>

The nice thing about template engines is that you can also you
conditionals or just remove/add stuff during the generation of the
XML.
The functionality to dynamically included/exclude route steps isn't
part of Camel route templates yet.


3. Run XML routes in the browser

In my open source project Assimbly, I also added ways to configure
routes as XML in the browser (including route configurations). This
was added in the

current beta: https://github.com/assimbly/gateway/releases/tag/3.7.0Beta.

You can check it here: https://github.com/assimbly/gateway/wiki/quick-start


Good luck,

Raymond










On Fri, Jun 17, 2022 at 8:37 PM j vh <jvh...@hotmail.com> wrote:

> Hi Raymond,
> Thanks for the suggestion. But seems that defining exception handling via
> the RouteConfigurationBuilder doesn't work either.
> Let me further explain with some piece of code.
> Maybe this will trigger some thoughts as you'll be able to see what I'm
> trying to do here.
>
> Hi-level overview:
> - 2 projects: 1 camel template base jar and 1 springboot camel application
> (that builds its route using the template from the other project).
> - the base jar builds a route template
> - the application jar builds a route using the template from the base jar
> - the desire here is to do some extra customization in the application (at
> templated-route creation time) to setup extra exception handling that is
> not included in the base template.
> - I have also tried to define global level exception handling using
> onException() in my application project's configure() method. But this is
> not catching anything either.
>
> Thanks,
> jvh
>
> ps: the post in between here by Ephemeris Lappis seems to be targeted for
> a different thread.   :-)
>
> Code snippets:
> 1) Base project route configure method:
>
>     @Override
>     public void configure() {
>       final RouteTemplateDefinition rtd = routeTemplate("route-template-1")
>             .templateParameter("queue-name")
>             .templateParameter("rest-endpoint")
>
>             .from("jmsBroker:queue:{{queue-name}}")
>             // .routeConfigurationId("test-route-configuration-id")    //
> tried to add (and remove the local .onException from here)
>
>            .onException(ConnectException.class)
>               .handled(false)
>               .log(LoggingLevel.ERROR, logger, "--> Exception:
> ${exception.message}, Delivery was rolled back")
>               .end()
>
>          .process(restHeaderProcessor)
>          .to("{{rest-endpoint}}")
>          .log(LoggingLevel.INFO, logger, "Message sent, ResponseCode:
> ${header.CamelHttpResponseCode}");
>     }
>
> 2) Application project configure method, building route from base project
> template:
>
>     @Override
>     public void configure() {
>       final String route = TemplatedRouteBuilder.builder(camelContext,
> "route-template-1")
>             .routeId("route-jms-to-rest")
>             .parameter("myQueue")
>             .parameter("http://localhost:9000/myRestEndpoint";)
>             .add();
>       log.info("buildTemplatedRoute() created templated route: {}",
> route);
>     }
>
> 3)  Application project Configuration spring boot component class:
>
> @Component
> public class MyCustomErrorHandler extends RouteConfigurationBuilder {
>
>    @Override
>    public void configuration() throws Exception {
>       routeConfiguration("test-route-configuration-id")
>       .onException(Exception.class)
>          .handled(true)  // discard the msg
>          .log(LoggingLevel.INFO, ">>>>> Hit this custom error handler:
> ${exception.message}")
>          .end();
>    }
> }
>
>
> ________________________________________
> From: ski n <raymondmees...@gmail.com>
> Sent: June 17, 2022 8:28 AM
> To: users@camel.apache.org
> Subject: Re: Apache Camel Exception Handling doubt
>
> Hi,
>
> It's good to provide a code example to see what you tried.
>
> Have you also tried to combine it with route configuration?
>
> https://camel.apache.org/manual/route-configuration.html
>
> This is available from 3.12.
>
> Raymond
>
> On Thu, Jun 16, 2022 at 7:43 PM j vh <jvh...@hotmail.com> wrote:
>
> > Hello,
> > btw... I'm using Camel 3.13.0 for this work.
> > ...jvh003
>

Reply via email to