Apache Camel: can I place multiple statements in that part of the conditional selection expression?

I would like to get the following kind of routing:

  • An HTTP POST message with an XML body is included in CAMEL
  • I save some XML body parameters
  • The message is routed to an external endpoint.
  • External endpoint response (external server)

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

The problem I am having right now is this:

.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() 

Question: any idea how to add these additional instructions in case the HTTP response code was 200 OK? It seems like when I cannot add additional statements ... (I got an error in my Eclipse IDE).

Thanks in advance.

Note. Could it be that I have to forward a message if 200 OK matches the β€œnew endpoint” and then create a new route with this new endpoint? For example:

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

In this last case, how exactly should I define this "new point"?

+7
source share
2 answers

In a DSL programming language such as Java, you can create predicates together. A few years ago I posted a blog post: http://davsclaus.blogspot.com/2009/02/apache-camel-and-using-compound.html

For example, having two predicates

 Predicate p1 = header("hl7.msh.messageType").isEqualTo("ORM"): Predicate p2 = header("hl7.msh.triggerEvent").isEqualTo("001"); 

You can bind them together using and / or or.

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

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); 
+20
source

yep, you can have multiple statements between .when () and .otherwise (), and you can always call .endChoice () to explicitly complete each conditional block ...

to your other question, you can use camel-direct to combine multiple routes, etc.

+4
source

All Articles