如何在带有 Java DSL 的路由中使用 apache Camel 在 try catch 块中使用选择

San*_*mar 2 apache-camel

如何在 Java DSL 路由中使用 Apache Camel 在 try catch 块中使用选择?

我有一种情况,我需要以下结构:

路线-->来自--> doTry-->选择-->何时-->简单-->到-->否则-->到-->enddoTry-->docatch-->到-->enddocatch- ->结束路线

截至目前,我尝试了以下几行:

    .doTry()
    .choice()
    .when(header("CamelFileName").contains("xxxxx"))
    .to()
    .otherwise().to("controlbus:route?routeId=XXXX&action=stop")
    .doCatch(java.lang.Exception.class)
    .log("STOPPING ROUTE")
    .to("controlbus:route?routeId=XXXX&action=stop&async=true")
Run Code Online (Sandbox Code Playgroud)

但我收到“找不到符号”错误docatch()

您能否建议在 Java DSL 的 try catch 块中使用“选择”的方法?

pvp*_*ran 6

尝试这个。这应该有效

.doTry()
    .choice()
      .when(header("CamelFileName").contains("xxxxx"))
        .to()
      .otherwise()
        .to("controlbus:route?routeId=XXXX&action=stop")
.endDoTry()
.doCatch(java.lang.Exception.class)
.log("STOPPING ROUTE")
.to("controlbus:route?routeId=XXXX&action=stop&async=true")
Run Code Online (Sandbox Code Playgroud)