ColdFusion & Flex Data Transformations with Conduit Filters

Previously I discuss a simple mechanism in Conduit
to enable you to apply data transformations on outgoing data from
ColdFusion to Flex, using a simple inheritance strategy, to overwrite
how the CFC=>Flex VO object translation occurred.

The only issue there is, if you need to be able to do different
transformations, you end up having to combine separate code-bases into
a single CFDeserialiser or CFSerialiser , which is not very portable, or decoupled.

To solve this problem, Conduit has filters that can be
applied at different points in the AMF communication life cycle, and
manipulate the data that is being passed through.

So, if we take the example we looked at previously, where we reversed
every simple value that was travelling from ColdFusion to Flex, we can
convert this into a simple filter, which is much easier to apply, and
can be combined with other filters to do fairly complex data

An example ReverseFilter looks like this:

<cfcomponent hint="filter that reverses all strings" output="false">

<cffunction name="init" hint="Constructor" access="public" returntype="ReverseFilter" output="false">
    <cfargument name="args" hint="the argument ConfigMap" type="struct" required="Yes">
        return this;

<cffunction name="doFilter" hint="does the filtering - reverses strings" access="public" returntype="void" output="false">
    <cfargument name="filterData" hint="the data for the filter" type="struct" required="Yes">
    <cfargument name="filterChain" hint="the filter chain" type="conduit.core.filter.FilterChain" required="Yes">

        //we know there will be a 'result', in the after filter
            arguments.filterData.result = Reverse(arguments.filterData.result);

        //push on to the next filter;


The doFilter() method is the method that manipulates the incoming data,
in this case, looking at the 'result' argument that is being passed in,
and if it's a simple value, reversing it.

The Filter is then passed on to any subsequent filters, by calling the
next() method on the filterChain.  If we didn't want filtering to
continue, we could simply skip that step.

We then configure this ReverseFilter against the CFSerialiser, to convert outgoing data that is going to Flex, like so:

<destination id="Conduit">
        <channel ref="my-cfamf" />
     <adapter ref="conduit" />
             <!--- cfc config --->
            <!-- This is an example filter that reverses strings -->        

The 'apply-after' section, tells Conduit to fire the ReverseFilter
after the processing of the CFSerialiser, rather than before, although
in this case, it won't make that much difference.

This is just a simple example for the sort of things that can be done
with Conduit Filters, but it should give you a good idea on how with a
few simple filters, you can drastically change the way data is sent to
and from Flex and ColdFusion.

If you want to read more about Conduit, please have a look at the wiki, and daily builds can be downloaded from the google group.

Leave a Comment