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 java.util.logging.Logger;
020
021 import com.google.appengine.api.users.UserService;
022 import com.google.appengine.api.users.UserServiceFactory;
023
024 import org.apache.camel.Exchange;
025 import org.apache.camel.Processor;
026
027 public class RequestProcessor implements Processor {
028
029 private static final Logger LOGGER = Logger.getLogger(RequestProcessor.class.getName());
030
031 public void process(Exchange exchange) throws Exception {
032 UserService userService = UserServiceFactory.getUserService();
033 String city = (String)exchange.getIn().removeHeader("city");
034 String requestor = userService.getCurrentUser().getEmail();
035 String recipient = requestor;
036
037 if (exchange.getIn().removeHeader("mailtocurrent") == null) {
038 recipient = (String)exchange.getIn().removeHeader("mailto");
039 }
040 exchange.getIn().setBody(new ReportData(city, recipient, requestor));
041 LOGGER.info(requestor + " requested weather data for " + city + ". Report will be sent to " + recipient);
042 }
043
044 }