Running the JavaComputeTransform sample

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.

Input test message

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>

Running the sample

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:

  1. Switch to the Broker Application Development perspective on IBM WebSphere Message Broker Toolkit.
  2. Open the test message enqueue file, JavaComputeTransformXPathMessage.
  3. Click Write to queue. A message is sent to the JAVACOMPUTE.TRANSFORMXPATH.IN queue. The message flow transforms the message using the JavaComputeTransformXPath node, and routes it to the JAVACOMPUTE.TRANSFORMXPATH.OUT queue.
  4. To check that the message has reached the correct queue use WebSphere MQ Explorer.
    1. Start WebSphere MQ Explorer.
    2. Expand the folders under the queue manager WBRK6_DEFAULT_QUEUE_MANAGER, and select Queues.
    3. When refreshing WebSphere MQ Explorer ensure that the Queues folder is selected and not an actual queue name. If you select a queue name, not all the queues shown will be refreshed.
  5. Refresh the queue display to show the current number of messages on each queue. A message should appear on the JAVACOMPUTE.TRANSFORMXPATH.OUT queue.
  6. To view this output message, go back to IBM WebSphere Message Broker Toolkit and click Get a message from a Queue on the toolbar.
  7. Type in a Queue Manager name of WBRK6_DEFAULT_QUEUE_MANAGER, and a Queue name of JAVACOMPUTE.TRANSFORMXPATH.OUT.
  8. Click Read From Queue to display the contents of the output message.
  9. Compare this with the expected output message.

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.

Expected output message (JavaComputeTransformNoXPath)

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>

Expected output message (JavaComputeTransformXPath)

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.

Main Page iconBack to Running the JavaCompute Node sample