JBoss.orgCommunity Documentation

Chapter 2. Tasks

2.1. New Smooks Configuration File Creation
2.2. Input Task Configuring
2.3. Mapping processes
2.3.1. Direct source to target mapping
2.3.2. Java Mapping Task
2.3.3. Apply Template Task
2.4. Smooks Configuration testing using Smooks Run Configuration

This chapter describes the main tasks that can be performed with Smooks tools. In this chapter we use the example that can be downloaded from here.

Select the project where you want to create the new Smooks Configuration File and right-click on it. Select NewOtherSmooksSmooks Configuration File. Then click the Next button.


Select the src folder to be the files container, and type the name smooks-config.xml. Click the Next button.


Configuring an Input task is mandatory step when creating a smooks project. You can configure it on the Process page of the editor: look for the "Input Task" in the Process Map at the top of the page.


Select it and you will see all the properties to set for the Input reader of your Smooks configuration. "Input type" corresponds to the type of data that you will be working with. For example, to work with incoming CSV (Comma-separated Values) data, you would specify "CSV" in the drop-down list. Each reader type has slightly different configuration details that must be set in the "Input configuration" area. For instance, the CSV reader requires you to specify details such as the encoding, quote character, separator character, and the list of incoming fields. The EDI reader requires the encoding and the path to the Mapping Model describing the incoming data. In the Input data section, you can specify some sample data that conforms to your reader configuration.

Once you've specified your reader configuration and sample data, you can see the input model rendered in a tree form in the Input model section. In the picture below you can see the correct configuration of an XML input task where input-message.xml is set as an input data file.


In previous versions of the Smooks tooling you were required to manually create a java mapping task before applying a transformation template to the data. A new method is now available called Direct source to target mapping. This allows you to skip the manual creation of Java mapping and apply a template directly to your data.

This option is used to view the results of Smooks transforming procedure. To do the testing you should select your Smooks Configuration file you want to transfer in the Project Navigator or open it in the Smooks Configuration Editor and then select "Run As..." from the Run toolbar button or select the Run->Smooks Run Configuration option in the top menu bar. The Smooks Configuration file will then be run automatically.


Any errors or warnings will appear in a pop up dialog. The output of the test will appear in the Console view. In our case the following streaming output will appear:

[Stream Templating Result ...]
    |--
    |"productId","quantity","price"
    |"111","2","8.9"
    |"222","7","5.2"
    |--

[Java Mapping Results...]
    |--
    |> order (beanId = "order")
    |    > header (beanId = "header")
    |        > date = "2006-11-15 20:45:28.0 EET"
    |        > customerNumber = 123123L
    |        > customerName = "Joe"
    |    > orderItems (beanId = "orderItems")
    |        > example.model.OrderItem (beanId = "orderItem")
    |            > productId = 111L
    |            > quantity = 2I
    |            > price = 8.9D
    |        > example.model.OrderItem (beanId = "orderItem")
    |            > productId = 222L
    |            > quantity = 7I
    |            > price = 5.2D
    |--

If the test runs but doesn't generate any streaming output the Console output will be the following:

 Nothing to Display:
            - No Java Mappings.
            - No Templates Applied.