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.lang.reflect.Proxy;
020 import java.net.URI;
021 import java.net.URISyntaxException;
022
023 import javax.servlet.http.HttpServletRequest;
024 import javax.servlet.http.HttpServletResponse;
025
026 import com.google.appengine.api.labs.taskqueue.Queue;
027 import com.google.appengine.api.labs.taskqueue.TaskOptions;
028
029 import org.apache.camel.Exchange;
030 import org.apache.camel.Producer;
031 import org.apache.camel.component.gae.bind.HttpBindingInvocationHandler;
032 import org.apache.camel.component.gae.bind.InboundBinding;
033 import org.apache.camel.component.gae.bind.OutboundBinding;
034 import org.apache.camel.component.gae.bind.OutboundBindingSupport;
035 import org.apache.camel.component.http.HttpBinding;
036 import org.apache.camel.component.http.HttpClientConfigurer;
037 import org.apache.camel.component.servlet.ServletComponent;
038 import org.apache.camel.component.servlet.ServletEndpoint;
039 import org.apache.commons.httpclient.HttpConnectionManager;
040 import org.apache.commons.httpclient.params.HttpClientParams;
041
042 /**
043 * Represents a <a href="http://camel.apache.org/gtask.html">Google App Engine Task Queueing endpoint</a>.
044 */
045 public class GTaskEndpoint extends ServletEndpoint implements OutboundBindingSupport<GTaskEndpoint, TaskOptions, Void> {
046
047 private OutboundBinding<GTaskEndpoint, TaskOptions, Void> outboundBinding;
048 private InboundBinding<GTaskEndpoint, HttpServletRequest, HttpServletResponse> inboundBinding;
049
050 private String workerRoot;
051
052 private Queue queue;
053
054 public GTaskEndpoint(String endpointUri, ServletComponent component,
055 URI httpUri, HttpClientParams params,
056 HttpConnectionManager httpConnectionManager,
057 HttpClientConfigurer clientConfigurer) throws URISyntaxException {
058 super(endpointUri, component, httpUri, params, httpConnectionManager, clientConfigurer);
059 }
060
061 public OutboundBinding<GTaskEndpoint, TaskOptions, Void> getOutboundBinding() {
062 return outboundBinding;
063 }
064
065 public void setOutboundBinding(OutboundBinding<GTaskEndpoint, TaskOptions, Void> outboundBinding) {
066 this.outboundBinding = outboundBinding;
067 }
068
069 public InboundBinding<GTaskEndpoint, HttpServletRequest, HttpServletResponse> getInboundBinding() {
070 return inboundBinding;
071 }
072
073 public void setInboundBinding(
074 InboundBinding<GTaskEndpoint, HttpServletRequest, HttpServletResponse> inboundBinding) {
075 this.inboundBinding = inboundBinding;
076 }
077
078 /**
079 * Proxies the {@link HttpBinding} returned by {@link super#getBinding()}
080 * with a dynamic proxy. The proxy's invocation handler further delegates to
081 * {@link InboundBinding#readRequest(org.apache.camel.Endpoint, Exchange, Object)}
082 * .
083 *
084 * @return proxied {@link HttpBinding}.
085 */
086 @Override
087 public HttpBinding getBinding() {
088 return (HttpBinding)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {HttpBinding.class},
089 new HttpBindingInvocationHandler<GTaskEndpoint, HttpServletRequest, HttpServletResponse>(
090 this, super.getBinding(), getInboundBinding()));
091 }
092
093 /**
094 * @see #setWorkerRoot(String)
095 */
096 public String getWorkerRoot() {
097 return workerRoot;
098 }
099
100 /**
101 * Sets the web hook path root.
102 *
103 * @param workerRoot
104 * the assumed web hook path root. The default is
105 * <code>worker</code>. The servlet handling the callback from
106 * the task queueing service should have a <code>/worker/*</code>
107 * servlet mapping in this case. If another servlet mapping is
108 * used it must be set here accordingly.
109 */
110 public void setWorkerRoot(String workerRoot) {
111 this.workerRoot = workerRoot;
112 }
113
114 public Queue getQueue() {
115 return queue;
116 }
117
118 public void setQueue(Queue queue) {
119 this.queue = queue;
120 }
121
122 public Producer createProducer() throws Exception {
123 return new GTaskProducer(this);
124 }
125
126 }