001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.example.gae;
018    
019    import org.w3c.dom.Document;
020    
021    import org.apache.camel.Exchange;
022    import org.apache.camel.builder.RouteBuilder;
023    import org.apache.camel.component.gae.mail.GMailBinding;
024    import org.apache.camel.processor.aggregate.AggregationStrategy;
025    
026    public class TutorialRouteBuilder extends RouteBuilder {
027    
028        @Override
029        public void configure() throws Exception {
030            from("ghttp:///weather")
031                .process(new RequestProcessor())
032                .marshal().serialization()
033                .to("gtask://default")
034                .unmarshal().serialization()
035                .process(new ResponseProcessor());
036          
037            from("gtask://default")
038                .unmarshal().serialization()
039                .setHeader(Exchange.HTTP_QUERY, constant("weather=").append(ReportData.city()))
040                .enrich("ghttp://www.google.com/ig/api", reportDataAggregator())
041                .setHeader(GMailBinding.GMAIL_SUBJECT, constant("Weather report"))
042                .setHeader(GMailBinding.GMAIL_SENDER, ReportData.requestor())
043                .setHeader(GMailBinding.GMAIL_TO, ReportData.recipient())
044                .process(new ReportGenerator())        
045                .to("gmail://default");
046        }
047    
048        private static AggregationStrategy reportDataAggregator() {
049            return new AggregationStrategy() {
050                public Exchange aggregate(Exchange reportExchange, Exchange weatherExchange) {
051                    ReportData reportData = reportExchange.getIn().getBody(ReportData.class);
052                    reportData.setWeather(weatherExchange.getIn().getBody(Document.class));
053                    return reportExchange;
054                }
055            };
056        }
057        
058    }