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.http;
018
019 import java.net.URI;
020 import java.util.Map;
021
022 import com.google.appengine.api.urlfetch.URLFetchService;
023 import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
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/todo.html">Google App Engine HTTP
036 * Component</a> supports HTTP-based inbound and outbound communication. Inbound
037 * HTTP communication is realized in terms of the <a
038 * href="http://camel.apache.org/servlet.html"> Servlet Component</a> component.
039 * Outbound HTTP communication uses the URL fetch service of the Google App
040 * Engine.
041 */
042 public class GHttpComponent extends ServletComponent {
043
044 @Override
045 @SuppressWarnings("unchecked")
046 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
047 boolean throwException = getAndRemoveParameter(parameters, "throwExceptionOnFailure", Boolean.class, true);
048 boolean bridgeEndpoint = getAndRemoveParameter(parameters, "bridgeEndpoint", Boolean.class, true);
049 OutboundBinding outboundBinding = resolveAndRemoveReferenceParameter(
050 parameters, "outboundBindingRef", OutboundBinding.class, new GHttpBinding());
051 InboundBinding inboundBinding = resolveAndRemoveReferenceParameter(
052 parameters, "inboundBindingRef", InboundBinding.class, new GHttpBinding());
053 URLFetchService service = resolveAndRemoveReferenceParameter(
054 parameters, "urlFetchServiceRef", URLFetchService.class, URLFetchServiceFactory.getURLFetchService());
055 GHttpEndpoint endpoint = (GHttpEndpoint)super.createEndpoint(uri, remaining, parameters);
056 endpoint.setThrowExceptionOnFailure(throwException);
057 endpoint.setBridgeEndpoint(bridgeEndpoint);
058 endpoint.setOutboundBinding(outboundBinding);
059 endpoint.setInboundBinding(inboundBinding);
060 endpoint.setUrlFetchService(service);
061 return endpoint;
062 }
063
064 @Override
065 protected ServletEndpoint createServletEndpoint(String endpointUri,
066 ServletComponent component, URI httpUri, HttpClientParams params,
067 HttpConnectionManager httpConnectionManager,
068 HttpClientConfigurer clientConfigurer) throws Exception {
069 return new GHttpEndpoint(endpointUri, component, httpUri, params,
070 httpConnectionManager, clientConfigurer);
071 }
072 }