Wednesday, November 23, 2011

CF: Tracing AMF (Action Message Format) packages for Flex/BlazeDS in Coldfusion

I know I had seen this and done this before but for some reason I could not find it. I am looking at a Flex based component that makes remote calls to ColdFusion (Flash Remoting), then, renders some of the data. Now I wanted to find out what is happening and more specifically what data is being exchanged between Flex and ColdFusion.
As you might know, the exchange between CF and Flex is in AMF format, which is a binary format and thus not easily readable over protocol sniffer.
I know, I know, I can get many tools, and ServiceCapture is mentioned many times; but I wanted to do this simpler.
What I done in the past is used the command window to get this, but with many things, you forget, or just get older ;o)
So you can start ColdFusion in a Command / Terminal window, by going to the installation folder and finding the right startup script.
For windows:
[cfroot]\bin\cfstart.bat

This will start the ColdFusion server in command window:
Command Window running ColdFusion


However, this did not automatically decode the AMF messages or gave me insight into flash remoting. In order to that I had to find the flex services-config file. On stand-alone server install on Windows this would be located here:
[cfroot]\wwwroot\WEB-INF\flex\services-config.xml

find the logging section and change logging level to "Debug" like so:

<logging>

        <target class="flex.messaging.log.ConsoleTarget" level="Debug">

        ...

</logging>



You can even change the prefix of the messages, e.g. to Flex like so:



<logging>

        <target class="flex.messaging.log.ConsoleTarget" level="Debug">

            <properties>

                <prefix>[Flex] </prefix>

This is the cheap way of getting debugging going on the protocol and see what is being exchanged.
Hope this helps,

-B


1 comment:

Charlie Arehart said...

Cool stuff, Bilal.

Just one more resource for such AMF monitoring that may interest your readers: those using FusionReactor (the Monitoring tool for CF, Railo, BD, and indeed any JEE server) can also easily monitor AMF communication on a per-request basis. They can view it using the "request details" page for any request (running or finished) and its available "AMF" tab.

This will show both the input (what CFCs and methods are called, with their arguments), but also what result is generated, in a more human-readable format. it's a real eye-opener for those who have not monitored such communications, and a real boon when troubleshooting them.

For more info, including screenshots, see the feature focus page for AMF.