1. So let's first take a look how to match a word in a string. To demonstrate how to do this I created this logging rule:
rule "Logging"
when
b: String(this matches "(?i).*Order(.|\n|\r)*" && this matches ".*EST(.|\n|\r)*")
then
System.out.println("b=|" + b + "|");
end
This rule will print out the incoming string if both the words 'Order' and 'EST' are matched.
The (?i) means 'ignore case', .*Order*. means the word 'Order' or 'order' anywhere in the string will be matched, but this will still not work if the string is multi-line (The '.' character does not match the newline character). So to fix that we need to make it .*Order(.|\n)*. Same story for the '\r'. This is the first word match which we can combine with '&&' or '||' with other matches like I did here looking for 'EST'.
2. Finally to push the String from the default place in the ESB message into the rules engine you need to use an object path of "body.'org.jboss.soa.esb.message.defaultEntry'" as shown in the XML fragment taking from a jboss-esb.xml.
<action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
<property name="ruleSet" value="ShippingRules.drl"/>
<property name="ruleReload" value="true"/>
<property name="object-paths">
<object-path esb="body.'org.jboss.soa.esb.message.defaultEntry'" />
</property>
<property name="destinations">
<route-to destination-name="express" service-category="ExpressShipping" service-name="ExpressShippingService"/>
<route-to destination-name="normal" service-category="NormalShipping" service-name="NormalShippingService"/>
</property>
</action>
alternatively you can use a path of esb="BODY_CONTENT".
4 comments:
thanks, Pal!
I try to use (?!) for case insensitive.
It seems that drools doesn't take it in account.
Hi Oleg,
This post just shows how to use regexp in Drools. I think you will have more luck asking your question at the Drools user-forum: https://lists.jboss.org/mailman/listinfo/rules-users.
Cheers,
--Kurt
I just make typo in my drools rule. I print (?!) instead of (?i). (?i) works correct. Sorry
Post a Comment