Just finished configuring BlazeDS with Spring! 🙂
We have been thinking to include Flex in our J2EE application for a few months now. We believe integrating Flex as a client end application will vastly improve user experience and also improve on the code separation if we can design properly. BlazeDS is a server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Flex applications. Both BlazeDS and Flex are open source products from Adobe.
After running the samples provided with BlazeDS download, I decided to have a go at it by trying to integrate it with Spring. Unfortunately I could not find any straight forward tutorial that could have guided me step by step. The closest I got was this tutorial that talks about integration of Spring with Adobe LiveCycle Data Service. Although I had to customize in few places, the tutorial was really helpful for my purpose.
BlazeDS download comes with a configured tomcat ready to run, which is pretty cool by the way! 🙂 Anyway, I chose to integrate Spring in the already deployed blazeds application under {blazeds}/tomcat/webapps. I followed all the steps of Example 1 in that tutorial considering my context root is {blazeds}/tomcat/webapps/blazeds. For example, when it asked me to copy jar files of Spring, I copied them to {blazeds}/tomcat/webapps/blazeds/WEB-INF/lib directory.
When it was time to run the application, as mentioned in Step 4, that didn’t work. The step asks to directly invoke the mxml file and assumes the Data Services application will compile it. I don’t think BlazeDS was configured for that feature yet. Therefore I had to take the help of Flex Builder 3 to compile the mxml file. I took the help of this tutorial to configure and create a J2EE project in Flex Builder. I followed all the 14 steps mentioned at the bottom of the page to create the project. I had to start my tomcat server to successfully validate the project configuration. Once that was done, rest was a piece of cake! The run button in Flex Builder automatically deploys the compiled swf file and opens it in browser.
Once my initial experiment was successful, I decided to create a formal project where I can work and use Ant to build and deploy my work. This is where things started to get rough! More on that later. So my first task was to write an Ant script that would deploy the necessary files in web server so that BlazeDS is deployed along with my project. I took the help of this nice and simple page to quickly get started with Ant. Then I had to install and configure Flex Ant Tasks and use it inside my build.xml to compile the mxml files. Once my script was ready, I thought I was done. But alas! the application was not working anymore. Remoting from my swf failed, it could not connect to the Spring service bean. After couple of hours of hair pulling time, I finally figured that the only difference between my current work and previous work (which ran successfully) is the compiled swf. Since we have to show the data service while creating a data service project, the Flex Builder must be doing something while compiling that my simple compile command was not doing. Once the problem was found, I looked into the compile command (mxmlc) in detail and found that I had to add -services and -context-root parameters to my mxmlc command. -services points to the services-config.xml file while context-root is the name of the context root, in my case – /blazeds. Then I used another build in ant task named html-wrapper that creates an html file for the corresponding swf, which makes it easier to view when deployed in web server. My Ant tasks now looks like this –
<target name=”compileflex”>
<mxmlc
file=”${web.dir}/mxml/main.mxml”
output=”${build.dir}/main.swf”
services=”${web.dir}/WEB-INF/flex/services-config.xml”
context-root=”/blazeds”
keep-generated-actionscript=”true”>
</mxmlc>
</target>
<target name=”wrapper” depends=”compileflex”>
<html-wrapper
title=”Welcome to My Flex App”
height=”300″
width=”400″
bgcolor=”red”
application=”app”
swf=”main”
version-major=”9″
version-minor=”0″
version-revision=”0″
history=”true”
template=”express-installation”
output=”${build.dir}”/>
</target>
Flex is cool to work with and I can’t wait to dive in deeper! Next stop is to find out how BlazeDS handles authentication and how can I get access to HttpSession.
Read Full Post »