Jun 15, 2009

Railo, FlashBuilder and Flash remoting - It works!

The Railo team has been hard at work pushing out updates quicker then we can install them - well not really as it only takes less then a minute to upgrade Railo :) . One of the most recent and exciting updates that has come out with 3.1.0.15 and .16 preview is the ability to communicate with Flex over AMF the same way you can with ColdFusion.

Here is a run through of how I set this up. As I run ColdFusion and IIS on my local machine to duplicate our main production environment I really didn't want to mess with all my settings and didn't want 2 CFML engines running all the time I opted to install ( extract from zip ) the Express Edition of Railo so I can start and stop easily with a batch file.

I extracted the zip to e:\RailoExpress

Copied the E:\RailoExpress\webroot to E:\RailoExpress\wwwroot ( to mirror ColdFusion's directory structure )

Start the Railo express server by running the "Start.bat" file. Confirm Railo is running by hitting http://127.0.0.1:8888 and confirm that http://127.0.0.1:8888/flex2gateway returns a blank page.

Open Flex(Flash)Builder. Created a new Flex Project.

Selected the server type as "ColdFusion", click next.

This is where there are a few changes. FlexBuilder expects there to be wwwroot in the ColdFusion server directory this is the reason I made the copy in step 2. I wont need to modify the .xml files in the WEB-INF for this example.

I'm not going to be using IIS as the webserver I'm happy with the one that comes with Railo express ( Jetty ) and the default port is 8888. Also set the webroot to the webroot folder under the Railo install directory.


Click finish and you can start coding.

If you want to check the compiler arguments right click the project, select properties, then Flex Compiler and it should look like this:


From this point I made a simple cfc that runs a query and returns it to flex. Drop the cfc into the webroot ( E:\RailoExpress\webroot ) called Query.cfc ( mappings work the same way they do in ColdFusion also )



I made a simple program to get the query data and display it in a grid. The code looks just the same as it would with ColdFusion. Also notice the source of the remote object is "Query" which matches to the name of the .cfc if you had this in a mapping it would be com.project.Query for example and this would work fine.



Demo:



Demo with source view can be seen here

The .16 update ( currently in preview ) fixed the issue where the column name's were always coming back as lower case now they are the correct case. It also addressed the issue of correct casing of VO's ( which is also working in my limited test cases ).

I picked a query as an example but all other data types seam to be working except a few odd ones ( I tried sending an image data blob back it didn't work....yet ) and all in all this will probably satisfy most people working with Flex and ColdFusion and now they can offer a slick backend to there clients as an alternative to ColdFusion.

The database is a sample from mySQL

8 comments:

  1. Nice write-up Paul, I'll be referring to this later when I start messing around with Railo a bit more for remoting.
    ReplyDelete
  2. Nice Paul! So glad Railo can now work with Flex in this manner. Will be looking to integrate it in the near future.
    ReplyDelete
  3. Nice Paul. I am going to play with this some more. good stuff
    ReplyDelete
  4. Definitely a step in the right direction. One thing to point out is that Railo does not yet support the serialization/deserialization of custom objects. For instance, if you use model it's not likely you are going to be able to work with Railo yet. The team is working on it, so hopefully we will see this soon!
    ReplyDelete
  5. Does this work in .15 or just .16? I downloaded .15 and deployed the war under tomcat, went to the following url and did get a blank page?

    http://localhost:8080/railofb4/ - Works
    http://localhost:8080/railofb4/flex2gateway - 404
    ReplyDelete
  6. It does work in .0.15 but the query will come back with column headers all in lower case same as VO's they only work as full lower case in .15 Railo team fixed this in 0.16 however.

    There are a few people working at setting up the BlazeDs mappings for jBows and tomcat on the Railo mailing list because I believe there are a few things you need to add to the web.xml that are already present in the Resin setups.

    http://groups.google.com/group/railo
    ReplyDelete
  7. Thanks for the help, I will post something on the Group!
    ReplyDelete
  8. For future reference here is the thread that solves Dan's 404 issue: http://groups.google.com/group/railo/browse_thread/thread/e02ba5bcd7274de9
    ReplyDelete