After you have imported and partially set up this sample, then performed the appropriate setup instructions, you can run the sample by following the instructions in the Running the sample section below.
This topic also includes an example input test message and a corresponding output message, so that you can confirm that the sample has worked.
All the test messages used in running this sample are based on the following format:
<SaleEnvelope>
<Header>
<SaleListCount>1</SaleListCount>
</Header>
<SaleList>
<Invoice>
<Initial>K</Initial>
<Initial>A</Initial>
<Surname>Braithwaite</Surname>
<Item>
<Code>00</Code>
<Code>01</Code>
<Code>02</Code>
<Description>Twister</Description>
<Category>Games</Category>
<Price>00.30</Price>
<Quantity>01</Quantity>
</Item>
<Item>
<Code>02</Code>
<Code>03</Code>
<Code>01</Code>
<Description>The Times Newspaper</Description>
<Category>Books and Media</Category>
<Price>00.20</Price>
<Quantity>01</Quantity>
</Item>
<Balance>00.50</Balance>
<Currency>Sterling</Currency>
</Invoice>
<Invoice>
<Initial>T</Initial>
<Initial>J</Initial>
<Surname>Dunnwin</Surname>
<Item>
<Code>04</Code>
<Code>05</Code>
<Code>01</Code>
<Description>The Origin of Species</Description>
<Category>Books and Media</Category>
<Price>22.34</Price>
<Quantity>02</Quantity>
</Item>
<Item>
<Code>06</Code>
<Code>07</Code>
<Code>01</Code>
<Description>Microscope</Description>
<Category>Miscellaneous</Category>
<Price>36.20</Price>
<Quantity>01</Quantity>
</Item>
<Balance>81.84</Balance>
<Currency>Euros</Currency>
</Invoice>
</SaleList>
<Trailer>
<CompletionTime>12.00.00</CompletionTime>
</Trailer>
</SaleEnvelope>
This sample contains two JavaCompute nodes, one of which uses XPath expressions (JavaComputeTransformXPath), and one of which uses the Java Plug-in Node API (JavaComputeTransformNoXPath). This is intended to provide a comparison between the two different approaches, both of which achieve the same result.
The following instructions cover the JavaComputeTransformXPath node - for the JavaComputeTransformNoXPath node, follow the instructions in exactly the same way but replace XPath with NoXPath where appropriate.
This sample uses the message flow JavaComputeTransformXPathFlow. It contains one input queue called JAVACOMPUTE.TRANSFORMXPATH.IN, and the message flow can transform and route the message to one of two output queues (JAVACOMPUTE.TRANSFORMXPATH.OUT and JAVACOMPUTE.TRANSFORMXPATH.FAILURE).
To run the sample:
If all the steps above have worked then the sample is complete. Take a look at the Java code in the message flow JavaComputeTransformXPathFlow to see how the message transformation was achieved.
If you use the JavaComputeTransformNoXPathFlow message flow, the output message is formatted like the following example:
<Parent>
<Statement Type="Monthly">
<Customer>
<Initials>KA</Initials>
<Name>Braithwaite</Name>
<Balance>00.50</Balance>
</Customer>
<Purchases>
<Article>
<Desc>Twister</Desc>
<Cost>0.48</Cost>
<Qty>01</Qty>
</Article>
<Article>
<Desc>The Times Newspaper</Desc>
<Cost>0.32</Cost>
<Qty>01</Qty>
</Article>
</Purchases>
<Amount>0.8</Amount>
</Statement>
<Statement Type="Monthly">
<Customer>
<Initials>TJ</Initials>
<Name>Dunnwin</Name>
<Balance>81.84</Balance>
</Customer>
<Purchases>
<Article>
<Desc>The Origin of Species</Desc>
<Cost>35.744</Cost>
<Qty>02</Qty>
</Article>
<Article>
<Desc>Microscope</Desc>
<Cost>57.92</Cost>
<Qty>01</Qty>
</Article>
</Purchases>
<Amount>129.40800000000002</Amount>
</Statement>
</SaleList>
</Parent>
If you use the JavaComputeTransformXPathFlow message flow, the output message is formatted like the following example:
<SaleEnvelope>
<SaleList>
<Statement Type="Monthly" Style="Full">
<Customer>
<Initials>KA</Initials>
<Name>Braithwaite</Name>
<Balance>00.50</Balance>
</Customer>
<Purchases>
<Article>
<Desc>Twister</Desc>
<Cost>0.48</Cost>
<Qty>01</Qty>
</Article>
<Article>
<Desc>The Times Newspaper</Desc>
<Cost>0.32</Cost>
<Qty>01</Qty>
</Article>
</Purchases>
<Amount>0.8</Amount>
</Statement>
<Statement Type="Monthly" Style="Full">
<Customer>
<Initials>TJ</Initials>
<Name>Dunnwin</Name>
<Balance>81.84</Balance>
</Customer>
<Purchases>
<Article>
<Desc>The Origin of Species</Desc>
<Cost>35.744</Cost>
<Qty>02</Qty>
</Article>
<Article>
<Desc>Microscope</Desc>
<Cost>57.92</Cost>
<Qty>01</Qty>
</Article>
</Purchases>
<Amount>129.408</Amount>
</Statement>
</SaleList>
</SaleEnvelope>
Note that there could be slight differences between the rounding of the JavaComputeTransformXPath and JavaComputeTransformNoXPath output messages, therefore expect to see 0.32000000000000006 instead of the 0.32 above.