8
Cloud Sherpas CLOUD SHERPAS WHITE PAPER Extending Google Apps with Java for App Engine ABSTRACT With the April 7th introduction of the Java runtime for App Engine and the Secure Data Connector, Google has provided a comprehensive solution for developing rich internet applications which can extend the business value of Google Apps. This white paper details the components involved and pro- vides a how-to for integrating a Java for App Engine application with Google Apps. Cloud Sherpas has developed a sample dashboard application that dem- onstrates how to integrate Google Apps with a custom application built on Google App Engine. The application, deployed using the new Java language support on App Engine, searches a user’s Google Calendar for the past week and displays how much time the user has spent in meetings. To see how you’re spending your time and to view the accompanying demo, please visit: http://gapps-demo-cs.appspot.com/ TECHNOLOGIES AND SERVICES Google Apps By 2011, 25% of new business software will be delivered as a service (Gart- ner, Inc 2006). The Enterprise is increasingly embracing the Software as a Service model to provide their users with on-demand Enterprise application. With the introduction of Google Apps in early 2007, Google plays a major role as early adopters choose to move some of their mission critical applications to a Software as a Service model in an effort to cut IT expenses and provide a more user-centric messaging and collaboration experience. Google Apps is Google’s on-demand robust business suite of Messaging and Collaboration applications. The suite includes GMail, Google Calendar, Google Docs, Google Talk, Google Video, and Google Sites. Google App Engine App Engine is Google’s Platform as a Service (PaaS) offering of its world-class, massively-scalable web application stack. This is the same tested architecture which serves Google Apps as well as Google Earth and Search. Along with the platform, Google provides the App Engine SDK for building and testing

Extending Google App Engine White Paper

Embed Size (px)

DESCRIPTION

This white paper details the components involved and provides a how-to for integrating a Java for App Engine application with Google Apps.

Citation preview

CloudSherpas

CLOUD SHERPAS WHITE PAPER

Extending Google Apps with Java for App Engine

AbSTRACT

With the April 7th introduction of the Java runtime for App Engine and the Secure Data Connector, Google has provided a comprehensive solution for developing rich internet applications which can extend the business value of Google Apps. This white paper details the components involved and pro-vides a how-to for integrating a Java for App Engine application with Google Apps.

Cloud Sherpas has developed a sample dashboard application that dem-onstrates how to integrate Google Apps with a custom application built on Google App Engine. The application, deployed using the new Java language support on App Engine, searches a user’s Google Calendar for the past week and displays how much time the user has spent in meetings. To see how you’re spending your time and to view the accompanying demo, please visit: http://gapps-demo-cs.appspot.com/

Technologies and services

Google Apps

by 2011, 25% of new business software will be delivered as a service (Gart-ner, Inc 2006). The Enterprise is increasingly embracing the Software as a Service model to provide their users with on-demand Enterprise application.

With the introduction of Google Apps in early 2007, Google plays a major role as early adopters choose to move some of their mission critical applications to a Software as a Service model in an effort to cut IT expenses and provide a more user-centric messaging and collaboration experience.

Google Apps is Google’s on-demand robust business suite of Messaging and Collaboration applications. The suite includes GMail, Google Calendar, Google Docs, Google Talk, Google Video, and Google Sites.

Google App Engine

App Engine is Google’s Platform as a Service (PaaS) offering of its world-class, massively-scalable web application stack. This is the same tested architecture which serves Google Apps as well as Google Earth and Search. Along with the platform, Google provides the App Engine SDK for building and testing

extending google apps with Java for app enginepage 2

applications locally, a tool for uploading applications to App Engine, and an administration console for monitoring and managing applications. We will be developing our demo application to run within App Engine’s new Java Servlet Container on Eclipse using Google’s new App Engine plugin.

Figure 1. Google App Engine Dynamically Scalable Platform Stack

Google Data APIs

Google Data APIs serve as a programmatic interface into Google Apps and other Google online applications. These APIs communicate with Google ap-plications via the AtomPub protocol with libraries available in Java, Python, .NET, JavaScript, Objective-C, and PHP. Our demo application will use the Calendar APIs to analyze the most recent week of a user’s calendar.

Secure Data Connector

The Secure Data Connector provides Google-hosted applications access to data systems behind the firewall. Since our demo application does not in-corporate firewalled data, we’ll need to save demonstrating this very useful feature as a follow-up.

Adobe Flex

Along with the suite of Google products that run on App Engine, Google has developed a platform that supports a wide range of 3rd party libraries and frameworks. To illustrate the point, we have chosen Adobe’s Flex framework as the UI layer of our application, passing it a simple XML feed of the result-ing meeting times.

Alternatively, we could have chosen the Google Web Toolkit (GWT) for pre-sentation. GWT avoids the Flash requirements of Flex, opening up support for mobile devices. GWT also enables Java Developers to write both the front

extending google apps with Java for app enginepage 3

and back ends of a web application in Java, simplifying the development process.

PUTTING IT ALL TOGETHER

Overview

Figure 2 illustrates the architecture for integrating a Google App Engine ap-plication with Google Apps. Our demo application utilizes the elements in color in the top row. After the user authenticates, the application will query the user’s Google Calendar and display charts and graphs analyzing data from the past week.

Figure 2. Demo application architecture

In order to accomplish creating this type of application, we will take a divide-and-conquer approach with the sub-tasks. First, we will register and create the base App Engine application. Next, we will implement the Google Data API querying of Calendar. Then we will focus on serving the data to the Flex UI via an XML feed. Finally, we will layout the Flex charts and UI components.

Creating a New Java Application for App Engine

The first step is to register a new application name at:http://appengine.google.com/

Once the application name is registered and we have installed all the down-loads listed at the end of this paper, we then create a new Google “Web Ap-plication Project” within Eclipse, selecting to use App Engine without GWT.

extending google apps with Java for app enginepage 4

Figure 4. Java Eclipse Platform

After creating the project, we can verify that it is able to run on the App En-gine SDK. If the server executes without issue, and we can view the applica-tion at http://localhost:8080/, we have a working base application.

Securely Connecting to Google Apps

Our next task is to securely query Calendar using the Google Data API. There are two main areas of work for this task: securing the API call and developing the query.

Since this is a public application interacting with sensitive data, we ensure we use Google’s highest security for AuthSub, though OAuth is another option.

The directions for implementing AuthSub can be found at:http://code.google.com/apis/gdata/authsub.html

In a nutshell, we will:

Generate a public and private key using the java built-in keytool for key 1. generation.

Register the application with Google, uploading the public key to: 2. https://www.google.com/accounts/ManageDomains

Add the private key as part of the Eclipse web application project.3.

Generate a link requesting secure access to Google Apps to the home 4. page of the application.

extending google apps with Java for app enginepage 5

Write code to respond to the AuthSub request using the private token 5. and AuthSubUtil methods for retrieving the single use token.

Use the same tools to convert it into a session token which can then be 6. stored on the session.

Enable sessions in our application by adding:7. <sessions-enabled>true</sessions-enabled>

to the appengine-web.xml config file.

Once AuthSub has been properly configured, we are ready to connect to Calendar using the Google Data APIs. Next, we need to add the calendar feed (http://www.google.com/calendar/feeds/) to the link requesting AuthSub-secured access.

Note, this demonstration will only query for the start and end times of events on a user’s calendar for the past week. No other personal data is reviewed or stored.

Next, we will also need to import all of the Java gdata jars required for calen-dar operations into the WEb-INF/lib directory of our project. The easiest way to determine which jars are required is to separately create a new Google Data project with Calendar API selected. All jars required in that project will be required by our web application.

We are now ready to implement our query according to Google’s Calendar API instructions for Java. Using the GData API for our purposes is fairly straight-forward:

Create a new instance of the GData API CalendarService.1. Add the required AuthSub properties to the service.2. Configure a custom CalendarQuery for the type of results.3. Use the CalendarService to execute the query.4. Retrieve and process the resulting entries.5.

Sample code for doing this is as follows:

CalendarService calendarApiService = new CalendarService(YOUR_APP_NAME);

calendarApiService.setAuthSubToken(token,PRIVATE_KEY);

CalendarQuery myQuery =

new CalendarQuery(new URL(“http://www.google.com/calendar/feeds/default/private/full”));

Date now = new Date();

myQuery.setMaximumStartTime(new DateTime(now));

Date oneWeekAgo = new Date(now.getTime()-604800000);

myQuery.setMinimumStartTime(new DateTime(oneWeekAgo));

extending google apps with Java for app enginepage 6

myQuery.setMaxResults(75);

CalendarEventFeed resultFeed = calendarApiService.query(myQuery, Calen-darEventFeed.class);

List<CalendarEventEntry> entries = resultFeed.getEntries();

Configuring the XML Feed

For this demo, we iterate over the query results, gathering the start and end times as unix-time long integer values of each meeting. These times are then wrapped in a basic xml stream and returned as the HTTP response to the requesting Flex HTTPService.

Assembling the Flex User InterfaceSince all we are passing to the UI is start and end timestamp pairs, de-velopment of the Flex piece can be performed separately from the backend connection by stubbing out the collection of timestamps. Our application uses three chart types, the standard PieChart and ColumnChart components along with Thomas Gonzalez’s very nice open source Gauge component. Once the UI is completed, we can implement the HTTPService connection to our application and shift our charts to respond to the service results.

Figure 5. Flex charts display Google Calendar query results

Uploading to App Engine

After completing and testing the Calendar query, the XML Feed, and the UI, we are ready to upload our application to run on App Engine. Pressing the App Engine icon in Eclipse pops-up the upload wizard. We enter the Google account user name and password and click on the App Engine Project Set-tings link to ensure the Application ID is identical to the one we registered with App Engine. And finally, we hit the deploy button and our application is uploaded to App Engine.

extending google apps with Java for app enginepage 7

SEE IT IN ACTION

We encourage you to try out the demo application at:http://gapps-demo-cs.appspot.com/

If you have multiple Google accounts, it would be best to choose an account that makes use of Google’s Calendar, else no results will be shown in the charts.

SUMMARy

This white paper and accompanying demo describe how to use the new Java language support in App Engine to build an application that integrates with Google Apps. Combined with the Secure Data Connector and other new fea-tures in the platform, Google App Engine offers businesses an open, scalable development platform best suited to extend the value of Google Apps.

Google Apps customers can leverage Google App Engine to build custom ap-plications and gadgets that integrate with the messaging and collaboration suite. Ultimately, Google App Engine allows an organization to migrate even more of its legacy on-premise workloads to Google’s growing suite of cloud computing services.

DOWNLOAD LINKS

Java http://java.sun.com/javase/downloads/index.jsp

Java runtime for App Engine http://code.google.com/appengine/docs/java/gettingstarted/installing.html

Google Secure Data Connector http://code.google.com/sdc

Eclipse http://www.eclipse.org/downloads/

Flex SDK http://opensource.adobe.com/wiki/display/flexsdk/Downloads

Google Data APIs Java Client http://code.google.com/p/gdata-java-client/downloads/list

GData APIs Eclipse Plugin http://code.google.com/p/gdata-java-client-eclipse-plugin/wiki/Installation

extending google apps with Java for app enginepage 8

AbOUT CLOUD SHERPAS

Cloud Sherpas (www.cloudsherpas.com) is a cloud computing systems in-tegrator and application developer. As a leading Google Enterprise partner, Cloud Sherpas helps organizations leverage Google Apps and Google App Engine to dramatically reduce IT expenses. The company delivers deploy-ment, change management, support and development services to commer-cial, enterprise and educational institutions seeking to adopt cloud comput-ing.

Cloud Sherpas is a Google Apps Authorized Reseller and enterprise deploy-ment partner. The company also supports cloud computing solutions from EMC/Decho, TriCipher and other best-in-breed vendors.

CloudSherpas

Google, Google App Engine, Secure Data Connector, Google Enterprise Partner, Google Apps and Google Apps Authorized Reseller are trademarks of Google Inc. Java is a trademark of Sun Microsystems, Inc. Flex is a trademark of Adobe Systems Incorporated.