Wicket and App Engine - How to avoid loading Wicket on startup

Thursday, 23 September 2010

A GAE app of mine (www.chesspresso.net) which is a backend to an Android app that most requests come via other code rather than through Wicket. Wicket is my chosen framework which I use to display the front-end of the application (the website!). And most of the requests to the application does not require wicket.

As I'm sure many GAE users know, the startup time is a big problem especially for low traffic apps, and having to load a framework such as Wicket on startup is damaging to the request time for an App.

To avoid having to start the WicketFilter every time the app starts I have extended the WicketFilter to only initialize when the first Wicket page is hit:

public class RequestWicketFilter extends WicketFilter
{
   private static boolean  requestMade = false;
   private static boolean  initialized = false;
   private static FilterConfig fConf;

   @Override
   public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
   {
      if (!requestMade)
         requestMade = true;

         init(fConf);
         super.doFilter(req, res, chain);
   }

   @Override
   public void init(FilterConfig fC) throws ServletException
   {
      if (fConf == null)
         fConf = fC;

      if (requestMade && !initialized)
      {
         super.init(fConf);
         initialized = true;
      }
   }
}