Archive for September, 2010

All of the existing integrations of Smooks within other frameworks (JBossESB, Mule and others) suffer from a common design flaw, whereby users need to specify Result type information inside the framework’s configurations.  This Result type information is used by the framework to map Smooks filtering results back into the frameworks messaging constructs.

The problem with the above approach is:

  1. It makes the framework configuration more verbose than it should be.  Also (in some cases), the embedding framework does not provide a rich enough configuration model for defining this information, resulting in ugly/un-intuitive configuration hacks for defining the result.
  2. It means the user needs to read and understand the Smooks configuration and then make the framework level configurations, based on what they have interpreted from the Smooks configuration.  This is a pain!
  3. Adding support for new Result types usually involves modifications to the framework integration.
  4. It typically only supports mapping of one result type, restricting the use of Smooks.

When doing the Camel integration, we started to encounter this issue again.  The solution that we came up with was to add a configuration element to the Smooks core namespace, pulling all of this configuration back into the Smooks configuration and providing a richer configuration model:



    
        
        
    

The newly added exports element declares the results that are produced by this Smooks configuration. A export element can contain one or more result elements. A framework that uses Smooks could then perform filtering like this:

// Get the Exported types that were configured.
Exports exports = Exports.getExports(smooks.getApplicationContext());
if (exports.hasExports())
{
    // Create the instances of the Result types.
    // (Only the types, i.e the Class type are declared in the 'type' attribute.
    Result[] results = exports.createResults();
    smooks.filterSource(executionContext, getSource(exchange), results);
    // The Results(s) will now be populate by Smooks filtering process and
    // available to the framework in question.
}

There might also be cases where you only want a portion of the result extracted and returned. You can use the ‘extract’ attribute to specify this:



    
        
        
    

The extract attribute is intended to be used when you are only interested in a sub-section of a produced result. In the example above we are saying that we only want the object named orderBean to be exported. The other contents of the JavaResult will be ignored. Another example where you might want to use this kind of extracting could be when you only want a ValidationResult of a certain type, for example to only return validation errors.

Below is an example of using the extracts option from an embedded framework

// Get the Exported types that were configured.
Exports exports = Exports.getExports(smooks.getApplicationContext());
if (exports.hasExports())
{
    // Create the instances of the Result types.
    // (Only the types, i.e the Class type are declared in the 'type' attribute.
    Result[] results = exports.createResults();
    smooks.filterSource(executionContext, getSource(exchange), results);
    List objects = Exports.extractResults(results, exports);
    // Now make the object available to the framework that this code is running:
    // Camel, JBossESB, Mule etc.

This feature is now available in Smooks trunk.

Comments and feedback are as always welcome.

Thanks,

/Daniel

Here is a quick overview where you can find the slides presented on the Smooks Community Day 2010: