在项目中遇到根据不同字段判断要推送的Uri地址的需求,由于用spring进行配置写在Java代码中的各种方法尝试无果后,根据查询文档找到一种方法可以实现。
具体场景如下:
1.根据字段值为目标地址赋值
String targetUrl = "";
if("1".equals(HomeDomain)){
targetUrl = "http://localhost/servlet1";
}else if("2".equals(HomeDomain)){
targetUrl = "http://localhost/servlet2";
}
2.然后把这个targetUrl放入camel的header中:message.setHeader("targetUrl", targetUrl);
3.在spring中配置流程如下:
<!-- 此配置用于使用目标Uri覆盖下边的uri -->
<camel:setHeader headerName="CamelHttpUri">
<camel:simple>${header.targetUrl}</camel:simple>
</camel:setHeader>
<camel:to uri="http://localhost:8080/sisimulator/"></camel:to>
这样经过操作之后,uri会跳转到你想要的targetUrl而不是http://localhost:8080/sisimulator/。
应该还有其他方法,等研究用到的时候再发现了。