Sonntag, 8. November 2009

How to run JSF 2.0 web applications on Google App Engine

The good news first: actually there's not much difference between setting up a JSF 2.0 web application for Google App Engine compared to using your regular application server of choice. However, Google's App Engine environment comes along with some constraints which have to be accounted for when configuring your application. There are basically two areas which have to be addressed: multi-threading and session handling.


What needs to be configured?

  • App Engine doesn't allow applications to create new threads. Since JSF frameworks make use of multiple threads per default you'll have to disable this behavior.
  • Session management: JSF relies on HTTP sessions for saving states, which are not enabled by default in App Engine.
  • State saving: the current release of JSF 2.0.1 has an issue with server-side state saving. Until that problem is resolved you will have to resort to client-side state saving.

All things just mentioned can be achieved by simply setting a few parameters in WEB-INF/appengine-web.xml and WEB-INF/web.xml.


Setup

Basically you should follow Derek Berube's great tutorial: Configuring JavaServer Faces 2.0 to run on the Google AppEngine. Just two things to note: you can't download "Apache Xalan-J 2.9.0" -- there is no such version (yet). Instead you must download Xalan-J 2.7.1. Also, you should download the most recent JSF version, which is JSF 2.0.1 at the time of writing. After setting up your project the way it's outlined in the tutorial, all that's left to do is to enable client-side state saving by adding the following parameter to WEB-INF/web.xml (more details on that here):

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>


That's it! You should be able to deploy and access your JSF 2.0 application now.


Troubleshooting

After uploading a version with changes to backing beans, you may find that when accessing your application you will simply get an empty page as result. This happens because the classes stored in the session are now incompatible and cannot be deserialized any more. (It shows up in your log as an InvalidClassException.)

Too bad there's no error message displayed in your browser. To fix this problem you'll need to restart your browser.


What about JSF 1.2?

It's a pain to get it working. Take for example the fact that Sun's reference implementation accesses InitialContext at startup, which is a restricted class in App Engine. Not a good start. You can fix this of course: by downloading the respective source code and commenting out the offending code, but come one ... I've read reports stating that MyFaces 1.2 seems to work, but I didn't care to try that. Instead I'm using JSF 2.0.1 for my GAE projects now. It is stable enough for my purposes, fixes many of JSF 1.2's annoyances, is much easier to configure via annotations and works (almost) out-of-the-box.

Freitag, 6. November 2009

Talk Like A Pirate Robot: List of Translations

The current list of translations supported by the robot is now available in real time. BTW: I'm always open to further suggestions!