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!

Freitag, 23. Oktober 2009

My first Google Wave robot: Talk Like a Pirate!

A few days ago I published my first Google Wave robot, just for fun and getting into it. All it does is substitute your blips into pirate language -- YARRR! ;-) You can try it by adding talk-like-a-pirate@appspot.com to your wave.

An advice upfront: please don't add it to public waves without permission ... you might easily upset people by turning them into pirates! :)

Mittwoch, 21. Oktober 2009

Testing gadgets outside Google Wave

Here are two sites which will help you test your gadgets outside Google Wave:

Dienstag, 20. Oktober 2009

Starting with Google Wave development

Let me just give you a short list of articles you should read and software you will need to install. This is how I started and should be enough to get you going:
  • For a general overview, you should start here: Google Wave API - questions like What is Google Wave? and What is the Google Wave API? are covered here. Be sure to watch the video of the Google I/O Keynote Address, this is the demo which got us all excited. :-)
  • Developers should head right here: Google Wave API Overview - this is where the basic concepts of Google Wave are explained. Generally speaking there are two ways to extend Google Wave: by robots -- programs which are participants of a wave -- or gadgets -- small applications which can be embedded into a wave.
  • If you're thinking about developing a bot, you should read Google Wave Robots: Overview and the excellent Google Wave Robots: Java Tutorial.
  • You will of course need to have a recent version of Eclipse installed, at least version 3.3 (Europa).
  • You will need the Google Plugin for Eclipse, which allows you to upload your applications to AppEngine. See the Quick Start Guide for installation instructions.
  • Wave robots are web applications and must be hosted on Google's AppEngine, for which you will need to create an account before you can upload and test your robot. Beware that you can only create a maximum of ten applications of which you can't change the name later! Every application has a unique URL, such as http://my-wave-bot.appspot.com, therefore it is a good idea to (A) think wisely when choosing a name and to (B) reserve at least one application for testing and on-going development!
  • Finally you'll need to download the Google Wave API and related libraries, which you'll need to put into your WAR's lib directory. Be sure to visit the download page from time to time and update your libraries. Especially during the preview phase the API is still being changed and bugs are fixed continuously.
That's what it took me to get started. More on my first robot in the next post ... happy waving!

Essential developer gadgets: CodeSnippet Gadget

Harry Denholm published a useful gadget which allows you to insert code clippings into your waves with full syntax highlighting. Here's how it looks like:


I'd say that's an ideal solution to discuss code online. Here's the wave containing the installation link.

Montag, 19. Oktober 2009

How to find a public wave

With yesterday's update Google changed the way to find public waves. You'll need to update your search queries, substituting with:public by group:public@a.gwave.com.

What might seem strange at first is actually a step into the right direction:
  • Searching for public waves is more straightforward now, since with:public was basically just a hack.
  • It looks like Google is enabling group-based waves by integrating Google Groups. It will be exciting to see where that goes.
Happy waving ...

EDIT: Apparently with:public works again. Hmmm, me no like. ;-)