[
https://issues.apache.org/jira/browse/CAMEL-18262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17564585#comment-17564585
]
j vh edited comment on CAMEL-18262 at 7/9/22 3:00 PM:
------------------------------------------------------
Hi [~rhuanrcoha],
I've just tried your suggest as shown below and it is also NOT working.
But if this is not exactly what you wanted to try - let me know.
Thanks,
{code:java}
@Override
public void configure() throws Exception {
camelContext.addRoutes(new MyCustomErrorHandler());
final String routeId = TemplatedRouteBuilder.builder(camelContext,
"route-template-1")
.routeId("my-test-file-route")
.parameter("input-directory-param-id", "input-directory")
.parameter("rest-endpoint-id",
"http://localhost:9000/TestSink/any-string")
.parameter("route-id-param-id", "my-internal-route-id")
.add();
log.info("Route {} created from template", routeId);
}{code}
{code:java}
public class MyCustomErrorHandler implements RoutesBuilder {
@Override
public void addRoutesToCamelContext(final CamelContext context) throws
Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(ConnectException.class)
.handled(true)
.log(LoggingLevel.ERROR, log, "--> Exception:
${exception.message}, Delivery was NOT rolled back")
.end();
}
});
}
@Override
public Set<String> updateRoutesToCamelContext(final CamelContext context)
throws Exception {
return null;
}
}
{code}
was (Author: JIRAUSER292531):
Hi [~rhuanrcoha],
I've just your suggest as shown below and it is also NOT working.
But if this is not exactly what you wanted to try - let me know.
Thanks,
{code:java}
@Override
public void configure() throws Exception {
camelContext.addRoutes(new MyCustomErrorHandler());
final String routeId = TemplatedRouteBuilder.builder(camelContext,
"route-template-1")
.routeId("my-test-file-route")
.parameter("input-directory-param-id", "input-directory")
.parameter("rest-endpoint-id",
"http://localhost:9000/TestSink/any-string")
.parameter("route-id-param-id", "my-internal-route-id")
.add();
log.info("Route {} created from template", routeId);
}{code}
{code:java}
public class MyCustomErrorHandler implements RoutesBuilder {
@Override
public void addRoutesToCamelContext(final CamelContext context) throws
Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(ConnectException.class)
.handled(true)
.log(LoggingLevel.ERROR, log, "--> Exception:
${exception.message}, Delivery was NOT rolled back")
.end();
}
});
}
@Override
public Set<String> updateRoutesToCamelContext(final CamelContext context)
throws Exception {
return null;
}
}
{code}
> 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)