My name is Sébastien Arbogast, I’m 27 and I’m a freelance Software Architect and Developer based in Brussels, Belgium. My main specialties are agile methodologies, rich internet application, highly productive Java development and iPhone development. Sebastien is a DZone MVB and is not an employee of DZone and has posted 26 posts at DZone. You can read more from them at their website. View Full User Profile

Grails BlazeDS 4 Integration Plugin

01.29.2010
| 11984 views |
  • submit to reddit

One of the main goals I’ve been pursuing for a few months is the integration of Grails with Flex 4. I need to rework ConferenceGuide’s administration backend to make it more ergonomic so that we can cover more events, and ever since I discovered Flex 4 niceties, I couldn’t think of doing that with anything else. The problem is that none of the existing plugins suited my needs.

All of them cover Flex 3 only, some of them introduce a lot of complexity for CRUD generation, some of them use GraniteDS instead of BlazeDS, and the simplest plugin, grails-flex has never gone further than the experimental stage. I did a lot of experiments, talked a lot about it on Grails mailing lists, until Tomas Lin kindly explained to me that maybe I was approaching it the wrong way. I wanted a plugin that would set up a complete environment for Flex development right in the middle of my Grails application.

And I wanted that because I wanted to avoid using Flash Builder (you know… Eclipse… ierk!), mainly because the only advantage of Flex Builder 3 over IntelliJ Idea was the visual designer. But he was right, I was wrong. Flash Builder 4 DOES change everything. It does include a lot of very interesting features that greatly improve Flex development productivity, especially when it comes to integration with backend technologies. And for those features, I can only admit that IntelliJ is not up to par yet. I’m still gonna use it for the Grails part, but Flash Builder will be my environment of choice for Flex 4.

So, once I learnt more about Flex 4, BlazeDS 4 and Flash Builder 4 beta 2, it was time to reconsider my approach and develop a much simpler Grails plugin so that any Grails application could be used in combination with Flash Builder. I just released grails-blazeds plugin to do just that. Here is how it works:

  1. Install grails-blazeds plugin: “grails install-plugin blazeds”. This plugin copies a couple of configuration files into your application and imports all of the required libraries, including BlazeDS 4 and Spring-BlazeDS integration 1.5, both in nightly snapshot versions, since they have not been officially released yet
  2. Create a service to be exposed to your Flex application over AMF, or choose an existing one
  3. Add @RemotingDestination annotation to your service class, and @RemotingInclude annotation to all of the methods in this service that you wish to expose
  4. Edit web-app/WEB-INF/flex-servlet.xml (created when you installed the plugin): uncomment the context:component-scan element and set the base-package corresponding to your service class
  5. Make sure your exposed service methods don’t use Groovy classes, either as argument or return types. This is a known limitation I’m still working on, but if there are some Groovy classes here, Flash Builder doesn’t manage to generate ActionScript counterparts.
  6. Run your Grails application using “grails run-war” instead of “grails run-app”. Once again this is a known limitation: Flash Builder BlazeDS data connection plugin relies on a classical web app layout and doesn’t understand Grails dynamic layout (that is until someone manages to create a Grails data connection wizard for Flash Builder 4)
  7. In Flash Builder 4 beta 2, create a new Flex project with a J2EE server. Here are what your parameters shoud look like, “conferenceguide” being the name of my Grails application and “sarbogast” being my home directory:

  8. Click “Data” menu, then “Connect to BlazeDS…”
  9. In the “Authentication required” dialog box that appears, check “no password required” box, and click OK
  10. You should see your service appear, and you can select it and click Finish.

  11. Your service should appear in the Data/Services view. You can then compose your user interface and drag and drop your service methods to the relevant components to connect them with your Grails backend.
  12. Don’t forget to configure a channelset on your service:

    <adminservice:AdminService id="adminService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true">
    <adminservice:channelSet>
    <s:ChannelSet>
    <s:AMFChannel uri="http://localhost:8080/conferenceguide/messagebroker/amf"/>
    </s:ChannelSet>
    </adminservice:channelSet>
    </adminservice:AdminService>

And there you go. Special thanks to James Ward, whose screencasts really helped me get it right. Now the only thing that this plugin misses, beyond the 2 known limitations, is integration with Spring Security, but this is just a start.

Enjoy!

From http://sebastien-arbogast.com

Published at DZone with permission of Sebastien Arbogast, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Nick Collins replied on Fri, 2010/01/29 - 7:08am

Have you found a way to get around the problem of not being able to directly serialize your domain objects without encountering LazyIntitializationExceptions? I know Jeremy Grelle was working on this with Spring-Flex, but didn't know if he had successfully implemented it yet.

Void Main replied on Fri, 2010/01/29 - 5:42pm

good article, I've always wanted to know if there is flex4 plugin in grails, and I'm glad I find there is one in your article, I have a question where is the document URL for this plugin and is it working for grails 1.1?

 thanks

Manuel Jordan replied on Sat, 2010/01/30 - 8:08am

Good work Sébastien

Thanks for this work

Guy Gavriely replied on Fri, 2010/02/19 - 4:42pm

Hi, would it be possible to share a sample application? thanks, guy

Tami Wright replied on Fri, 2010/04/02 - 3:00am

Sebastien,

 I was looking at your plugin to use with our project but I can't get the grails app/project to compile with the @RemotingDestination and @RemotingInclude annotations.  I'm using Grails 1.2.0.  Any suggestions or insights to offer?

Also, we've currently got the Grails Flex Scaffolding plugin installed.  Do you happen to know if there are collisions or issues between your plugin and GFS?

 Tami

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.