Camel on Google App Engine Tutorial
This tutorial will be updated whenever new features are added to the Camel Components for Google App Engine.
Goal of this tutorial is to get a non-trivial Camel application running on Google App Engine (GAE). For developing that application the Camel Components for Google App Engine will be used. The application allows the user to enter the name of a city and an email adsress in an HTML form. The form data are submitted by the user to a Camel application, running on GAE, which retrieves weather data for the given city. It then sends a weather report to the user-defined email address. The following figure gives an overview.
POSTed form data are dispatched to the Camel application via the ghttp component. Then the application queues the message with the gtask component for further background processing. This includes retrieval of weather data from the Google Weather Service, transforming the data to generate a report and sending that report by email via the gmail component.
- Sign up for a Google App Engine account if you don't have already.
- Create a new application via the admin console or reuse an existing one for uploading the example.
- Install the Google App Engine SDK for Java. This tutorial has been tested with version 1.2.6.
To deploy the example application, first checkout the sources with
camel-example-gae/src/main/webapp/WEB-INF/application-web.xml file in an editor and replace the template application name
replaceme with the name of the application that you created in the previous section.
camel-example-gae/src/main/resources/context.xml file and change the
sender property value to the email address of your Google App Engine account.
Then go to the
camel-example-gae directory and enter
This will create the application
war file in the target directory. Finally use the
appcfg command-line tool of the App Engine SDK to deploy the application.
version needs to be replaced with the version of Camel you're using. You will be prompted for the email address and password of your Google App Engine account. After deployment the example application is ready to use.
replaceme must be replaced with the application name you entered in
appengine-web.xml. The following form should now appear.
Enter the name of a city and your email address, for example:
Submit. The immediate response is
In the background, the current weather conditions for the user-defined city will be obtained from the Google weather service and a formatted weather report will be send by email. Submitting the form the first time initializes the application on Google App Engine which can take several seconds. Subsequent submissions are served much faster. Check your emails and you should now see a new email with subject
Wheather report and content similar to this one:
The report is partly internationalized, depending on the language settings of your browser.
Route builder walkthrough
Form data are received via the ghttp component. After receiving the request it is added to the
default queue for background processing. Queueing messages on GAE is done with the gtask component. After queueing the request a response is generated for being displayed in the browser. The value of the
mailto header is the email address the user entered in the form.
Background processing of the queued messages starts
from("gtask://default"). The first step is the construction of the Google weather service URL followed by the weather service invocation using the ghttp component. For example, if the user entered
London in the city field of the form the resulting URL is
http://www.google.com/ig/api?weather=London. The resulting XML data are processed by the
This processor extracts data from the XML result with XPath expressions and creates a simple text-based report for being sent by email. For sending the email the gmail component is used. The recipient is derived from the user-defined
mailto header value.