Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
11.4. Configuring Smooks to Capture Multiple NodeModels
- To configure Smooks to capture multiple NodeModels for use by the FreeMarker templates, you should configure the DomModelCreator visitor. It should be targeted at the root node of each model. Note again that Smooks also makes this available to SAX filtering (the key to processing huge messages).This is The Smooks configuration for creating the NodeModels for the message:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Next, apply the following FreeMarker templates:
- A template to output the order
header
details, up to but not including the order items. - A template for each of the order items, to generate the item elements in the salesorder.
- A template to close out the message.
With Smooks, you can implement this by defining two FreeMarker templates. One to cover points one and three (combined) above, and a second to cover the item elements. - Applt the first FreeMarker template. It is targeted at the order-items element and looks like this:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The?TEMPLATE-SPLIT-PI?
processing instruction tells Smooks where to split the template, outputting the first part of the template at the start of the order-items element, and the other part at the end of the order-items element. The item element template (the second template) will be output in between. - Apply the second FreeMarker template. This outputs the item elements at the end of every order-item element in the source message:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Because the second template fires on the end of the order-item elements, it effectively generates output into the location of the?TEMPLATE-SPLIT-PI?
processing instruction in the first template. Note that the second template could have also referenced data in theorder
NodeModel. - Apply a closing template of your choice.NoteThis approach to performing a one-to-one transformation of a huge message works because the only objects in memory at any one time are the order header details and the current order-item details (in the Virtual Object Model). Obviously it can' work if the transformation is so obscure as to always require full access to all the data in the source message, for example if the messages needs to have all the order items reversed in order (or sorted). In such a case however, you do have the option of routing the order details and items to a database and then using the database's storage, query and paging features to perform the transformation.