Grails and BlazeDS with a Flex UI

All of my spare time has been taken up with the Google App Engine project I mentioned before. As with all tech these days, the platform is a moving target. With the initial release of GAE only supporting Python I dived straight in to learning Python and the Django framework. Then they release Java as the second language for GAE. Java is my day job so this would have saved a lot of time at the start. Learning Python was useful but spare time is a limited resource.

Then I spent quite a lot of time writing an authentication system for it as the one supplied, that utilises Google Accounts, did not associate a Google account with a specific ID, just an email address which might change – not particularly useful. The latest version of GAE fixes this.

Oh well. I’m happy with what I have but I’m still a fair way from going live.

But, as you can tell from the title, I am dipping into a couple other ideas I have. One is for a utility that might help the company I work for with their distributed development model. I wanted a highly productive server framework and a rich UI so decided on a Flex front end and Grails with BlazeDS for the server side. It seemed ideal. Especially as I could use Grails with the Flex plugin. I tried the quick start guide and it worked straight away. Within 10 minutes I had a flex client that could call a BlazeDS remote service. Creating the service was childs play, it was fantastic.

Then I hit a snag thats held me up for a couple of days. The quick start guide gets you to create the Flex app as MXML and AS files inside the Grails app folder structure. This is served to the client by the Flex webtier compiler which compiles on the fly. Great for development but no good for production. (Well it should be great for dev but my app didnt compile properly – no errors it just didn’t work properly and I haven’t worked out why yet) . The main problem was, whenever I compiled a swf file the remoting stopped working. I’m using Flashdevelop for the Flex IDE not FlexBuilder. The latter app may make the reason for this problem obvious but it wasn’t to me.

Anyway the solution for me was:

When you install the Flex plugin and create remoting services a services-config.xml file is created in the “web-app/WEB-INF/flex” folder of your Grails app. The client Flex app needs to know about this file in order to get the channel definitions. To do that you have to copy the XML file to your Flex project folder (I had a config folder alongside the src folder) and then tell the flex compiler about it with the -services argument. So I added this argument to the compile command “-services config\services-config.xml”. In the XML file there are a couple of tokens and the compiler did complain about the “context.root” token so I had to hard code this value into the XML file. But having done that and then re-compiled I copied the generated swf file and associated webpage into the Grails webapp folder, started the application, navigated to that page and remoting started working again 🙂

Having got it working, this whole process of creating and consuming AMF remote services is incredibly simple and fast. Convention over config rocks.

Next to get the webtier compiler working for my Flex app…..

Leave a Reply

Comment spam protected by SpamBam

© Copyright 2007 - BoraDev Consulting