Using conditional expressions
When you configure event mappings for received JMS messages, you specify Apama event types to which JMS messages will be mapped along with the mapping rules. The correlator-integrated mapper for JMS uses JUEL expressions to indicate which mapping rules to use. JUEL (Java Unified Expression Language) expressions are a standard way to access data. When you specify an event type for a receiver, Apama Studio creates a default conditional expression that evaluates a JMS property named MESSAGE_TYPE, testing to see if its value is the name of the specified Apama event type. You can modify the default expression if you need to test for a different condition, depending on the format of the JMS messages that Apama will be receiving.
Depending on your application's needs, you can create a conditional expression for the following cases:
Match a JMS Header
Match a JMS Property
If the XML document root element exists
Match an XPath into the JMS message body
To specify a custom conditional expression:
1. On the Receiver Mapping Configuration tab, click the expression in the Expression column.
2. Click the Browse button next to the expression. This displays the Conditional Expression dialog, where you can edit the default expression.
3. In the Condition field, select the type of conditional expression you want from the drop-down list. Depending on your selection, the remaining available fields will vary.
4. Fill in the remaining fields as required. For some fields you select from drop-down lists, for others you enter values directly. If you select the Custom type of conditional expression, you can edit the expression directly. If a string literal in the expression contains a single or double quotation mark, it needs to be escaped with the backslash character ( \' or \" ).
5. Click OK. The new expression is displayed in the Expression column of the Receiver Mapping Configuration tab.
Conditional operators in custom expressions
The following operators are available:
== equal to
!= not equal
lt less than
gt greater than
le less than or equal
ge greater than or equal
and or empty null or empty
not A number of methods are available for common string operations such as the ones listed below.
contains() endsWith() equals() equalsIgnoreCase() matches() startsWith() For a complete list of the available methods as well as details for using these methods, see
JUEL mapping expressions reference for JMS.
Custom conditional expression examples
In most cases the decision about which Apama event type to map to for a given JMS message is based on a JMS message property value or sometimes a header, such as JMSType. In other cases, when there is no alternative, the decision is made by parsing XML content in the document body and evaluating an XPath expression over it. Here are some examples of typical conditional expressions.
JUEL boolean expression based on a JMS string property value:
${jms.property['MY_MESSAGE_TYPE'] == 'MyMessage1'}
JUEL boolean expression based on a JMS header value:
${jms.header['JMSType'] == 'MyMessage1'}
JUEL boolean expression based on the existence of the XML root element 'message1' in the body of a TextMessage:
${xpath(jms.body.textmessage, 'boolean(/message1)')}
JUEL boolean expression based on testing the value of an XML attribute in the body of a TextMessage:
${xpath(jms.body.textmessage, '/message/info/@messageType') == 'MyMessage'}
JUEL boolean expression for matching based on message type (
TypeMessage,
MapMessage,
BytesMessage,
ObjectMessage, or
Message):
${jms.body.type == 'TextMessage'}
The following boolean JUEL expressions show advanced cases demonstrating what is possible using JUEL and illustrating how the syntax works with example XML documents
JUEL expression that matches all messages:
${true}
'greater than' numeric operator:
${jms.property['MY_LONG_PROPERTY'] gt 120}
Using backslash to escape quotes inside a JUEL expression:
${jms.body.textmessage == 'Contains \'quoted\' string'}
Operators 'not', 'and', 'or', and 'empty':
${not (jms.property['MY_MESSAGE_TYPE'] == 'MyMessage1' or
jms.property['MY_MESSAGE_TYPE'] == 'MyMessage2') and
not empty jms.property['MY_MESSAGE_TYPE']}
Testing the value of an entry in the body of a MapMessage:
${jms.body.mapmessage['myMessageTypeKey'] == 'MapMessage1'}
An advanced XPath query (and use of JUEL double-quoted string literal and XPath single-quoted string literal in the same expression)
${xpath(jms.body.textmessage, " (count(/message3/e) > 2) and
/message3/e[2] = 'there' and
(/message3/e[1] = /message3/e[3]) ")}
For an XML document such as
<message3><e>Hello</e><e>there</e><e>Hello</e></message3>
XPath namespace support:
${xpath(jms.body.textmessage, " /message4/*[local-name()='element1' and
namespace-uri()='http://www.myco.com/testns']/text() ") ==
'Hello world'}
For an XML document such as
<message4 xmlns:myprefix="http://www.myco.com/testns">
<element1>No namespace</element1>
<myprefix:element1>Hello world</myprefix:element1></message4>
Recursively parsing XML content nested in the CDATA section of another XML document:
${xpath( xpath(jms.body.textmessage, '/messageA/text()'),
'/messageB/text()') == 'MyNestedMessageType'}
For an XML document such as
<messageA><![CDATA[
<messageB>MyNestedMessageType</messageB> ]]>
</messageA>
Check if a JMS string property value contains the specified value:
${jms.property['MY_MESSAGE_TYPE'].contains(‘Apama')}
Check if a JMS TextMessage body matches the specified regular expression:
${jms.body.textmessage.matches('.*inb*[ou]*r') }
For a table of expressions for getting and setting values in JMS messages and recommended mappings to Apama event types, see
JUEL mapping expressions reference for JMS.