Addy is in software development at UBS working on ETD trade management systems. He has previously worked in technical consultancy for 10 years and have enjoyed working with clients/verticals ranging from media, hospitality, energy to finance. In his spare time he loves trying out new Java based technologies especially open source frameworks like Apache and Spring. Aditya has posted 4 posts at DZone. You can read more from them at their website. View Full User Profile

Using JSF 2 with Google App Engine

11.25.2009
| 26511 views |
  • submit to reddit

Since last week I have been playing with Google App Engine (GAE) and some of the frameworks that we normally use in enterprise applications. After developing some basic servlets to get comfortable with appspot I decided to use JSF 2. I wanted to see how well it fits in GAE aware of the fact that there are quite a few caveats mentioned on GAE website regarding JSF. I followed the obvious steps mentioned on the help pages but I think they are a bit outdated.

I decided to compile a list that one can follow to successfully get JSF 2.0.1 (Mojarra) working on GAE 1.2.6. If you have followed steps provided elsewhere and are still getting the following errors beware that you might have missed one or more of the setting provided.

Resources

  1. Will it play in GAE - Gives of list of technologies which are supported on GAE
  2. Configuring JSF 2 in GAE - Configuration provided by Google but this doesn't work straightaway
  3. JSF 2 Compatibility Issues - Compatibility issues with JSF 2
  4. JSF 2 impl jar fix - Josh has kindly provided a fix for JSF impl jar which resolves the startup problem

Setup steps:

  • Follow the steps provided in the jsf configuration guide on GAE website (see Resources:2)
  • Replace the jsf-impl.jar with provided on Josh's blog page . Stack trace fixed

 

WARNING: Error starting handlers Throwable occurred:
java.lang.NoClassDefFoundError:javax.naming.InitialContext

 

  • Now you app should start up on dev box but it when you deploy it on GAE you will get the following stack trace (lower the level to debug or warning)

 

Nested in javax.servlet.ServletException: java.lang.RuntimeException: java.lang.ClassNotFoundException: void:
java.lang.RuntimeException: java.lang.ClassNotFoundException: void
 at com.google.apphosting.runtime.jetty.SessionManager.deserialize(SessionManager.java:389)
 at com.google.apphosting.runtime.jetty.SessionManager.loadSession(SessionManager.java:307)
 at com.google.apphosting.runtime.jetty.SessionManager.getSession(SessionManager.java:282)
 at org.mortbay.jetty.servlet.AbstractSessionManager.getHttpSession(AbstractSessionManager.java:237)
 at org.mortbay.jetty.Request.getSession(Request.java:998)
 at com.sun.faces.application.WebappLifecycleListener.syncSessionScopedBeans(WebappLifecycleListener.java:393)

 

  • In order to fix the above exception make sure following configuration are in web.xml (These are recommendations from GAE JSF2 compatibility issues: see Resources:3)

 

<!-- Seems like GAE 1.2.6 cannot handle server side session management. At least for JSF 2.0.1 -->
  <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
<!-- Recommendation from GAE pages  -->
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
  </context-param>

 

  • Finally, I have noticed that sometimes objects kept in session loose data. For instance, I created a session scoped managed bean called CustomerBean and added customer name and email to it. When I move to second view, the name and email address stored in the managed bean are lost. Now this happens only on appspot not on the dev server so I can't debug and I haven't yet figured out why it this happens. I am working on a strange hack which put a token key value in the session in every request which solves the issue but I am sure why.
    If anyone has any clue why please post a comment.

Hopefully, these setting will get you started on your first JSF 2 app on Google App Engine.

Published at DZone with permission of its author, Aditya Bhardwaj.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Jose Maria Arranz replied on Wed, 2009/11/25 - 11:53am

When I move to second view, the name and email address stored in the managed bean are lost. Now this happens only on appspot not on the dev server so I can't debug and I haven't yet figured out why it this happens

Fixing this bug could help you, please vote for it.

 

Sergio Valdez replied on Tue, 2011/01/25 - 1:49pm

Thanks a lot, This is helpfully

Gilberto Da Sil... replied on Sun, 2011/09/04 - 3:46pm

Good post, but I have the same problem of lost of data.

Vamsi Krishna replied on Sun, 2014/11/02 - 7:24am

Its a great post google app engine is really helpful ssc results 2015 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.