Apache Wicket on Google App Engine for Java

Holy smokes, that was easy. I’ve got a basic Wicket app running on Google App Engine in under 2 minutes.

3 small traps for the unwary. First of all, you need to enable sessions in your appengine config file.

    true

Secondly, add the following line into your WebApplication’s init() method:

    @Override
    protected void init() {
        super.init();
        
        //remove thread monitoring from resource watcher
        this.getResourceSettings().setResourcePollFrequency(null);
    }

Thirdly, override the newSessionStore() method to return HttpSessionStore, because the default second level session store uses java.io.File, which Google App Engine doesn’t allow:

    @Override
    protected ISessionStore newSessionStore()
    {   
        return new HttpSessionStore(this);
//      return new SecondLevelCacheSessionStore(this, new InMemoryPageStore());
    }

That’s because Google App Engine doesn’t want you spawning threads. Obvious enough.

So that’s it! You’re in a Wicket-land of infinite scalability…

(I’m sure there’s more to it but I was excited…)

See my stupid test here: http://transitplatform.appspot.com/

Building Google App Engine Java projects with Maven2

Ok, so I had a whole bunch of work to do today and I’ve just thrown it out the window: Google has unleashed Java support for Google App Engine.

This is huge news. The implementation is solid (it does its best, within the restrictions of Google’s architecture, to support standards and avoid architectural lock-in).

Let’s cut to the chase: I spent this afternoon working out how to build App Engine Java projects with Maven 2 instead of Ant.

I do this for several reasons, the main one being that the CMS I’m building uses Maven as a build system and I love it. A secondary reason is that Maven easily gives me the power to target OSGI, App Engine, and plain ol’ Java Servlets with the one project.

So here we go. First, here’s a script to install some of Google’s more obscure libraries into your local Maven repository:

#!/bin/sh

#install Google App Engine dependencies into local maven repository

#copyright 2009 Gravity Rail Pty Ltd

export CURR=`pwd`
export SDK=`pwd`
export LIB="${SDK}/lib"
export VERS="1.2.0"

cd $LIB

mvn install:install-file -Dfile=${LIB}/appengine-tools-api.jar 
  -DgroupId=com.google 
  -DartifactId=appengine-tools 
  -Dversion=${VERS} 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/appengine-local-runtime-shared.jar 
  -DgroupId=com.google 
  -DartifactId=appengine-tools 
  -Dversion=${VERS} 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/geronimo-el_1.0_spec-1.0.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-el_1.0_spec 
  -Dversion=1.0.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/geronimo-jsp_2.1_spec-1.0.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-jsp_2.1_spec 
  -Dversion=1.0.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/shared/geronimo-servlet_2.5_spec-1.2.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-servlet_2.5_spec 
  -Dversion=1.2 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/user/orm/geronimo-jpa_3.0_spec-1.1.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-jpa_3.0_spec 
  -Dversion=1.1.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/user/orm/geronimo-jta_1.1_spec-1.1.1.jar 
  -DgroupId=org.apache.geronimo.specs 
  -DartifactId=geronimo-jta_1.1_spec 
  -Dversion=1.1.1 
  -Dpackaging=jar 
  -DgeneratePom=true

mvn install:install-file -Dfile=${LIB}/user/orm/datanucleus-appengine-1.0.0.final.jar 
  -DgroupId=org.datanucleus 
  -DartifactId=datanucleus-appengine 
  -Dversion=1.0.0.final 
  -Dpackaging=jar 
  -DgeneratePom=true

cd $CURR

Next, let’s modify the ant build.xml file in the root of our project slightly to take account of Maven’s default project layout:


    

    

    
        
        
            
        
        
            
        
    

    
        
        
            
                
            
        
    

    
        
        
            
                
            
        
        
        
        
            

            
        
    

    
        
    

    
        
    

    
        
    

    
        
    

    
        
    

    
        
            
                
            
            
                
            
        
    



Finally, we put in our pom.xml file that calls ant for tasks like deployment (doesn’t quite work yet):


    4.0.0
    com.transitplatform
    TransitAppEngine
    war
    Transit App Engine
    1.0-SNAPSHOT
    
        war/WEB-INF/classes
        
            
                src/main/resources
            
            
                src/main/java
                
                    **
                
                
                    **/*.java
                
            
        
        
            
                maven-compiler-plugin
                
                    1.6
                    1.6
                
            
            
                maven-antrun-plugin
                
                    
                        1
                        
                        compile
                        
                            
                                <!--
                                    
                                -->
                                
                            
                        
                        
                            run
                        
                    
                    
                        2
                        
                        deploy
                        
                            
                                <!--
                                    
                                -->
                                
                            
                        
                        
                            run
                        
                    
                
            
        

    


    
        
            org.apache.wicket
            wicket
            1.4-rc2
        
        
            org.apache.geronimo.specs
            geronimo-jsp_2.1_spec
            1.0.1
        
        
            org.apache.geronimo.specs
            geronimo-jpa_3.0_spec
            1.1.1
        
        
            org.apache.geronimo.specs
            geronimo-jpa_3.0_spec
            1.1.1
        
        
            ant
            ant
            1.6.5
        
        
            ant
            ant-launcher
            1.6.5
        
        
            commons-logging
            commons-logging
            1.1.1
        
        
            commons-el
            commons-el
            1.0
        
        
            org.datanucleus
            datanucleus-core
            1.1.0
            
                
                    javax.transaction
                    transaction-api
                
            
        
        
            org.datanucleus
            datanucleus-jpa
            1.1.0
        
        
            org.datanucleus
            datanucleus-appengine
            1.0.0.final
        
        
            tomcat
            jasper-compiler
            5.0.28
        
        
            tomcat
            jasper-runtime
            5.0.28
        
        
            javax.jdo
            jdo2-api
            2.3-SNAPSHOT
            
                
                    javax.transaction
                    transaction-api
                
            
        
        
            javax.transaction
            jta
            1.1
        
        
            org.slf4j
            jcl104-over-slf4j
            1.4.3
        
        
            org.slf4j
            slf4j-simple
            1.4.3
        
    


    
        
            datanucleus
            Datanucleus Repository
            http://www.datanucleus.org/downloads/maven2/
        
    

Hope you find this useful, and good luck! Also, let me know if you have any corrections, compliments, duffel-bags-full-of-cash, etc.

Download a sample project here:

mavenappengine