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.component.gae.task;
018
019 import java.net.URI;
020 import java.util.Map;
021
022 import com.google.appengine.api.labs.taskqueue.Queue;
023 import com.google.appengine.api.labs.taskqueue.QueueFactory;
024
025 import org.apache.camel.Endpoint;
026 import org.apache.camel.component.gae.bind.InboundBinding;
027 import org.apache.camel.component.gae.bind.OutboundBinding;
028 import org.apache.camel.component.http.HttpClientConfigurer;
029 import org.apache.camel.component.servlet.ServletComponent;
030 import org.apache.camel.component.servlet.ServletEndpoint;
031 import org.apache.commons.httpclient.HttpConnectionManager;
032 import org.apache.commons.httpclient.params.HttpClientParams;
033
034 /**
035 * The <a href="http://camel.apache.org/gtask.html">Google App Engine Task
036 * Queueing Component</a> supports asynchronous message processing. Outbound
037 * communication uses the task queueing service of the Google App Engine.
038 * Inbound communication is realized in terms of the <a
039 * href="http://camel.apache.org/servlet.html">Servlet Component</a> component
040 * for installing a web hook.
041 */
042 public class GTaskComponent extends ServletComponent {
043
044 @Override
045 @SuppressWarnings("unchecked")
046 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
047 String workerRoot = getAndRemoveParameter(
048 parameters, "workerRoot", String.class, "worker");
049 OutboundBinding outboundBinding = resolveAndRemoveReferenceParameter(
050 parameters, "outboundBindingRef", OutboundBinding.class, new GTaskBinding());
051 InboundBinding inboundBinding = resolveAndRemoveReferenceParameter(
052 parameters, "inboundBindingRef", InboundBinding.class, new GTaskBinding());
053 GTaskEndpointInfo info = new GTaskEndpointInfo(uri, remaining);
054 GTaskEndpoint endpoint = (GTaskEndpoint)super.createEndpoint(
055 info.getCanonicalUri(),
056 info.getCanonicalUriPath(),
057 parameters);
058 endpoint.setWorkerRoot(workerRoot);
059 endpoint.setOutboundBinding(outboundBinding);
060 endpoint.setInboundBinding(inboundBinding);
061 endpoint.setQueue(QueueFactory.getQueue(remaining));
062 return endpoint;
063 }
064
065 @Override
066 protected ServletEndpoint createServletEndpoint(String endpointUri,
067 ServletComponent component, URI httpUri, HttpClientParams params,
068 HttpConnectionManager httpConnectionManager,
069 HttpClientConfigurer clientConfigurer) throws Exception {
070 return new GTaskEndpoint(endpointUri, component, httpUri, params,
071 httpConnectionManager, clientConfigurer);
072 }
073
074 }