Tag Archives: Spring

Grails BlazeDS 4 Integration Plugin

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 developement 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!

Why Do I Hate Eclipse?

As a consultant, I’m very often forced to use Eclipse as a development environment, and every time I do, it’s such a pain for me that I can’t help complaining about the poorness of this thing. And every time I do, most of my team mates, who have been brainwashed by the monopolistic propaganda of Eclipse, just keep asking me what’s wrong with it. And sometimes it’s hard to explain because it’s really a matter of user experience. And each time I find a specific example, I get answers like “yeah, but that’s just one thing”, or “I’ve never had that, you’re not lucky”, or “this is just because you’re not used to the Eclipse way of doing things”, or even the worst one “maybe yes, but it’s free!”. Since when is “free” a feature?

Right now, I’m reading the SpringSource dm Server getting started guide, and I was very surprised to read that SpringSource guys, who aren’t exactly stupid, and seem very experienced with Eclipse itself as they have based all their development tools on it (Spring IDE, STS, etc.), talk about what they call the “Eclipse Dance”. I didn’t know about the expression but I’ve definitely danced it more than once: every now and then, Eclipse views get all mixed up, some views indicate errors in a file, while other views on the same file say everything is OK. Or you get a message saying that it cannot find a class where you have the source in front of your eyes. Or like now, I have 2 maven projects at the same level referencing the same parent POM, and one of the projects says it can’t find the parent artifact, whether the other one seems to find it without problem. And when that kind of things happen, the only thing to do is to try a combination of closing all projects and reopening them, clean all projects to force a clean build, or even restart the whole Eclipse workbench. WTF?

How can SpringSource support such a poorly designed environment while admitting such unacceptable bugs? Oh yeah right! It’s free, so everybody uses it. This is really the perfect example of when Open Source can also kill innovation instead of fostering it. It’s free so everybody uses it, including corporate customers, so all tool vendors base their tools on it (Spring IDE, Flex Builder, Weblogic Portal Workshop, etc.), so even more people use it (even if they have better tools in their bag), and we’re screwed.

I would love that framework vendors focus first on command-line integration with tools like Maven and Ant, and then provide IDE integration for a few popular environments, including Eclipse, Netbeans, and my personal choice, IntelliJ IDEA. This would reinforce competition between IDE vendors instead of killing it while considerably lowering the barrier to entry to their frameworks. Right now, SpringSource is lucky I really need to understand more about dm Server, because if it had been only for cusriosity’s sake, I would have given up already just because of the tight integration with this crappy Eclipse thing and all the pain I have to make it work consistently.

So if you’ve already been in that situation, and you start to think there’s gotta be a better way, try out IntelliJ IDEA.

PS: I’m not related to Jetbrains in any way. I just happen to be a very happy customer of theirs, happy to pay a few hundred bucks every year to get their latest version, because as a Jetbrains guy said it last year at Devoxx, “IntelliJ iDEA is the only IDE worth paying for.”

Flex, Spring and BlazeDS: the full stack! ERRATUM

OK, obviously there are 2 problems in my article on Adobe Developer Connection and I finally found the time to look into it:

First of all, there was a big error in one of the POMs in todolist3.zip. In todolist-web/pom.xml, if the first dependency looks like this:

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>todolist-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

Then replace it with this:

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>todolist-config</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>resources</classifier>
<type>zip</type>
<scope>provided</scope>
</dependency>

And it should work fine.

The second error is in the article itself: of course, all of the namespace declarations should be xmlns:mx=”http://www.adobe.com/2006/mxml” instead of xmlns:mx=”/2006/mxml” .

I’ll try to reach ADC editor so that they can fix those mistakes. Thanks for the feedback.

The Flex, Spring and BlazeDS full stack on Adobe Developer Connection

The last part of the reedition of my article series about Flex and Spring has been published on the Adobe Developer Connection. This episode is the last one in this improved series so if you haven’t read it yet on my blog, I think the version I gave to ADC is better.

Episode 1
Episode 2
Episode 3

Enjoy!

You dreamt of it? SpringSource did it!

3 months ago, the day SpringSource announced their acquisition of Covalent, the company behind Tomcat, I knew they were up to something. I even talked about it with Andrew Glover for JavaWorld. And now it’s real: SpringSource has just announced SpringSource Application Platform.

First off, a few links around this announcement:

Now this is very exciting. That’s the kind of inspiring technologies that make me think of tens of ideas for new projects, new tools that were just impossible before and that could now become reality. Adobe Flex had the same effect of unleashing my software artist imagination. Now I’m starting to think about combining the user experience of Flex applications on top of the ease of management, deployment and extensibility of OSGi with SSAP. Jeez, we’re living an incredible period!

Flex, Spring and BlazeDS: the full stack! (Epilogue)

Thanks to Brian E. Fox, I managed to avoid duplication of Flex remoting configuration files in this project. It requires a bit of additional configuration and I hope that Maven will soon provide a simpler way to do this simple resource inheritance thing. But in the meantime, this one will work.

I’m going to update my fourarticle series to include those modifications, but for those of you who have already gone through it before the update, here are the exact modifications you need to make to the project you got at the end of Part 4.
Continue reading Flex, Spring and BlazeDS: the full stack! (Epilogue)

Flex, Spring and BlazeDS: the full stack! (Part 4) [updated]

[UPDATE] This article series has been reedited on the Adobe Developer Connection. For more information, see this post.

In the previous articles in this series, we did the boring stuff of setting up Spring, Hibernate and MySQL on a sample todo list server on one side, and we wrote a small useless Flex UI on the other side. In this article, we’re going to write the final UI and connect it with the Spring backend using BlazeDS. Let’s go!
Continue reading Flex, Spring and BlazeDS: the full stack! (Part 4) [updated]