Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Camel on Google App Engine TutorialOverviewGoal 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 are used. The example web application generates a weather report for a city that is entered by the user into a form and sends the weather report via email to either the currently logged-in user or a user-defined receiver. The following figure gives an overview. Users of this application need to login with their Google account.
POSTed form data are dispatched to the Camel application via the ghttp component. The application transforms the report request and enqueues it with the gtask component for further background processing. It then generates an immediate HTML response containing information about the city and the receiver of the report. The response also contains a link logging out from the application. In the background, the application retrieves weather data from the Google Weather Service, transforms the data to generate a simple weather report and sends the report by email via the gmail component. Java clients Clients other than web browsers may also interact with this application by POSTing the form data and an authentication cookie. At the moment the example application doesn't include a standalone Java client that demonstrates how to do that. This is work in progress. In the meantime, refer to the glogin component documentation for instructions how to access security-enabled GAE services. Tutorial online The next two sections describe how to checkout, build and deploy the example application. If you want to skip these steps, go directly to the #Usage section and use the pre-deployed example application at http://camelcloud.appspot.com. Prerequisites
DeploymentFirst, checkout the sources from the Camel code repository. svn co http://svn.apache.org/repos/asf/camel/trunk camel Navigate to the camel-example-gae and install from here. Open the appengine-web.xml <?xml version="1.0" encoding="utf-8"?> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <!-- Set your application name and version here --> <application>replaceme</application> <version>1</version> <static-files> <exclude path="/index.html" /> </static-files> <system-properties> <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> </system-properties> </appengine-web-app> Then go to the mvn install This will create the application appcfg update target/camel-example-gae-<version> where UsageIn the following, the application name
After login, the application displays the tutorial's main page where you can enter the name of a city and optionally enter an email address where to send the waether report. If you check
After pressing
The Weather report for: London, England Current condition: Klar Current temperature: 12 (Celsius) The report is partly internationalized, depending on the language settings of your browser. Code walkthroughThe TutorialRouteBuilder.java package org.apache.camel.example.gae; import org.w3c.dom.Document; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.gae.mail.GMailBinding; import org.apache.camel.processor.aggregate.AggregationStrategy; public class TutorialRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("ghttp:///weather") .process(new RequestProcessor()) .marshal().serialization() .to("gtask://default") .unmarshal().serialization() .process(new ResponseProcessor()); from("gtask://default") .unmarshal().serialization() .setHeader(Exchange.HTTP_QUERY, constant("weather=").append(ReportData.city())) .enrich("ghttp://www.google.com/ig/api", reportDataAggregator()) .setHeader(GMailBinding.GMAIL_SUBJECT, constant("Weather report")) .setHeader(GMailBinding.GMAIL_SENDER, ReportData.requestor()) .setHeader(GMailBinding.GMAIL_TO, ReportData.recipient()) .process(new ReportGenerator()) .to("gmail://default"); } private static AggregationStrategy reportDataAggregator() { return new AggregationStrategy() { public Exchange aggregate(Exchange reportExchange, Exchange weatherExchange) { ReportData reportData = reportExchange.getIn().getBody(ReportData.class); reportData.setWeather(weatherExchange.getIn().getBody(Document.class)); return reportExchange; } }; } } Background processing of the queued messages starts |