Cloud Computing.com

Running a Web service on Google App Engine

By William Brogden, Contributor

App Engine is Google's service for building Web applications in the cloud. The initial version only supported Python, but Java servlet support has recently entered early release. Developers can experiment with a quota of free resources, so naturally I was interested. I downloaded the software development kit (SDK) Version 1.2.1 and got the Google plug-in for Eclipse 3.4.2. Documentation for the Java version has not quite caught up with the quality of the Python documentation, but you'll find what you need with a little digging.

App Engine Java servlet environment
The runtime environment for the App Engine is Java 6 with the standard libraries. The structure of a Java servlet in the App Engine environment follows normal Java practice for Servlet API 2.5 with certain restrictions. All of the static resources normally served directly by the servlet container -- such as HTML files, CSS files and images -- are placed according to convention under the root directory of the application. For example, you might have a logo image addressed as "/graphics/mylogo.gif."

Resources that are private to the application and are only read, never written, such as jar libraries, class files and configuration files, are stored under the usual "/WEB-INF" directory. For obvious security reasons, Google can't let an application wander unrestrained through the file system, so if your application reads and writes files, you will have to make some major adjustments to use the persistent data-storage methods that App Engine supports. Furthermore, your servlet must complete a response within 30 seconds and may not start any new processes.

Scaling to an increased user-request load is handled automatically by creating new instances of an application and removing them when the load decreases. The App Engine environment ensures that all instances will have access to correctly updated common resources. Here are some of the Google specific tools your application can make use of.

The Eclipse development environment for App Engine
Currently, plug-ins are available only for Eclipse 3.3 and 3.4 -- as of this writing, there are no plug-ins for the newest 3.5 "Galileo" Eclipse. If you are downloading and installing Eclipse for the first time, go for the "Java EE Developers" package. The Google plug-ins provide extensive support for simulating the App Engine environment. Selecting the "New Web Application Project" option automatically creates the proper directory structure with the correct Java library files.

Creating an example service
As an example, I decided to try porting a servlet-based Web service to App Engine. The service is a simple one I have used for several example coding projects. It lets you look up lists of words that sound alike using the "metaphone" phonetic code algorithm. It uses some serialized Java objects to hold the lookup structures for thousands of precomputed phonetic codes. Since these are read-only objects, they can be stored with other application resources.

Getting a Google App Engine account
Since I've had an account with Google for years, I figured this should be the simplest part of the process, but I was wrong. For some reason, Google wanted to verify my account by means of a SMS message to my cell phone -- I don't have a cell phone! With help from a cell phone owner, I got my verification code, and I was able to proceed. I suspect that this SMS capability will find its way into the API soon as Google integrates App Engine with other Google projects. With the verification accomplished, my normal Google account let me request an application name. I chose "phonetic01" so the full URL to the service is "phonetic01.appspot.com."

Installing to Google's system
The Eclipse App Engine plug-in guides you through configuration of your application and uploads all of the components. In addition to the usual web.xml deployment descriptor, App Engine uses an AppEngine-web.xml file to associate a name and version number with the code. Eclipse makes modification of components and redeployment quite easy and fast.

After the application had been inactive for a while, I found that response time to a request took a few seconds, presumably because App Engine does not keep every application loaded all the time. Subsequent requests were quite fast.

Conclusions
Although it is still under development, Google's App Engine support for Java servlet-based Web services is very usable. With good Eclipse support, it is easy to start experimenting. If you don't have Eclipse, the SDK has command-line utilities to support development and deployment with your normal tools.

Resources
 


 

21 Jul 2009

All Rights Reserved, Copyright 2010 - 2024, TechTarget | Read our Privacy Statement