As I’ve been blogging lately, I’m trying to jump headfirst into Flex and Flex Data Services with ColdFusion. Actually, I had been trying to use Live Cycle Data Services, since it’s the newest shiniest version of FDS. But, it’s also beta and I’m not familiar enough with the previous versions to know where the beta really begins and ends. As a result I decided it was probably in my best interest to work with FDS express for now.
So, I uninstalled LCDS and installed FDS and began on my merry way. The first real problem I ran into (besides not having the faintest clue how to get started) was, well, getting started.
And I might joke about needing to know how to get started before I get started, but seriously, that was a problem. Eventually after reading a few articles on Adobe.com I stumbled across the Flex documentation in LiveDocs. (Brilliant!) Under the Getting Started with Flex 2 lessons (who would have thought!) I found "Use ColdFusion Event Gateway Adaptor".
This chapter was the most clear of any other information I found on getting started. It walked me through several steps of creating a Flex app that could send a message to ColdFusion and how to use ColdFusion to "push" data back up to Flex clients.
The first thing the instructions had me do is edit the FDS messaging-config.xml file. For some reason which is not yet clear to me, I’ll need to edit configuration files all the time with FDS. I believe that this is because although FDS is a server, it’s treated like a framework or an API. For instance, a lot of people gripe about having to create and edit Reactor’s XML file. I suspect that it’s the same basic concept. Before it can do anything, the server needs to be told what and how to do it. IOC, baby.
After attempting to get FDS setup I created an instance of the Flex Messaging event gateway in ColdFusion. Honestly, I don’t have any experience with this either. I couldn’t explain why, but I’ve always boycotted event gateways. I think my logic was that if I can’t use them across the board on any instance of ColdFusion then they’re too much trouble. That, and I hate needing to use the ColdFusion admin to setup event gateways!
(Now anyone who’s been paying attention may have noticed my contradiction: I hate editing XML to configure FDS and I hate using the UI to configure ColdFusion. That’s right! I want both of them to magically just know what I want without any extra effort on my part. Seriously though, I’d like configuration to be a part of my application, not stored in some external server. But, given the option between a UI and XML, I’d choose XML, so long as I understood it well.)
So, getting back on topic, I created a new instance of the Flex Messaging event gateway. And, from what I can tell, it doesn’t take a lot of work. You just give it an ID, point it at a CFC, and turn it on. Fun!
From there the docs took me through the process of creating a Flex UI for sending an email. The documentation provides all the code, which I simply copied and pasted into my app. As a part of this, you create instances of a messaging Producer and Consumer objects. These objects know how to create and listen for messages from the Flex server.
So, when I’m using the UI to send an email, when I click a send message button it runs some Actionscript that creates a message to send, it populates the message with important information an then uses the message Producer to send the message on down to FDS. FDS then presumably broadcast the exact same message out to all other clients that have an interest. Because of this, the Flex Messaging event gateway receives the message and passes it on down to the CFC I configured it to use.
The CFC that receives the message has a method, onIncomingMessage, which I assume is an interface requirement defined by the Flex Messaging event gateway. The CFC the docs had me write receives the message as a part of the arguments passed into this method. I use information pulled out of the message to send an email and, once that’s done, I send a message back to the Flex Messaging event gateway.
This is where it goes south for me. If I run my application I can type in all the details of the email in the Flex client and, when I click to send the email I can watch the message as it gets spooled by CF and sent out. However, CF never successfully makes the call back to the FDS server.
I’m running both FDS and ColdFusion from the command line so I can watch the resulting messages for debugging purposes. Initially the CF server was reporting an error related to the gateway message. I was able to work around that. (I don’t remember exactly what I did, but I think I shut down both servers and restarted Flex then ColdFusion.) Once that issue was fixed I saw another warning being reported by FDS:
[Flex] [WARN] HttpFlexSession has not been registered as a listener in web.xml for this application so no events will be dispatched to FlexSessionAttributeListeners or FlexSessionBindingListeners. To correct this, register flex.messaging.HttpFlexSession as a listener in web.xml.
Because this is a warning and not an error I probably would typically ignore this. However, my Flex client was not receiving messages sent from ColdFusion. Based on the error message, the fact that CF is sending the message without errors and that the Flex client isn’t getting the message, I suspect that there’s a configuration problem where FDS won’t send messages to clients served over HTTP.
I haven’t yet been able to work though this. I’m not familiar enough to know what it means to register HttpFlexSession in the web.xml. First off, there are no less than four web.xml files in the FDS folder under JRun. Two of these have this block of XML in them:
&lt;!-- Http Flex Session attribute and binding listener support --&gt; &lt;listener&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;listener-class&gt;flex.messaging.HttpFlexSession&lt;/listener-class&gt; &lt;/listener&gt;
Not knowing what I’m looking at, it’s easy to assume that flex.messaging.HttpFlexSession is already registered. But, I don’t know! Googling any of this doesn’t result in anything useful.
So, that’s where I’m stuck. I can send messages to CF from a Flex client, but not the other way. As I work this out I’ll blog more and maybe it’ll be of use to someone in the future.