同事们,我正在尝试使用choice
和doTry
配置Camel路由。我的问题是第二个when
子句上的Cannot resolve method 'when'
。问题是:是否可以在choice
子句中使用doTry
构造?
路线如下所示:
public void configure() {
from("sftp://.....").choice()
.when(header("CamelFileName").contains("XML P")).log("Validate ${file:name}").bean(new MessProcessor(), "logInputMessDetails")
.doTry().
to("validator:file:C:\\Users...\\xsds\\p.xsd").log("${file:name} is valid")
.doCatch(ValidationException.class)
.log("XML P is not valid")
.to("file:sftp-inbound\\data-invalid\\" + header("CamelFileParent").toString())
.bean(messProcessor, "stopCamel")
/*The problem is here*/ .when(header("CamelFileName").contains("XML X")).log("Validate ${file:name}").bean(new MessProcessor(), "logInputMessDetails").
doTry().to("validator:file:C:\\Users\....\xsds\\position.xsd").log("${file:name} is valid").
doCatch(ValidationException.class).log("XML X is not valid").to("file:sftp-inbound\\data-invalid\\" + header("CamelFileParent").toString()).
bean(messProcessor, "stopCamel")
.end();
}
- 更新**
.bean(messProcessor, "stopCamel")
删除后路由:
public void configure() {
from("sftp://.....").choice()
.when(header("CamelFileName").contains("XML P")).log("Validate ${file:name}").bean(new MessProcessor(), "logInputMessDetails")
.doTry().
to("validator:file:C:\\Users...\\xsds\\p.xsd").log("${file:name} is valid")
.doCatch(ValidationException.class)
.log("XML P is not valid")
.to("file:sftp-inbound\\data-invalid\\" + header("CamelFileParent").toString())
.end;
/*The problem is still here*/ .when(header("CamelFileName").contains("XML X")).log("Validate ${file:name}").bean(new MessProcessor(), "logInputMessDetails").
doTry().to("validator:file:C:\\Users\....\xsds\\position.xsd").log("${file:name} is valid").
doCatch(ValidationException.class).log("XML X is not valid").to("file:sftp-inbound\\data-invalid\\" + header("CamelFileParent").toString()).
bean(messProcessor, "stopCamel")
.end();
}
- 更新**还有一个变体
public void configure() {
from("sftp:...}")
.choice()
.when(header("CamelFileName").contains("XML_POS")).log("Validate ${file:name}")
.to("validator:file:C:\\pos.xsd").log("${file:name} valid")
.when(header("CamelFileName").contains("XML_SETS")).log("Validate ${file:name}")
.to("validator:file:C:\\sets.xsd").log("${file:name} valid").end()
.onException(Exception.class)
.process(new FailureResponseProcessor())
.handled(true);
/*to("file:sftp-inbound");*/
}
2条答案
按热度按时间ttisahbt1#
将错误处理与路由分离,
然后把路线
xxls0lw82#
重点可能是
不会生成支持
when()
方法的对象。请记住:这仍然是普通的Java。2你只能在对应的类定义的对象上调用那些方法。3而且编译器只是告诉你调用
bean()
确实会导致一些不知道when
的东西。因此,答案是退一步,查看
bean()
的确切结果类型,并可能在那里进行不同的调用。