Deploying a Wicket App on Google’s AppEngine

Google’s App Engine (GAE) cloud infrastructure provides a fast and easy way to deploy a Java web application to the public web. And it’s free up to a certain traffic threshold. So, I tried it with a Wicket application and had to overcome some small obstacles. Following is a description of the steps necessary to deploy a Java application (precisely, a Wicket application) to Google App Engine.

Create a GAE account

Go to https://developers.google.com/appengine and create an App Engine account. If you already have a Google Mail account, it’s just a click.

>Install GAE SDK

Download the GAE SDK for Java here. Unzip it anywhere on your hard drive.

Prepare your Java application for GAE

Next to the standard web.xml deployment descriptor you need to provide a descriptor called appengine-web.xml in the WEB-INF folder of your WAR. Following is the content of an appengine-web.xml with which I successfully deployed a demo app on App Engine:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>wicket-charts</application>
  <!-- Version must only contain letters, hyphens ("-") and numbers! Otherwise, 
    a HTTP 500 will occur on update -->
  <version>1-2-0</version>
  <threadsafe>false</threadsafe>
  <sessions-enabled>true</sessions-enabled>
  <system-properties></system-properties>
</appengine-web-app>

Take care that the content of the version tag contains only letters, numbers or hyphens (no periods!). Otherwise you get an inexpressive HTTP 500 error when deploying the application.

Additionally to providing a depoyment descriptor you have to adhere to some restrictions GAE imposes on java applications. The main restrictions are:

  • Your application may not store anything in the local filesystem (which actually already is a constraint of the servlet API, but most application servers do not enforce this rule)
  • Your application may not use all classes of the JRE. For example, AWT/Swing classes are a no-go for GAE applications. The classes you may use are listed in a white list.

The second restriction is by far the more constraining. You simply cannot run an application on GAE that uses one of the prohibited classes! This makes the deployment of applications built without GAE in mind a gamble.

Prepare your Wicket application for GAE

The steps above are valid for all Java applications. For making a Wicket application ready for GAE, simply put the Google App Engine Initializer in the classpath of your application and you’re done. The initializer will automatically configure your Wicket application on startup so that it adheres to the GAE restrictions. Among other things, the initializer configures your application not to use Wicket’s DiskDataStore which stores the PageMap in the file system.

If you want to have full control over how your Wicket application is configured, you have to make the necessary configurations in your application’s init method yourself (but you have to find out yourself what configurations are necessary for the application to run on GAE).

Deploy your application on the GAE development server

To test if your application runs on GAE, run the following command:

<path_to_appengine_sdk>/bin/dev_appserver.cmd <path_to_your_war>

where points to a directory (expanded war archive) and not a war file.

On http://localhost:8080 you should now see your application.

Deploy your application into the GAE cloud

To finally deploy your application to the cloud, run the following command:

<path_to_appengine_sdk>/bin/appcfg.cmd update <path_to_your_war>

where  again points to a directory. You will be prompted to enter your GAE login credentials before the application will be uploaded.

You should then be able to access your application on http://.appspot.com.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s