同事们,我正在尝试使用choice
和doTry
配置Camel路由。
我的问题是Cannot resolve method 'when'
第二个when
条款。
问题:是否可以在doTry
子句中使用choice
构造?
路线如下:
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");*/
}
答案 0 :(得分:2)
将错误处理与路线分开,
onException (exception)
handled (true)
process failure processor
然后才有路线
from ftp
to validate
答案 1 :(得分:0)
重点可能是
.bean(messProcessor, "stopCamel")
不会产生支持when()
方法的对象。
请记住:这仍然是普通的Java。您只能在相应类定义的对象上调用这些方法。编译器只是告诉你,调用bean()
会导致某些事情不知道when
。
所以答案是退后一步,查看bean()
的确切结果类型,并可能在那里进行不同的调用。