Apama 10.3 | Apama Documentation | 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>
<e-2 e2att='value1'><subElement>e2-sub-value1</subElement></e-2>
<e-2 e2att='value2'><subElement>e2-sub-value2</subElement></e-2>
<namespacedElement xmlns='urn:xmlns:foobar'>My namespaced
<p:namespacedElement>My namespaced text 2</p:namespacedElement>
<namespacedElement>My non-namespaced text 3</namespacedElement>
<return>Element whose name is an EPL keyword</return>
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:
MyRoot("An element value",
["My namespaced text","My namespaced text 2","My non-namespaced text 3"],
"Element whose name is an EPL keyword",
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: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:e-2 e2att="value2">

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.