3

我正在尝试构建一个尝试验证 xml 的路由,如果一切正确,则必须拆分此文件,否则会引发异常并且它必须执行其他操作。所以我做了以下事情:

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("validator:classpath:"+validator)
        .split(xPathMessageTypeSplit)
        .to("jms:"+queue+"?jmsMessageType=Text")
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
        .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
    .end();

但它不编译(如果我不使用拆分,那么它会编译并工作)并且错误是:

The method doCatch(Class<ValidationException>) is undefined for the type ExpressionNode

所以我尝试了以下

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("direct:validate")
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
        .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
    .end();

    from("direct:validate")
        .to("validator:classpath:"+validator)
        .to("direct:split_message");

    from("direct:split_message")
        .split(xPathMessageTypeSplit)
        .to("jms:"+queue+"?jmsMessageType=Text");

这次我得到重复端点的错误

 org.apache.camel.FailedToStartRouteException: Failed to start route route312 because of Multiple consumers for the same endpoint is not allowed: Endpoint[direct://validate]

你对如何解决这个问题有任何想法吗?

4

2 回答 2

7

为了从 split() 块(或选择或其他嵌套类型)返回 doTry() 块,您需要使用 endDoTry()。与其名称相反,此方法将结束嵌套的拆分块并返回到 doTry() DSL。

我将使用您发布的第一条路线进行这些更改:

from("file:"+fileOutboxTransformed+"?preMove=inprogress&move="+backupFolderTransformed+"/"+labelMessageType+"_${date:now:yyyyMMddHHmmssSSS}-${file:name.noext}.${file:ext}")
    .log(LoggingLevel.INFO, "Got transformed file and sending it to jms queue: "+queue)
    .doTry()
        .to("validator:classpath:"+validator)
        .split(xPathMessageTypeSplit)
            .to("jms:"+queue+"?jmsMessageType=Text")
        .endDoTry()
    .doCatch(ValidationException.class)
        .log(LoggingLevel.INFO, "Validation Exception for message ${body}")
        .to("xslt:classpath:"+transformationsErrorAfter)
        .split(xPathNotificationSplit)
            .to("file:"+fileOutboxInvalid+"?fileName=${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.err2")
        .endDoTry()
    .end();
于 2013-07-31T14:13:01.050 回答
1

你的第二次尝试似乎很好。您收到的错误是由两条以from("direct:validate") Don't you have an other route in your application from the same endpoint? 开头的两条路由引起的吗?

编辑:尝试以不同的方式命名它,也许验证已经存在(在您的应用程序中或骆驼内部)

于 2012-07-26T12:49:54.547 回答