Friday, January 4, 2013

BlazeDS Error with an Illogical Fix

I've been having nothing but problems with BlazeDS lately, and I wanted to share an oddity I came across.

Configuration errors are the bane of my existence.  I don't want to know how BlazeDS works under the covers, it always just works.  That's why I use it, plus it's integration with Adobe ColdFusion and Grails (if you use the BlazeDS plugin).

For the past few days I have been receiving the error:
[BlazeDS]Exception occurred during serialization: java.lang.NullPointerException
NPE errors are always so helpful.  The basic setup is that CF sends an Apache Flex client messages.  Message1 occurs when a user signs in.  I notify the CF server via a RemoteObject call, and it then pushes a message out to all connected clients using BlazeDS the ColdFusionGateway channel.  This is working great and the Flex client receives the message via a consumer subscribed to an AMF polling channel.

The message in question occurs when a new person joins a group chat.  I send a DTO to CF via the sameRemoteObject, and then the CF sends a message to all clients that care about this specific group chat.  This fails with the above error when the client polls for its messages.  I am however, able to send the message from a browser test file through the same gateway and Flex receives the message and everyone is happy.

If I make the same call from Flex and disregard the DTO sent from Flex, creating my own DTO on the server side, I also get the error above.

What is weird is the first case works, and the second case does not.  The fix was to go into the config file that ColdFusion uses in its gateway config {cfroot}/WEB-INF/cfusion/gateway/config/flex-messaging-gateway.cfg and comment out the line "host=localhost".

The config file states:
# [Optional] The hostname or IP address of the Flex server.
# If omitted, the Flex server is expected to be installed as part
# of ColdFusion.  Specify 'localhost' if Flex is on this machine but
# not installed as part of ColdFusion.
I don't know what it means to install Flex as "part of ColdFusion" but the Flex client is running from the debugger, so it is definitely not part of ColdFusion.  I don;t think there has been a Flex Server component since version 1.5.  If they mean BlazeDS or Flash Remoting, then, maybe?  Either way, the configuration help needs improved upon.

While I can't explain what is going on here, I can at least provide the above solution so that someone else can save the 4 days it took me to figure this out.  Enjoy!

Thursday, January 3, 2013

ColdFusion 9 and ColdFusion 10 Together - Behind Apache HTTP Server

I have several projects using Adobe ColdFusion 9 and a new one starting on CF 10, so I needed to get CF 10 (running on Apache Tomcat of course) behind an Apache HTTP server.  I was having some issues finding anything via Google, but hidden behind a dead page that I could view only in text-mode via the cache was this gem from one of Adobe's ColdFusion engineers, Kavya: Co-existence of ColdFusion9 and ColdFusion10 using Apache web server

I was running a beta version of ColdFusion 10 so I had some issues initially, where the CF 10 instance ignoring the DocumentRoot directive and pushing me into the {cfwebroot}/cfusion/wwwroot directory.  One I reinstalled the latest release all was fine.

Two notes from Kavya's post:
  1. If you are not familiar with Apache HTTP server and are setting it up on multiple ports, you'll need to add Listen directives inside your httpd.conf file (e.g. Listen 81), one port per line.
  2. I set mine up all listening on port 80 and it worked beautifully.  Not sure if anyone still needs the workaround with multiple ports.
 Hope this cross-post will help Kavya's post get some traffic, as I couldn't find it on Google.