Lately I have been itching to build something with BlazeDS. I have seen a couple presentations on it and am very intrigued by what one could do with it. After doing some reading and a presentation on it I decided to jump in and just build something.

I grabbed the code that Aaron West created for his BlazeDS / ColdFusion 9/ Flex presentation to use as a reference. I read though his presentation docs and configured ColdFusion in just a few minutes. The rest was a snap and I had the code from his demo running in little under 30 minutes.

I then started to expand the code to do more advanced things with it. The main thing I wanted to accomplish was to send a message to a specific consumer. I found out that had to inject a custom header that the consumers could filter on. This seemed very straightforward to do. Especially since the sample code from Aaron showed how to set a header var. This simple task ended up taking me 2 days to figure out.

The following chain of events started because the custom header I was trying to add was not there. I also noticed that the error created by the demo code didn't exist. At this point I had no reason to believe the code was bad because Aaron has used this same code in many presentations. I assumed that if the code had an issue someone would have pointed it out by now.

I first thought I discovered a bug that prevented the custom headers from being created. I first thought it was a bug in ColdFusion. Then I thought my issue was a bug in BlazeDS. Both of these panned out to be false. I then thought my altering of the original code was causing it.

I reverted my code back to the default state from Aaron's demo and added one line of debug code to it. This debug code appeared to have no affect on anything. I tried to get ColdFusion to write a log dump out some data but it wouldn't write anything. It started seeming that it was just skipping the debug code.

I then put in some 100% bogus code that would have thrown an error. What ended up happening was the exact opposite. The code still ran and there was no error. I checked every log file that ColdFusion creates and found nothing. I was still getting messages sent to BlazeDS. This is the point where I about pulled the rest of my hair out.

My next step was to alter the gateway. I changed it from a DataServicesMessaging gateway to an Asynchronous CFML gateway. I was trying to see if the gateway type for BlazeDS caused the error. With this gateway my intentionally bad code failed. I was then able to write dump data out and validate the data being generated. I started inspecting caching and turning off all cache settings in the ColdFusion administrator.

I then started swapping the gateway back and forth to figure out what was going wrong... or right. Mind you, I am no rookie when it comes to gateways. I have written a couple articles on them and use them on a daily basis to build clientless applications.

I again, went back to the docs to see if I had missed something. I combed the docs and the interwebs for hours. I was unable to discover anything relevant to my issue. On a whim I changed the name of the onIncomingMessage function to get ColdFusion to throw an error. To my amazement no error was thrown and the message was sent to BlazeDS.

This is a rather long winded story on how I found out that the gateway for BlazeDS does not use the onIncomingMessage function of the gateway cfc like other gateways do. I now have the ColdFusion gateway for BlaseDS pointing at a blank cfm file. Yep that is right.. a CFM not a CFC. It still works. Apparently when a message is sent to the gateway it is passed to BlazeDS and no CFM code is ran at all.

In part 2 I will be sharing the code I wrote to send messages to specific clients.

Till next time...