Apama 10.15.2 | Connecting Apama Applications to External Components | Correlator-Integrated Support for the Java Message Service (JMS) | Using the Java Message Service (JMS) | Mapping Apama events and JMS messages | Using convention-based XML mapping with JMS messages | Convention-based JMS message mapping example
 
Convention-based JMS message mapping example
The following example shows how to parse a JMS message whose body contains an XML document and map it to an Apama event called MyEvent.
Consider a JMS message whose body contains the following XML document:
<?xml version='1.0' encoding='UTF-8'?>
<myroot xmlns:p='http://www.myco.com/dummy-namespace'>
<myelement1>An element value</myelement1>
<myelement2 myattribute='123' myboolattribute='true'>456</myelement2>
<ignoredElement>XML content that is not included in the event definition
is ignored</ignoredElement>
<e1>Hello</e1>
<e1>there</e1>
<e-2 e2att='value1'><subElement>e2-sub-value1</subElement></e-2>
<e-2 e2att='value2'><subElement>e2-sub-value2</subElement></e-2>
<e1>world</e1>
<namespacedElement xmlns='urn:xmlns:foobar'>My namespaced
text</namespacedElement>
<p:namespacedElement>My namespaced text 2</p:namespacedElement>
<namespacedElement>My non-namespaced text 3</namespacedElement>
<return>Element whose name is an EPL keyword</return>
</myroot>
Define the Apama event MyEvent as follows:
event MyElement2
{
string _myattribute;
boolean _myboolattribute;
string xmlTextNode;

}

event E2
{
string _e2att;
string subElement;
}

event MyRoot
{
string myelement1;
MyElement2 myelement2;
sequence<string> e1;
sequence<string> namespacedElement;
string #return;
sequence<E2> e$002d2;
}

event MyEvent
{
string destination;
MyRoot myroot;
}
Note that the field names and types matter but the event type names do not.
The document above would be parsed to the following Apama event string:
MyEvent("queue:MyQueue",
MyRoot("An element value",
MyElement2("123",true,"456"),
["Hello","there","world"],
["My namespaced text","My namespaced text 2","My non-namespaced text 3"],
"Element whose name is an EPL keyword",
[E2("value1","e2-sub-value1"),E2("value2","e2-sub-value2")]
))
The exact same event definitions could be used in the other direction for creating an XML document, although the node order will be slightly different from that of the document shown above (based on the field order) and everything would be in the same XML namespace.
For the above example, the following XML is generated with http://www.example.com/myevent as the namespace and p as the namespace prefix:
<p:myroot xmlns:p="http://www.example.com/myevent">
<p:myelement1>An element value</p:myelement1>
<p:myelement2 myattribute="123" myboolattribute="true">456</p:myelement2>
<p:e1>Hello</p:e1>
<p:e1>there</p:e1>
<p:e1>world</p:e1>
<p:namespacedElement>My namespaced text</p:namespacedElement>
<p:namespacedElement>My namespaced text 2</p:namespacedElement>
<p:namespacedElement>My non-namespaced text 3</p:namespacedElement>
<p:return>Element whose name is an EPL keyword</p:return>
<p:e-2 e2att="value1">
<p:subElement>e2-sub-value1</p:subElement>
</p:e-2>
<p:e-2 e2att="value2">
<p:subElement>e2-sub-value2</p:subElement>
</p:e-2>
</p:myroot>