I recently wrote a gift list management site for my family using Grails. Grails made it simple, the entire site was done in less than a week. That was version 1 of the site. In version 2 of the site, I rewrote the Ajax’d GSP’s using Flex 3, since I spent over 16 frustrating hours trying to get IE 6 and IE 7 to display the Yahoo accordion panels correctly with the GSP pages. The conversion was relatively straightforward, and the ease of sending and receiving XML and JSON message between Grails and Flex made the server side dead simple. Most of my time was spent browsing Flex API documentation to get the UI to behave how I wanted it to.
Version 2 of the site, with Flex and Grails, is ready to be deployed, but I found the lack of Java hosting options to be frustrating. This is still one reason that PHP is still so popular, because PHP is enabled by default on most web servers, including the one that hosts this blog. The best Java hosting I found is here, it gives you a private Tomcat instance with 4GB RAM. I’d rather just host it at my house, but my upload speed is too low for a lot of clients. This led to version 3 of the site, which was to replace the Grails back end with Google App Engine, using Groovy. Google App Engine offers free Java hosting in a cloud environment.
Version 3 took a large amount of time compared to the first two. And yes, I tried the Grails GAE plugin, but is does not support GORM yet, and my app used many of the GORM features. Most of the time was spent writing a data access layer for JDO in replace of the missing GORM features. I’m interested in how hard it would be to replace GORM’s use of Hibernate with JDO instead.
I also ran into a couple of issues with the current Google App Engine SDK.
- Keys and JDO entities
You need to use Key and not Long for the PrimaryKey of a parent entity, else you will hit this defect. You also need to make sure that any unowned relationships are Key and not the entity type if you plan on setting the relationship after object creation. So in my application, I have a GiftPurchase entity that has a purchaser and recipient, both of type User, and these are managed as Keys and not User:
@PersistenceCapable (identityType = IdentityType.APPLICATION, detachable = "true")
class GiftPurchase {@PrimaryKey
@Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
Key id@Persistent
Key purchaser@Persistent
Key recipient@Persistent
Date purchaseDate
}
- Flex and SSL with Google App Engine
If you have any requests that need to happen over SSL (https), you cannot load the Flex asset, such as a swf, over http, you need to load it with https, and then setup Google App Engine to require https for certain URL patterns. You also need to have a crossdomain.xml file at the root of the war if you want to allow Flex to send non-encrypted messages over http:<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “/xml/dtds/cross-domain-policy.dtd”>
<cross-domain-policy>
<site-control permitted-cross-domain-policies=”all”/>
<allow-access-from domain=”*” to-ports=”*” secure=”false” />
<allow-http-request-headers-from domain=”*” headers=”*” />
</cross-domain-policy></blockquote>
- The GAE Development server behaves differently in certain cases than the actual Google App Engine
One difference I ran into is that you cannot set session attributes of non-serializable objects, so you cannot put JDO entity objects in the session.Bad:
session.setAttribute('user', new User())Good:
session.setAttribute('user', new Long(user.id))
Despite these issues, the Google App Engine is a nice platform. Not having to provide your own SSL certificate, getting free hosting, and being able to use parts of Java are nice. Groovy and other languages work with the SDK, so you are not bound to the verbosity of Java. Grails is still more attractive in terms of development speed, so hopefully GORM support for the GAE plugin gets completed soon. So for those of you that clicked on the link to the site, that is version 3 and is run with Google App Engine server side and Flex on the client.