Wicket on Google App Engine

http://stronglytypedblog.blogspot.com/2009/04/wicket-on-google-app-engine.html

2. Add Wicket jars
Add the following jars to the war/WEB-INF/lib directory and add them as external jars to the eclipse project:

- wicket-1.3.5.jar
- slf4j-api-1.5.2.jar
- slf4j-log4j12-1.4.2.jar
- log4j-1.2.13.jar



3. Turn on logging
Turn on logging, so that you can see any strange things, that may occur. App Engine won't tell you much by default.

- log4j.properties: log4j.logger.org.apache.wicket=DEBUG, A1
- java6 logging.properties: .level = INFO

4. Create a Wicket Application and a Page
Add WicketApplication.java
  1. package wicket;  
  2.   
  3. public class WicketApplication extends WebApplication {  
  4.    public Class getHomePage() {  
  5.        return HomePage.class;  
  6.    }  
  7. }  

and a simple HomePage.java and HomePage.html:
  1. public class HomePage extends WebPage {  
  2.    public HomePage() {  
  3.        add(new Label("label"new Model("Hello, World")));  
  4.    }  
  5. }  



5. Set up WicketFilter
Add the Wicket servlet filter to web.xml. Alternatively use WicketServlet:
  1. <filter>  
  2.  <filter-name>WicketFilter</filter-name>  
  3.  <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>  
  4.  <init-param>  
  5.   <param-name>applicationClassName</param-name>  
  6.   <param-value>wicket.WicketApplication</param-value>  
  7.  </init-param>  
  8. </filter>  
  9.   
  10. <filter-mapping>  
  11.  <filter-name>WicketFilter</filter-name>  
  12.  <url-pattern>/wicket/*</url-pattern>  
  13. </filter-mapping>  



6. Add HTTP session support
Enable HTTP session support (by default it's disabled) by adding the following line to appengine-web.xml:
  1. <sessions-enabled>true</sessions-enabled>  


Now the app is ready to run, but there are still some issues.

7. Disable resource modification watching
When Wicket is started in development mode now, exceptions are raised because Wicket spawns threads to check resource files such as HTML files for modifications. Let's just disable resource modification checking by setting the resource poll frequency in ourWicketApplication's init() method to null.
  1. protected void init() {  
  2.    getResourceSettings().setResourcePollFrequency(null);  
  3. }  

8. Disable SecondLevelCacheSessionStore
We cannot use the SecondLevelCacheSessionStore in the app engine, which is the default. At least not with a DiskPageStore, because this serializes the pages to the disk. But writing to the disk is not allowed in the app engine. You can use the simple HttpSessionStoreimplementation instead (this increases HTTP session size), by overriding newSessionStore() in our WicketApplication:
  1. protected ISessionStore newSessionStore() {  
  2.    //return new SecondLevelCacheSessionStore(this, new DiskPageStore());  
  3.    return new HttpSessionStore(this);  
  4. }  


9. Run
From the context menu of the project, call Run As -> Web Application. Open http://localhost:8080/wicket/ in your browser and see the app running.


Download the demo as an eclipse poject.
Comments