我想获得以下类型的路由:
- 带有 XML 正文的 HTTP POST 消息进入 CAMEL
- 我存储了XML主体的一些参数
- 消息被路由到外部端点
- 外部端点(外部服务器)回复
-> 此时,我想检查来自外部端点的回复是否是包含等于 SUCCESS 的 XML 参数的 HTTP 200 OK。
-> 如果是这样,那么我想使用一些存储的参数来构造一个新的 HTTP 消息(这次是 method = PUT)并将其发送到外部端点
我目前遇到的问题如下:
.choice()
.when(simple("${in.headers.CamelHttpResponseCode} == 200"))
// now I want do a few things, eg: check also the XML body via xpath
// and change the message to be sent out (change Method to PUT, ...)
.to("http://myserver.com")
.otherwise()
// if no 200 OK, I want the route to be stopped ... not sure how ?
.end()
问题:知道如何在 HTTP 响应代码为 200 OK 的情况下添加这些额外的语句吗?看起来 when 不允许我添加额外的语句......
(我的 Eclipse IDE 出现错误)。
提前致谢。
注意:如果 200 OK 与“新端点”匹配,我是否必须路由消息,然后使用此新端点创建新的路由?
例如:
.choice()
.when(simple("${in.headers.CamelHttpResponseCode} == 200"))
.to("mynewendpoint")
.otherwise()
// if no 200 OK, I want the route to be stopped ... not sure how ?
.end();
from("mynewendpoint").
.setHeader(etc etc)
.to("http://myserver.com")
在后一种情况下,我应该如何定义这个“newendpoint”?
在 Java 等编程语言 DSL 中,您可以一起构建谓词。几年前我发表了一篇关于此的博客文章:http://davsclaus.blogspot.com/2009/02/apache-camel-and-using-compound.html
例如有两个谓词
Predicate p1 = header("hl7.msh.messageType").isEqualTo("ORM"):
Predicate p2 = header("hl7.msh.triggerEvent").isEqualTo("001");
您可以使用 and 或 or 将它们链接在一起。
Predicate isOrm = PredicateBuilder.and(p1, p2);
然后你可以在路由中使用 isOrm
from("hl7listener")
.unmarshal(hl7format)
.choice()
.when(isOrm).beanRef("hl7handler", "handleORM")
.otherwise().beanRef("hl7handler", "badMessage")
.end()
.marshal(hl7format);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)