Gary Liu
Gary Liu

Reputation: 31

Apache Camel Route - RegEx for multiple HTTP Request

Here is a sample to route message if USER_AUDIT Transaction with http request list: http://www.blabla.com/dothis/USER_AUDIT?AA=aa&BB=bb

   <when>
      <simple>${in.header.CamelHttpPath} regex '(?i)/USER_AUDIT'</simple>
      <bean ref="transactionList" method="get" />
      <bean ref="transactionTransform" method="convert" />
    </when>

Now I want to route other transactions see, CARD_VER to the same route. Is there a syntax like:

<simple>${in.header.CamelHttpPath} regex '(?i)/USER_AUDIT' || '(?i)/CARD_VER'</simple> ?

Upvotes: 2

Views: 1003

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55525

In the regular expression you can add "or"s so you can match if either of the 2 is matching. But then you need to a bit a bit reg exp ninja to do that. That would be something alike

'(?i)/[USER_AUDIT|CARD_VER]'

But check the JavaDoc for regular expression: http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html. And Other docs for how to do regular expressions. Also there is plugins you can install in your Java editors where you can try out regular expressions on the fly, to figure out a pattern that works for you.

However in the Simple expression in Camel you can also use binary operators, and add a 2nd expression. So it would be something like:

<simple>${in.header.CamelHttpPath} regex '(?i)/USER_AUDIT' ||
        ${in.header.CamelHttpPath} regex '(?i)/CARD_VER'</simple>

In Camel 2.8.x or older, you could only have 1 binary operator, but from Camel 2.9 onwards you can have as many you want.

See details in the Camel documentation for the Simple expression. See the section about operators at: http://camel.apache.org/simple

Upvotes: 2

Related Questions