One Star

CatchDefinition cannot be cast to ChoiceDefinition cTry/cMessageRouter

Hi,
I have a route where I want to execute a job and fallback to a second job if the first one fails. If both fail a custom error message should be returned to the client. If the client request doesn't fulfill certain conditions, an error message will be returned without trying.


I get a ClassCastException:
org.apache.camel.model.CatchDefinition cannot be cast to org.apache.camel.model.ChoiceDefinition
java.lang.ClassCastException: org.apache.camel.model.CatchDefinition cannot be cast to org.apache.camel.model.ChoiceDefinition
    at org.apache.camel.model.ProcessorDefinition.endChoice(ProcessorDefinition.java:1316)
    at esb_workshop.trycatchroute_0_1.TryCatchRoute.configure(TryCatchRoute.java:118)
    at org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)
    at org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:276)
    at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:262)
    at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:677)
    at org.apache.camel.main.MainSupport.postProcessCamelContext(MainSupport.java:471)
    at org.apache.camel.main.MainSupport.postProcessContext(MainSupport.java:406)
    at esb_workshop.trycatchroute_0_1.TryCatchRoute$1.doStart(TryCatchRoute.java:180)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)

Activating "Append endChoice()" on the when condition doesn't help. Should I open a JIRA issue for it? What's the recommend workaround in this case?
I'm using TOS 5.5.1.
Cheers
Dennis
1 REPLY
One Star

Re: CatchDefinition cannot be cast to ChoiceDefinition cTry/cMessageRouter

This Camel FAQ entry is helpful: https://camel.apache.org/why-can-i-not-use-when-or-otherwise-in-a-java-camel-route.html
Of course it works if I split up the route in multiple routes but in my view the TOS should not produce invalid code.