Posts mit dem Label eclipse werden angezeigt. Alle Posts anzeigen
Posts mit dem Label eclipse werden angezeigt. Alle Posts anzeigen

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.

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!