Google App Engine

Google App Engine (GAE), also known as App Engine, enables you to host web applications on Google’s infrastructure. GAE is a Platform as a Service (PaaS) cloud computing platform for hosting web applications in Google-managed data centers. App Engine offers automatic scaling for web applications as request increases by allocating more resources for the application to handle the additional demand.

App Engine supports applications written in Java, Python and Go. It offers a range of options to store data like App Engine Datastore (NoSQL schemaless object store), Google Cloud SQL (relational SQL database) and Google Cloud Storage. Apps run in sandbox and span across multiple servers.

Best thing about App Engine is that it is free to start with and comes with a free quota of resources. Free quota is sufficient for demo or apps catering to a small audience.

Whereas other cloud platforms like Amazon EC2 which allows to run any POSIX compatible softwares and RedHat OpenShift which gives you the widest choice of programming languages, frameworks and runtimes, App Engine restricts the apps to use only supported API and frameworks. One has to be careful while developing an application for GAE so as to avoid vendor lock-in. This Chapter explains how to enable GAE support in Eclipse and also how to disable GAE support in case you want to migrate to any other platform. We have to keep this aspect in mind when we extend the Fins with GAE features.

10.1. Enable App Engine

To enable App Engine support, go to project context menu and choose GoogleApp Engine Settings . . . and enter values as shown in the next figure.

App Engine Settings
Figure 10.1. App Engine Settings

Project uses DataNucleus JDO version 2 to access datastore. As we have not enabled Google Cloud SQL, app uses default App Engine Datastore, which is a NoSQL schemaless object datastore with a query engine and atomic transactions. On clicking OK, Google Plugin for Eclipse (GPE) adds App Engine descriptor file, libraries etc., to the project.

When we enable App Engine support, GPE adds following files/builders to the project.

  • adds appengine-web.xml descriptor file to war/WEB-INF directory.

  • adds SystemServiceServlet entry to war/WEB-INF/web.xml.

  • adds App Engine and JDO libraries to war/WEB-INF/lib directory and updates project build path.

  • adds App Engine builder and JDO Enhancer to project builders so that project auto builds.

 
 
App Config

In addition to standard deployment descriptor - web.xml, App Engine uses appengine-web.xml to configure the application. When GAE support is enabled, GPE adds this file to war/WEB-INF directory and for Fins, we go with the configuration generated by GPE. Only interesting element in this file for the moment is logging system property which points to WEB-INF/logging.properties. Add following logging.properties file.

war/WEB-INF/logging.properties

# Logging configuration file for Google App Engine tools.

# Specify the handlers to create in the root logger
# (all loggers are children of the root logger)
# The following creates the console handler
handlers = java.util.logging.ConsoleHandler

# Set the default logging level for the root logger
.level = INFO

# Set the default logging level for the datanucleus loggers
DataNucleus.JDO.level=WARNING
DataNucleus.Persistence.level=WARNING
DataNucleus.Cache.level=WARNING
DataNucleus.MetaData.level=WARNING
DataNucleus.General.level=WARNING
DataNucleus.Utility.level=WARNING
DataNucleus.Transaction.level=WARNING
DataNucleus.Datastore.level=WARNING
DataNucleus.ClassLoading.level=WARNING
DataNucleus.Plugin.level=WARNING
DataNucleus.ValueGeneration.level=WARNING
DataNucleus.Enhancer.level=WARNING
DataNucleus.SchemaTool.level=WARNING

GPE adds an entry for SystemServiceServlet to web.xml which handles requests to EndPoints and we leave that one as it is.

App Engine Libraries

GPE adds a number of jars to war/WEB-INF/lib, and the next figure shows a list of them.

App Engine Libraries
Figure 10.2. App Engine Libraries

Except gwt-servlet.jar and gwt-visualization.jar, all other jars are added by GPE when GAE support is enabled. App Engine uses DataNucleus implementation of JDO specification to provide JDO support and JDO uses ASM to enhance persistent classes via Java Byte code manipulation. App Engine’s MemCache is based on JSR-107 specification and we use this feature in the next chapter.

GPE updates project build path with a library entry - App Engine SDK, as shown in next figure.

Build Path
Figure 10.3. Build Path
JDO Class Enhancement

Earlier we had installed DataNucleus plugin and enabled DataNucleus Support to our project. This is no longer required and to disable DataNucleus Support right click on project and in context menu choose DataNucleusRemove DataNucleus Support. Once App Engine Support is enabled, its build system takes care to enhance the persistence classes.

Revert back the jars

In case you have messed with the app engine jars or class path, then to revert back the jars and appengine-web.xml do as follows.

  • in project context menu, choose Build PathConfigure Build Path and in Java Build Path dialog, select Libraries tab. Select and remove App Engine SDK entry.

  • next in project context menu, choose GoogleApp Engine Settings . . . and in App Engine dialog, deselect Use Google App Engine checkbox and click OK to close the dialog.

  • again in project context menu, invoke GoogleApp Engine Settings . . . and in App Engine dialog, select Use Google App Engine checkbox.

    This will add all required App Engine components to the project.

Disable App Engine Support

In case, for whatever reason, you want to revert back the app to run on a generic web server then to remove App Engine support do as follows.

  • remove SystemServiceServlet entry from war/WEB-INF/web.xml.

  • delete war/WEB-INF/appengine-web.xml and war/WEB-INF/logging.properties.

  • remove App Engine generated directories; war/WEB-INF/appengine-generated and war/WEB-INF/deploy (if exists)

  • in project context menu, choose Build PathConfigure Build Path and in Java Build Path dialog, select Libraries tab. Select and remove App Engine SDK entry.

  • next in project context menu, choose GoogleApp Engine Settings . . . and in App Engine dialog, deselect Use Google App Engine checkbox.

  • remove all App Engine related jars from war/WEB-INF/lib which were added by GPE when App Engine support was enabled.

Apache Ivy

If you are using Apache Ivy then you may remove App Engine related jars in a easy way. No need to know which are App Engine related jars, just delete all jars, except gwt-servlet.jar and gwt-visualization.jar, from war/WEB-INF/lib . Then hit Ivy refresh button which copies dependencies managed by it to project’s lib directory from its cache.

Libraries

To manage dependencies, you may like to have a list of the required jars. For your reference, list of required jars is as shown in following screen shots.

For Google App Engine

antlr-2.7.7.jar                  gwt-servlet.jar
appengine-api-1.0-sdk-1.7.5.jar  gwt-visualization-1.1.2.jar
appengine-api-labs.jar           hibernate-commons-annotations-4.0.1.Final.jar
appengine-endpoints.jar          hibernate-core-4.1.10.Final.jar
appengine-jsr107cache-1.7.5.jar  hibernate-jpa-2.0-api-1.0.1.Final.jar
asm-4.0.jar                      javassist-3.15.0-GA.jar
commons-fileupload-1.2.2.jar     jboss-logging-3.1.0.GA.jar
commons-io-2.4.jar           jboss-transaction-api_1.1_spec-1.0.0.Final.jar
commons-lang-2.6.jar             jdo-api-3.0.1.jar
datanucleus-api-jdo-3.1.3.jar    jsr107cache-1.1.jar
datanucleus-api-jpa-3.1.3.jar    jta-1.1.jar
datanucleus-appengine-2.1.2.jar  mybatis-3.2.0.jar
datanucleus-core-3.1.3.jar       portlet-api-1.0.jar
dom4j-1.6.1.jar                  servlet-api-2.4.jar     
geronimo-jpa_2.0_spec-1.0.jar

For regular App Server or Servlet containers like JBoss or Tomcat etc.

activation-1.1.jar                             hibernate-core-4.1.10.Final.jar
ant-1.8.4.jar                                  hibernate-jpa-2.0-api-1.0.1.Final.jar
ant-launcher-1.8.4.jar                         hibernate-validator-4.1.0.Final.jar
antlr-2.7.7.jar                                hsqldb-2.2.9.jar
asm-4.0.jar                                    javassist-3.15.0-GA.jar
commons-fileupload-1.2.2.jar                   jaxb-api-2.2.jar
commons-io-2.4.jar                             jaxb-impl-2.1.12.jar
commons-lang-2.6.jar                           jboss-logging-3.1.0.GA.jar
datanucleus-api-jdo-3.1.3.jar                  
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
datanucleus-core-3.1.4.jar                     jdo-api-3.0.1.jar
datanucleus-enhancer-3.1.1.jar                 jta-1.1.jar
datanucleus-rdbms-3.1.4.jar                    log4j-1.2.16.jar
dom4j-1.6.1.jar                                mail-1.4.1.jar
geronimo-jms_1.1_spec-1.0.jar                  mybatis-3.2.0.jar
geronimo-jpa_3.0_spec-1.0.jar                  portlet-api-1.0.jar
geronimo-jta_1.1_spec-1.1.jar                  servlet-api-2.4.jar
gwt-servlet.jar                                slf4j-api-1.5.6.jar
gwt-visualization-1.1.2.jar                    slf4j-log4j12-1.5.6.jar
hibernate-commons-annotations-4.0.1.Final.jar  validation-api-1.0.0.GA.jar
 
 

After App Engine support is enabled, you may continue with the development in Development Mode as you where doing so far.

The next section deals with deployment of the application to Google App Engine.