Today: February 14, 2025 9:38 pm
A collection of Software and Cloud patterns with a focus on the Enterprise

WordPress plugin licensing: Wicket on Google App Engine

For the user interface layer of the licensing system I was interested in using a framework like Wicket. It was a lot of work to setup. The process was made somewhat frustrating by the fact that most of Google’s results are a few years old and deal with older versions.

I did finally get it working and here’s the process. Other articles take the default Google App Engine project and modify it to accommodate wicket. I decided to go the other direction and start with the wicket quickstart. This is the process I followed and links to the resources that I used. Hopefully that makes this post age better. We’ll see 🙂

Add Maven support to Eclipse

Since I wanted to start with the current wicket quickstart, I needed maven. Eclipse doesn’t support maven out of the box, but there’s a great plugin that makes working with Maven projects easy. You can get all the details at http://eclipse.org/m2e/.

Generate a wicket quickstart project

The wicket project provides a rather clever mechanism based on Maven to build a quickstart project based on various release version of wicket. You can access the quickstart configuration tool at http://wicket.apache.org/start/quickstart.html.

What that generates is a Maven command. As long as you have Maven installed on your computer, you should be able to generate a quickstart project based on that command. If they maintain this resource then it should be easy to create a fresh project for any future version of wicket. Here’s what I ran to create the quickstart for the licensing system:

Import into Eclipse and Configure for GAE

Now we need to import this project into eclipse and configure it to work with Google App Engine. If you have already install the Maven to Eclipse plugin above then you should be able to import the project. To do this choose File -> Import. From the import dialog choose Existing Maven Project.

On the next screen you provide the path to the directory where the pom.xml file is and choose Finish. Now you have an eclipse project for your wicket quickstart.

Add Google App Engine libraries

Add the Google App Engine libraries to your project by opening the Java Build Path dialog and choosing from available libraries (this assumes you have eclipse setup for google app engine development).

Update project settings for GAE

The process of updating the projects settings feels a bit clumsy because you have to save some settings before others will take. Begin by opening the project settings (right click on project name in Package Explorer panel of Eclipse). The first thing you need to do is set the war directory under Google -> Web Application.

Save this setting and close the properties window. Next you need to reopen the window and navigate to Google -> App Engine. There you will check the box next to “Use Google App Engine”.

This will have generated a problem, but you might not see it. Open the Problems panel in Eclipse using the menu options Window -> Show -> Problems. In the problems view you will see that there’s an error indicating that the appengine-web.xml file is missing. You need to right click on the error and choose Quick Fix. Eclipse will create the appengine-web.xml file for you.

Now would be a good time to make a small update to the appengine-web.xml to enable session support (something that’s disabled by default on the App Engine platform). This change is very straight forward and the line you need to add to the file is already in there as a comment. Here’s the line you need to add:

<sessions-enabled>true</sessions-enabled>

Copy over properties and jars

Now we need a handful of files copied over to our WEB-INF/lib directory so that the GAE development server can find them. This include the followng jar files:

  • log4j
  • slf4j-api
  • slf4j-log4j
  • wicket-core
  • wicket-util
  • wicket-request

I’ve left off the version details since those may be different when you get around to this, but you can see below how your WEB-INF/lib directory should look.

You might have noticed while editing the appengine-web.xml file above that it expects a logging.properties file in WEB-INF. You can create this file with this single line:


.level = WARNING

Update pom.xml output directory, etc.

The default output location for compiled classes is under the ‘target’ directory. The Google App Engine development environment will look under webapp, so we need to modify the Maven configuration file to indicate the directories where we want the compiled classes to go. This is done by adding a couple of elements to the build element as shown below.


<project ...>
  <build>
    <directory>src/main/webapp/WEB-INF</directory>
    <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
    ...
  </build>
</project>

Related to the above modification, we need to update the classpaths for builds. This is easily done by opening the project properties and removing the hard coded references to the output directory and making sure the default value is correct. Here’s what that looks like:

While we have the pom.xml file open, let’s make a few other small changes. One will reduce the noise of warnings we get during development. This has to do with the encodings of the files that are copied over during a build cycle.


<project ...>
  <properties>
    ...
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

Wicketstuff gae-initializer

The final required step is to use the gae-initializer that’s part of the wicketstuff repository. You can view the repository https://github.com/wicketstuff/core.

There are two ways to incorporate this into your project. One is through the Maven configuration file. The other is by including the wicketstuff-gae-initializer-1.5.3.jar directly. In order to make my development environment work correctly I had to include the jar file. You can find the jar files here:

http://repo2.maven.org/maven2/org/wicketstuff/wicketstuff-gae-initializer/1.5.3/

To incorporate the gae-initializer into your pom.xml file, open your pom.xml file and click on the Dependencies tab. You can then Add the dependency with the following details:


<project ...>
  <dependencies>
    <dependency>
      <groupId>org.wicketstuff</groupId>
      <artifactId>wicketstuff-gae-initializer</artifactId>
      <version>YOUR-WICKET-VERSION</version>
    </dependency>
    ...
  </dependencies>
</project>

Here’s what it looks like in Eclipse:

I suppose that alone should be enough, and it might be enough for your deployment to production in Google App Engine, but I found that I also need to add the JAR to my build path as an external JAR. This is how I did that:

I now have a running wicket application in Google App Engine.

Resources

Below are a list of old (and very old) tutorials. I couldn’t get these to work with the current version of wicket and GAE. Still, they may be useful if you encounter problems related to features that I didn’t use or test.
http://www.danwalmsley.com/2009/04/08/apache-wicket-on-google-app-engine-for-java/
http://stronglytypedblog.blogspot.com/2009/04/wicket-on-google-app-engine.html
http://stronglytypedblog.blogspot.com/2009/07/wicket-spring-jdo-on-google-app-engine.html

Documentation for gae-initializer in wicketstuff core repository:
https://github.com/wicketstuff/core/wiki/Google-AppEngine-Initializer

This thread covered some points that might fill in gaps:
http://mail-archives.apache.org/mod_mbox/wicket-users/201003.mbox/%3C1269607382.11633.11.camel@kaffeeserver%3E

This article had some discussion of serialization problems. I think that the gae-initializer that I cover in this article addresses the points in the article below.
http://thoughts.inphina.com/2010/10/20/managing-wicket-serialization-problem-on-google-app-engine/

Complaints about GAE not supporting wicket properly (related to above article):
http://code.google.com/p/googleappengine/issues/detail?id=2500

My most recent thread on the wicket users list working through some of the points in this article:
http://apache-wicket.1842946.n4.nabble.com/Wicket-on-Google-App-Engine-td4259205.html

Comments

  1. i followed all instructions, but getting error. Can u share this example?

  2. […] with the project that I setup using my Wicket + GAE tutorial, I added two new files and modified the WicketApplication. Here are the […]

  3. Thank you very much for this great instructions. But I found there another three steps must be done too, otherwise it’ll throws many exceptions.

    In WebApplication’s init method:
    1. this.setSessionStoreProvider(new IProvider(){

    public ISessionStore get() {
    // TODO Auto-generated method stub

    return new HttpSessionStore();
    }
    });
    2. this.setPageManagerProvider(new DefaultPageManagerProvider(this){

    @Override
    protected IDataStore newDataStore() {
    // TODO Auto-generated method stub
    return new HttpSessionDataStore(new DefaultPageManagerContext(), new PageNumberEvictionStrategy(20));
    }

    });
    In web.xml
    3.
    wicket.configuration
    deployment

  4. Thanks Daniel, your post helped a lot.

    I got it working with wicket 6.7.0 so it’s still up to date.

    First I tried the other way round, to start with a GAE Project and add wicket in there, but wicket did not load for some reasons.
    While googling for errors, I found your tutorial, and it worked almost perfectly.

    The only issue I got is that when I call 127.0.0.1:8888 the HomePage.class is not loaded, I have to call its URL.

    Since this is no big issue for me your tutorial helped a lot.

  5. Very helpfull! I got it working with wicket 6.13.0 so it is still up to date! Thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.