Thursday, December 3, 2009

Fix MessageBroker/AMF error with BlazeDS and Tomcat

As part of a project I am working on, my team is building a dashboard using Adobe Flex that interacts with a back end database. The complete stack we are using is Adobe Flex, BlazeDS, Spring, Hibernate, Oracle 10g. Adobe Flex provides the rich platform for developing the dashboard. BlazeDS serves as the messaging broker between the Flex front end and Spring. Spring is a framework that we are using to perform our necessary business logic. Hibernate is a persistence layer for maintaining connections with the database. Oracle 10g is the database we are using to store our data. We are using Apache Tomcat 6 as our web/application server running on Ubuntu 9.04.

To build the project my team has been using a combination of two IDEs. Adobe Flex Builder is the primary development tool for building the dashboard. That code is then added to a project created using MyEclipse. We have been using MyEclipse because it provides for a very simple way to integrate Spring and Hibernate into a Java Web project. From there we can replace the contents of the WEB-INF and META-INF directories with the BlazeDS equivalents.

Our project would build and run perfectly on a local machine. The problem we ran into was that when we moved the built .war file to the server we would see a MessageBroker/AMF error when the dashboard tried to contact the database. This was our error:
code:
Client.Error.MessageSend

Message:
Send failed

Detail:
Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed:
url: 'http://{server.name}:8080/{context.root}/messagebroker/amf'

After a lot of digging and frustration we found the problem to be the version of Tomcat6 that we were using. On our server we installed Tomcat from the repositories. That version does not support the necessary messaging services to use with BlazeDS. Instead, install Tomcat according to the instructions in this post.

Now, test if the messaging service is working by deploying your application, restarting Tomcat, and then navigate to: 
http://{server.name}:{server.port}/{context.root}/messagebroker/amf
You should see a blank page. If you see anything else it is not working correctly.

Verify that you have a channel setup for messaging in {context.root}/WEB-INF/flex/services-config.xml. It should look similar to this:
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled&gtfalse</polling-enabled>
</properties>
</channel-definition>


If you are still having problems, here are some of the other resources we came across. They didn't fix our problems but they might help fix yours:
http://forum.springsource.org/archive/index.php/t-68405.html
http://adityac1984.wordpress.com/2009/04/23/set-up-blazeds-on-tomcat-with-eclipse-for-flex/ 

A big thanks to this post for solving our issue and to my team mate Phil for not giving up until this was working.

No comments:

Post a Comment