gpt4 book ai didi

java - Camel : How to once insert data into DB table if only all xmls are valid?

转载 作者:行者123 更新时间:2023-12-01 08:53:36 25 4
gpt4 key购买 nike

同事们,我有通过 xsd 验证 xml 的路线。在这种情况下,每当任何 xml 有效时,路由都会调用 .to("jdbc:DataSource"):

 from("ftp://....." +
"&throwExceptionOnConnectFailed=true" +
"&filterDirectory=${date:now:yyyymmdd}")
.choice()
.when(header("CamelFileName").contains("XML_A.....")).log("Validate ${file:name}")
.to("validator:file:C:\\integration\\xsds\\xml_a.xsd").log("${file:name} is valid")
.when(header("CamelFileName").contains("XML_B.....")).log("Validate ${file:name}")
.to("validator:file:C:\\integration\\xsds\\xml_b.xsd").log("${file:name} is valid")
.when(header("CamelFileName").contains("XML_C.....")).log("Validate ${file:name}")
.to("validator:file:C:\\integration\\xsds\\xml_c.xsd").log("${file:name} is valid")
.end()
.log("Upload table ExtractS")
.to("bean:stgExtractToSQL")
.to("jdbc:dataSource") /*Here i would like to execute only one insert into one single table*/
;

当所有 xml 都有效时,如何仅调用 .to("jdbc:dataSource") 一次?附:在 .to("jdbc:dataSource") 之后,我需要处理每个 xml 文件。谢谢。

最佳答案

如果出现验证错误,Camel 的 validator 组件将抛出异常,因此您不应该访问 .to("jdbc:dataSource") 并且应该是安全的。但是,处理此问题的更好方法是在路由中使用 doTry()doCatch() 来指示它已意识到异常,并且在您需要时当验证失败时添加额外的行为。所以你的路线将如下所示:

from("ftp://....." +
"&throwExceptionOnConnectFailed=true" +
"&filterDirectory=${date:now:yyyymmdd}")
.log("Validate ${file:name}")
.doTry()
.choice()
.when(header("CamelFileName").contains("XML_A....."))
.to("validator:file:C:\\integration\\xsds\\xml_a.xsd")
.when(header("CamelFileName").contains("XML_B....."))
.to("validator:file:C:\\integration\\xsds\\xml_b.xsd")
.when(header("CamelFileName").contains("XML_C....."))
.to("validator:file:C:\\integration\\xsds\\xml_c.xsd")
.endChoice()

.log("${file:name} is valid")
.log("Upload table ExtractS")
.to("bean:stgExtractToSQL")
.to("jdbc:dataSource") /*Here i would like to execute only one insert into one single table*/
.endDoTry()
.doCatch(ValidationException.class)
.log("Validation of file [${file:name}] failed")
.end()
;

关于java - Camel : How to once insert data into DB table if only all xmls are valid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42203893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com