[ 
https://issues.apache.org/jira/browse/CAMEL-18262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17564603#comment-17564603
 ] 

Rhuan Rocha edited comment on CAMEL-18262 at 7/9/22 5:40 PM:
-------------------------------------------------------------

Hi,

The template does not use the routes configured inside the RouterBuilder. A way 
to configure it is by creating the RouteConfigurationBuilder as below.

 
{code:java}
@Component
public class MyCustomErrorHandler extends RouteConfigurationBuilder {
   @Override
   public void configuration() throws Exception {
       routeConfiguration("my-error-handler").
       onException(ConnectException.class)
      .handled(true)
      .log(LoggingLevel.ERROR, log, "--> Exception: ${exception.message}, 
Delivery was NOT rolled back");

     }
}{code}
Thus you configure it inside the template
{code:java}
routeTemplate("route-template-1")
.templateParameter("input-directory-param-id")
.templateParameter("rest-endpoint-id")
.templateParameter("route-id-param-id")

.from("file:{{input-directory-param-id}}")
.routeConfigurationId("my-error-handler")//He is the configuration. If needed 
you can use the template parameter.
.log(LoggingLevel.INFO, log, "--> Read file: ${header.CamelFileName}")
.to("{{rest-endpoint-id}}")
.id("{{route-id-param-id}}")
.log(LoggingLevel.INFO, log, "--> File: ${header.CamelFileName} sent to 
rest-endpoint: {{rest-endpoint-id}}");{code}
However, I have seen it has a bug and the template is not using the 
RouteConfigurationBuilder. I have found the root cause and I`ll send a PR soon 
to solve that. 


was (Author: rhuanrcoha):
Hi,

The template does not use the routes configured inside the RouterBuilder. A way 
to configure  it is creating the  RouteConfigurationBuilder as below.

 
{code:java}
@Component
public class MyCustomErrorHandler extends RouteConfigurationBuilder {
   @Override
   public void configuration() throws Exception {
       routeConfiguration("my-error-handler").
       onException(ConnectException.class)
      .handled(true)
      .log(LoggingLevel.ERROR, log, "--> Exception: ${exception.message}, 
Delivery was NOT rolled back");

     }
}{code}
Thus you configure it inside the template
{code:java}
routeTemplate("route-template-1")
.templateParameter("input-directory-param-id")
.templateParameter("rest-endpoint-id")
.templateParameter("route-id-param-id")

.from("file:{{input-directory-param-id}}")
.routeConfigurationId("my-error-handler")//He is the configuration. If needed 
you can use the template parameter.
.log(LoggingLevel.INFO, log, "--> Read file: ${header.CamelFileName}")
.to("{{rest-endpoint-id}}")
.id("{{route-id-param-id}}")
.log(LoggingLevel.INFO, log, "--> File: ${header.CamelFileName} sent to 
rest-endpoint: {{rest-endpoint-id}}");{code}
However, I have seen it has a bug and the template is not using the 
RouteConfigurationBuilder. I have found the root cause and I`ll send a PR soon 
to solve that. 

> Templated route exception handling not working
> ----------------------------------------------
>
>                 Key: CAMEL-18262
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18262
>             Project: Camel
>          Issue Type: Bug
>          Components: came-core
>    Affects Versions: 3.18.0
>         Environment: * Camel 3.18.0
>  * Spring-boot 2.7.1
>  * OpenJDK 11
>  * Maven 3.5.0
>            Reporter: j vh
>            Priority: Major
>         Attachments: camel-template-so.7z
>
>
> Using Route Templates as described here in the Camel docs: [route-template, 
> |https://camel.apache.org/manual/route-template.html]I cannot get any 
> exception handling to work unless I define it within the class that is 
> constructing the template itself.
> Specifically,  trying to use global exception handling in the class that 
> calls TemplatedRouteBuilder.builder() to build a route from my template. 
> Expected exceptions are not caught.
> And there is no .onException() method implementation to customize the 
> handling that could be called in the list of fluent methods starting with 
> TemplatedRouteBuilder.build().
> I have already posted this, with my example code, in the Camel mailing list. 
> Please have a look at the discussion here: 
> [mail-archive|[https://lists.apache.org/thread/26kp2tpfbgj9mxpfdr106f36xyj51d7g]]
> This is the hi-level description from that mail article:
> {code:java}
> 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.
>  {code}
> There is a overview of the code in the mail article as well. But I also have 
> a simplified single spring-boot test project with junit that I can provide if 
> needed.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to