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!

No comments: