Apache Camel:我可以在条件选择语句的when部分中放置多个语句吗? [英] Apache Camel: can I put multiple statements in the when part of the conditional choice statement?

查看:358
本文介绍了Apache Camel:我可以在条件选择语句的when部分中放置多个语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得以下类型的路由:

I would like to obtain the following kind of routing:

  1. 带有XML正文的HTTP POST消息进入CAME​​L
  2. 我存储了XML主体的一些参数
  3. 邮件被路由到外部端点
  4. 外部端点(外部服务器)答复

->这时,我想检查来自外部端点的答复是否是一个HTTP 200 OK,其中包含等于SUCCESS的XML参数. ->如果是这样,那么我想使用一些存储的参数来构造新的HTTP消息(这次是方法= PUT)并将其发送到外部端点

-> at this moment, I would like to check whether the reply from the external endpoint is a HTTP 200 OK containing a XML parameter equal to SUCCESS. -> if so, then I would like to use some of the stored parameters to construct a new HTTP message (method = PUT this time) and send it out to an external endpoint

我当前遇到的问题如下:

Problem that I am currently having, is the following:

.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的情况下添加这些额外的语句吗?好像什么时候不允许我添加额外的语句... (我在Eclipse IDE中出错).

Question: any idea how to add those extra statements in case the HTTP response code was 200 OK ? It looks like the when does not allow me to add extra statements ... (I got an error in my Eclipse IDE).

谢谢.

注意:如果200 OK匹配到新终结点",然后我必须使用该新终结点从路由创建一个新消息,可能是我必须路由消息吗? 例如:

Note: could it be that I have to route the message in case the 200 OK matches to a 'new endpoint' and then create a new from route with this new endpoint ? Eg:

.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"?

In this latter case, how exactly should I define this 'newendpoint' ?

推荐答案

在Java之类的编程语言DSL中,您可以一起构建谓词.几年前,我在以下位置发布了有关此内容的博客文章: http://davsclaus. blogspot.com/2009/02/apache-camel-and-using-compound.html

In the programming language DSLs such as Java, you can build predicates together. I posted a blog entry some years ago about this at: 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");

您可以使用和或或将它们链接在一起.

You can chain them together, using and or or.

Predicate isOrm = PredicateBuilder.and(p1, p2);

然后您可以在路由中使用isOrm

And then you can use isOrm in the route

from("hl7listener")
    .unmarshal(hl7format)
    .choice()
        .when(isOrm).beanRef("hl7handler", "handleORM")
        .otherwise().beanRef("hl7handler", "badMessage")
    .end()
    .marshal(hl7format);

这篇关于Apache Camel:我可以在条件选择语句的when部分中放置多个语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆