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