Camel on Google App Engine Tutorial
Work in progress
This tutorial is still work in progress but already provides enough information to get a non-trivial Camel application running on GAE.
Goal of this tutorial is to get a Camel application running on Google App Engine that can send weather reports to user-defined email accounts. The user enters the name of a city and the email address of the report receiver into a form and submits it to the tutorial application. Retrieving weather data for that city and sending the weather report is done in the background.
The packaged tutorial application can be (temporarily) downloaded from here. It is an Eclipse project that requires the Google Eclipse Plugin and the App Engine Java SDK 1.2.6 for running. A Maven-based version of the project should be available soon. The following sections describe how to build that application from scratch.
Create a GAE application
For setting up the Camel-independent parts of a GAE application refer to the Java Getting Started Guide in the GAE documentation. This tutorial uses the Google Plugin for Eclipse and the App Engine Java SDK 1.2.6. After installing the SDK and the plugin, create a new GAE project via
File->New->Web Application Project.
Finish the new GAE project appears in the package explorer.
Add required libraries
The created project is not a Maven project so all required dependencies must be added manually to the
war/WEB_INF/lib directory. These are
Then right-click on the
Tutorial project and add these libraries to the classpath via
Properties->Java Build Path->Libraries->Add JARs.... After adding they should now appear in the
Referenced Libraries container.
Setup deployment descriptors
The deployment descriptors
appengine-web.xml are located in the
<application> element in
appengine-web.xml requires a GAE application name. In the following example, replace the value
replaceme with a valid GAE application name.
Setup the form
Users provide input data to the application by submitting form data. The following form definition should be stored in
When the user presses the
Submit button the form data are POSTed to
http://<appname>.appspot.com/camel/weather. The input field values will be available as
in message headers
Setup the routes
Add the following
TutorialRouteBuilder class to the
org.apache.camel.example.gae package. The previously generated
TutorialServlet in that package can be deleted.
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. Add this class to the
org.apache.camel.example.gae package. For sending the email the gmail component is used. The sender is given by the endpoint URI where
<replaceme> must be replaced with the username of the admin account of the GAE application (usually the account to deploy the GAE application). The recipient is derived from the user-defined
Local development server
Please note that on the local development server sending emails does not work and queued tasks must be executed manually from the developer console.
Setup the application context
Add the following application context XML file to the project's
src directory (needs to be on the classpath).
Deploy the application
To deploy the application right-click on the
Tutorial project and select
Google->Deploy to App Engine. In the dialog enter the project name, your email address and password for logging into App Engine and press
Use the application
<appname> must be replaced with a valid GAE application name. The following form should now appear.
Enter the name of a city and your email address, for example:
Submit. Submitting the form the first time will initialize the application on Google App Engine which can take more than 10 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.