Google App Engine Java and GWT Application Development

Book description

Build powerful, scalable, and interactive web applications in the cloud

  • Comprehensive coverage of building scalable, modular, and maintainable applications with GWT and GAE using Java

  • Leverage the Google App Engine services and enhance your app functionality and performance

  • Integrate your application with Google Accounts, Facebook, and Twitter

  • Safely deploy, monitor, and maintain your GAE applications

  • A practical guide with a step-by-step approach that helps you build an application in stages

In Detail

Google Application Engine is a cloud computing technology that lets you run web applications that are easy to build and maintain as well as being scaled and load-balanced automatically. To build interesting and interactive web applications developers are turning to Java. However, building and deploying scalable web applications using Google Web Toolkit and Google App Engine for Java can be challenging even to developers. The start to finish approach of this book helps you meet these challenges.

This book is designed to give developers all the information they need to develop their own GAE+GWT applications, with a particular focus on some of the technologies useful for building scalable social-media-oriented applications. It is an easy-to-follow guide that shows you how to get the most out of combining the powerful features of GAE and GWT. It provides you with solutions to many of the problems that arise in developing, maintaining, and scaling web applications.

The book introduces you to the features of Google App Engine (GAE) and the Google Web Toolkit (GWT) to help you build interesting and interactive real-world AJAX applications. Over the course of the book, you are guided by the development of a sample application using the Google Web Toolkit (GWT) plugin for Eclipse. To make things easier for you, all application building blocks are explained in detail, walking you through the development process step by step.

The book teaches you the key technologies and methodologies that can be applied to developing your application locally, enhancing your application functionality and accelerating performance, integrating your application with Google Accounts, Facebook, and Twitter as well as monitoring and maintaining your web application.

Packed with great examples and clear explanations, you will be able to build your own web applications that are scalable and reliable using GAE and GWT with Java.

Build a real-world interactive web application in the cloud using GAE/J and GWT, with Push, background processing, OAuth, social media APIs, and more

Table of contents

  1. Google App Engine Java and GWT Application Development
    1. Table of Contents
    2. Google App Engine Java and GWT Application Development
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    7. 1. Introduction
      1. Overview of the chapter
      2. Introduction to Google App Engine
        1. The Datastore
          1. App Engine's scalable services
          2. Java App Engine runtime and the application development environment
          3. GAE/J and the Eclipse IDE
          4. App Engine application hosting
            1. Google App Engine for Business
          5. App Engine "surprises" for new developers
        2. Introduction to GWT
          1. GWT UI support
          2. Other GWT features
          3. GWT's RPC API
          4. GWT with GAE
          5. The GWT/GAE Eclipse plugin
          6. GWT support for Java
          7. Recommended GWT background
      3. Example application: Connectr
        1. A look ahead
      4. Online resources
        1. GAE and GWT galleries
        2. Documentation, blogs, and discussion groups
      5. Summary
    8. 2. Using Eclipse and the Google Plugin
      1. Installing the plugin and supporting software
        1. Installing the Java SDK
          1. Installing Java on Mac OS X
          2. Installing Java on other platforms
        2. Installing Eclipse
        3. Installing the Google plugin
          1. Updating the Google plugin
      2. Developing your application in Eclipse
        1. Creating a new web application project in Eclipse
          1. First look: The anatomy of a web application project
          2. The Google plugin wizards and helpers
      3. Running and debugging your application
        1. Running your application in Development Mode
          1. Developing the application in debug mode
          2. Development Mode and the GWT browser plugin
          3. Defining a run or debug configuration
        2. Debugging
        3. Compiling your GWT code for production mode
      4. Deploying your application
        1. Registering and setting an application ID for your application
        2. How to set the application ID and version for a project
        3. Uploading and deploying your application
        4. Your App Engine Admin Console
      5. Importing an existing application
        1. Adding the Google SDKs to your project's build path
        2. Adding third-party JAR files
        3. Managing multiple Google SDKs
        4. Running Google's demo apps in Eclipse
      6. Summary
    9. 3. Building the Connectr User Interface with GWT
      1. Installing the (first version of) the Connectr project in Eclipse
      2. AJAX and its benefits
      3. Why AJAX apps are the way forward
        1. AJAX apps minimize traffic and workload both on the client and the server
      4. Challenges associated with AJAX programming and how GWT solves them
        1. JavaScript browser's implementation is not consistent
        2. Mastering JavaScript—an uphill battle
        3. How GWT comes to the rescue to make developers more efficient
      5. Google Web Toolkit overview—modern tools for modern developers
        1. GWT user interface building blocks
      6. Building the Connectr application—the user interface
        1. User interface design elements of Connectr
        2. Coding the Connectr user interface
        3. Introducing UiBinder to increase productivity
          1. Declarative UiBinder versus procedural Java—let's compare
        4. Implementing the application layout with UiBinder
        5. Tying the view to the Java code
        6. Adding custom widgets to UiBinder
        7. Adding CSS styles to the application
        8. Implementing CSS styles in a global CSS file
        9. Adding a logo to the application
        10. Catching mouse and keyboard events
      7. Grouping CSS files and images for faster speed with ClientBundle
        1. Creating a ClientBundle
        2. Using image resources in Connectr
        3. Automatically checking CSS styles at compile time with CssResource
      8. Getting data from the server using GWT RPC
        1. Creating the login service
        2. Implementing the server-side login service
        3. Creating the asynchronous interface
        4. Invoking the login service
        5. Catching exceptions
      9. Summary
    10. 4. Persisting Data: The App Engine Datastore
      1. Introduction
        1. The Connectr server-side object model
      2. The Datastore
        1. Datastore entities and their properties
        2. Entity keys
        3. Datastore queries and indexes
          1. Queries are supported by indexes
          2. App Engine queries are fast
        4. The Datastore versus a relational database
      3. JDO
        1. Setting up JDO
      4. Creating Connectr's data models
        1. The PersistenceManager and the PersistenceManagerFactory
        2. Making data classes persistable
          1. Class and field annotations
        3. Persistable field types
          1. Core value types
          2. Collections and multi-valued properties
          3. Datastore keys and JDO key fields
            1. Unencoded String key field
            2. Long key field
            3. Key
            4. Key as encoded string
          4. Defining keys and core value type fields for Friend and UserAccount
          5. Referencing complex objects
          6. Serializable objects and serialized fields
            1. Using a serialized field to hold friend details
            2. Changing the value of a serialized field
          7. Embedded classes
        4. Data class inheritance
        5. Saving, updating, and deleting data objects
          1. Persisting an object
          2. Fetching a persisted object by its k
          3. Deleting a persisted object
          4. An object has an associated PersistenceManager
          5. Fetch groups
        6. Connectr example: creating and modifying UserAccount
          1. Creating new Friend objects
          2. Deleting a Friend object
          3. Fetching a list of Friend objects using the key list
        7. Detached objects
        8. Detached Data Access Objects and Data Transfer Objects
          1. DTOs in the Connectr application
      5. Inspecting the Datastore
        1. The local development console
        2. The App Engine Datastore
          1. Browsing the App Engine Datastore
          2. Viewing application data statistics
      6. Resources
      7. Summary
    11. 5. JDO Object Relationships and Queries
      1. Modeling relationships between objects
        1. Owned relationships and entity groups
        2. Uni-directional owned relationships
          1. Supporting uni-directional owned relationships in Connectr
          2. Dependent children
        3. Bi-directional owned relationships
          1. Bi-directional one-to-one relationship
          2. Bi-directional one-to-many relationship
        4. One-to-many Collection ordering
        5. Unowned relationships
      2. Finding objects—queries and indexes
        1. Constructing JDOQL queries
          1. Query examples
            1. Example 1:
            2. Example 2:
            3. Example 3:
            4. Example 4:
            5. Example 5:
            6. Example 6:
          2. Query filter operators
            1. Constraints on using inequality filters
            2. The contains() operator and ||
          3. Query filters on fields with multiple values
          4. Query sort orders and ranges
        2. Executing a query and getting the results
          1. Query cursors
          2. Unset and unindexed entity fields
        3. Deleting by query
        4. Batch fetches using a list of keys
        5. Keys-only queries
        6. Extents: fetching all objects of a particular kind
      3. The App Engine Datastore index
        1. Automatically-generated indexes
        2. Custom indexes
        3. Revisiting constraints on queries
          1. Exploding indexes
        4. Using the Admin Console Datastore index viewer and index vacuuming
        5. Side-stepping query constraints
          1. Pre-persist callbacks—normalizing Friend name information
      4. Summary
    12. 6. Implementing MVP, an Event Bus, and Other GWT Patterns
      1. Introducing MVP – The need for design patterns in software
      2. Introduction to MVP
        1. The view
        2. The model
        3. The Presenter
      3. Connectr MVP application architecture overview
        1. Package and file organization
      4. Coding MVP into Connectr
        1. Starting up the application
        2. Inside a presenter
          1. Populating the Friend list view
          2. Responding to user interface events
        3. Listening to the event bus
        4. Integrating UiBinder views into MVP
      5. Events and the event bus
        1. Creating a custom event class
        2. Adding an application controller
      6. Adding support for browser history
        1. Introducing the browser history stack and navigation tokens
      7. Implementing browser history management
        1. Bootstrapping the browser history at application startup
      8. Centralizing RPC calls for better handling and usability and reliability
        1. Introducing an encompassing RPC class
        2. Displaying a loading indicator when the app is busy
        3. Catching server exceptions
        4. Retrying a call after failure
        5. Putting it all together
      9. MVP Development with Activities and Places
        1. Building a basic application
        2. Traditional MVP versus MVP with Activities and Places
        3. Moving parts of ProfileMVP
          1. Activities
          2. Places and the Place History Mapper
        4. The Browser Factory
          1. Adding deferred binding for iPhone and Android views
        5. Activity mapper
        6. Putting the pieces together: the onModuleLoad method
      10. Summary
    13. 7. Background Processing and Feed Management
      1. Overview of the chapter
      2. Using Servlets in App Engine
        1. Making your Servlets accessible—the deployment descriptor
        2. Defining a Servlet
          1. Servlet requests and responses
          2. Generating a response
        3. App Engine Servlet limitations
        4. Restricting access to a Servlet
        5. Sessions
        6. The JRE whitelist and system restrictions
        7. Accessing static application files
      3. Using migrations to evolve the Datastore entities
        1. Removing a field from a JDO data class definition
        2. Adding a field to a JDO data class definition
        3. Facilitating "schema" transitions via migrations
          1. Approach—defining a migration
          2. The Migration interface
          3. Implementing a Migration: The FriendMigration class
        4. Running the Migration: A Migration Servlet and the Task Queue
          1. Invoking the Servlet as a web request
          2. Servlet admin authentication
      4. Pulling in Feeds: The URL Fetch service
        1. App Engine services
        2. URL Fetch
          1. Java support for URL Fetch
        3. Using
          1. Making an HTTP request
          2. Using HTTP(S) URLConnection objects
            1. Setting request headers
            2. Making a POST request
            3. Using a Blob to store a binary response
        4. The "low-level" Java URL Fetch API
        5. The ROME and ROME Fetcher RSS/Atom libraries
          1. Downloading the ROME and ROME Fetcher jars and their dependencies
          2. Installing the library JAR files
      5. Using RSS/Atom feeds in the Connectr app
        1. Adding feed support
        2. The feed classes
          1. Adding and removing friend feeds
        3. Fetching and updating feeds
          1. Subclassing the ROME Fetcher HttpURLFeedFetcher class
        4. Processing changes to Friend URLs
      6. Enabling background feed updating and processing
        1. Add some test feeds to your app
        2. Updating the most recently requested FeedInfo objects
          1. The FeedUpdateServlet mapping
          2. Using an admin-only Servlet URL for the feed update job
        3. Updating all feeds for the Friends of a UserAccount
          1. Updating the feeds for a specific Friend
        4. A simple Servlet to display feed contents
      7. Summary
    14. 8. Authentication using Twitter, Facebook OAuth, and Google Accounts
      1. Connectr login implementation
        1. Step-by-step implementation of the login sequence
      2. OAuth: a new way to login and authorize
      3. Integrating with Facebook
      4. Registering Connectr with Facebook
        1. Authenticating with Facebook OAuth
        2. Integrating Connectr inside Facebook
      5. Authenticating against Google
      6. Authenticating against Twitter with OAuth
        1. Registering Connectr with Twitter
        2. Introducing the Twitter login servlet
        3. Analyzing the Twitter callback servlet
      7. Logging out
        1. Logging out when authenticating against Google or Twitter
        2. Logging out of Facebook
      8. Uniquely identifying Connectr users
      9. Automatically registering users when they login
      10. Summary
    15. 9. Robustness and Scalability: Transactions, Memcache, and Datastore Design
      1. Data modeling and scalability
        1. Reducing latency—read consistency and Datastore access deadlines
        2. Splitting big data models into multiple entities to make access more efficient
          1. Discussion
        3. Splitting a model by creating an "index" and a "data" entity
        4. Use of property lists to support "join" behavior
          1. Supporting the semantics of more complex joins
      2. Using transactions
        1. Transaction commits and rollbacks
          1. Example—a JDO transaction
          2. App Engine transactions use optimistic concurrency
          3. Transaction retries
        2. Transactions and entity groups
        3. Creating entities in the same entity group
          1. Getting the entity parent key from the child key
          2. Entity group design considerations
        4. What you can do inside a transaction
        5. When to use a transaction
        6. Adding transactional control to the Connectr application
          1. Transactional tasks
            1. What if something goes wrong during the feed update task?
            2. Task parameters—sending a payload of byte[ ] data as the request
      3. Using Memcache
        1. Using the App Engine Memcache Java API in Connectr
          1. Memcache error handlers
          2. Memcache statistics
          3. Atomic increment/decrement of Memcache values
        2. Using Memcache with JDO data objects
        3. JDO lifecycle listeners
          1. Defining a cacheable interface
          2. The Connectr application's lifecycle listeners
            1. Using the lifecycle listeners consistently
            2. Checking for a cache hit
      4. Summary
    16. 10. Pushing Fresh Content to Clients with the Channel API
      1. Why use push technology
      2. Implementation overview
      3. Setting up the application to handle pushed messages
        1. Server side channel creation
          1. Under the hood of ChannelServer
        2. Preparing the GWT client for pushed messages
          1. Adding a handler to process pushed messages
      4. Pushing messages to clients
      5. Creating custom classes of pushed messages
      6. Telling the server a client is inactive
      7. Adding a refresh button to allow on-demand news updates
      8. Summary
    17. 11. Managing and Backing Up your App Engine Application
      1. Configuration and deployment
        1. Configuration
          1. The deployment descriptor—web.xml
            1. Servlet declarations and mappings, security, and authentication
            2. Servlet filters
          2. Configuring DoS protection blacklists—dos.xml
          3. App configuration—appengine-web.xml
            1. Enabling Servlet sessions
            2. Adding Admin Console pages
            3. System properties and logging
              1. Logging properties
              2. Generating log messages
            4. Static and resource files
              1. Specifying static and resource files
          4. App engine application versions
            1. Application deployment and Datastore indexes
            2. App versions and the Admin Console
          5. Application file limits
      2. The Admin Console
        1. Browsing an app version's logs
          1. App server startup latency
        2. Quotas and billing
          1. Monitoring your quota levels and resource usage
          2. Application behavior when a quota is depleted
        3. Adding developers for an application
      3. Command-line administration
        1. Using
          1. Locating
          2. Using
          3. Downloading application logs
        2. Bulk download and upload of an app's Datastore
          1. Downloading data
          2. Uploading or restoring data
      4. Using Appstats
        1. Enabling and configuring Appstats
        2. Browsing the Appstats statistics page
      5. Using your own domain for an app
      6. Summary
    18. 12. Asynchronous Processing with Cron, Task Queue, and XMPP
      1. Introduction
        1. What the client sees
        2. What goes on behind the scenes
        3. Overview of the chapter
      2. Activity stream classes
        1. The StreamItem persistent class
          1. HTML 'sanitization'
        2. The StreamItem DTOs
      3. Server-Side asynchronous processing
        1. Tasks and Task Queues
          1. Task Queue specification
          2. Task Queue quotas and limits
          3. Monitoring tasks in the App Engine Admin Console
          4. Using application-defined Task Queues
          5. Defining a task: TaskOptions
          6. Some Task Queue design considerations
            1. Fanout and Task Names
            2. Query cursors and next task creation
            3. Create many quick-running tasks
        2. Cron Jobs
        3. Asynchronous server-side tasks in Connectr
          1. Regular background tasks
            1. Feed updates
              1. Updating feeds for active users
              2. Updating recently-accessed feeds
            2. Purge of old data from the Datastore
          2. Context-Specific feed update tasks
            1. Feed update on login
            2. Feed update on URL addition
      4. Supporting synchronous content delivery: Datastore queries and caching
        1. Making StreamItem queries fast
          1. Finding StreamItems for all Friends of a user: doing write-time work to make queries fast
          2. Filtering the StreamItems on a subset of the user's Friends: Using key paths and contains()
        2. Stream cache management
      5. XMPP: Information push to the app
        1. The App Engine XMPP service and API
          1. XMPP addresses
          2. Sending an XMPP message
          3. Receiving an XMPP message
          4. XMPP-related quotas and limits
        2. Setting up Connectr as an XMPP client
          1. Subscribing a Connectr app to the XMPP Breaking News Gateway App
          2. Processing the incoming XMPP notifications
      6. Summary
    19. 13. Conclusion and Final Thoughts
      1. What lies ahead for App Engine and GWT?
    20. Index

Product information

  • Title: Google App Engine Java and GWT Application Development
  • Author(s):
  • Release date: November 2010
  • Publisher(s): Packt Publishing
  • ISBN: 9781849690447