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 org.apache.camel.Endpoint;
023    import org.apache.camel.component.gae.bind.InboundBinding;
024    import org.apache.camel.component.gae.bind.OutboundBinding;
025    import org.apache.camel.component.http.HttpClientConfigurer;
026    import org.apache.camel.component.servlet.ServletComponent;
027    import org.apache.camel.component.servlet.ServletEndpoint;
028    import org.apache.commons.httpclient.HttpConnectionManager;
029    import org.apache.commons.httpclient.params.HttpClientParams;
030    
031    /**
032     * The <a href="http://camel.apache.org/ghttp.html">Google App Engine HTTP
033     * Component</a> supports HTTP-based inbound and outbound communication. Inbound
034     * HTTP communication is realized in terms of the <a
035     * href="http://camel.apache.org/servlet.html"> Servlet Component</a> component.
036     * Outbound HTTP communication uses the URL fetch service of the Google App
037     * Engine.
038     */
039    public class GHttpComponent extends ServletComponent {
040    
041        @Override
042        @SuppressWarnings("unchecked")
043        protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
044            boolean throwException = getAndRemoveParameter(parameters, "throwExceptionOnFailure", Boolean.class, true); 
045            boolean bridgeEndpoint = getAndRemoveParameter(parameters, "bridgeEndpoint", Boolean.class, true); 
046            OutboundBinding outboundBinding = resolveAndRemoveReferenceParameter(
047                    parameters, "outboundBindingRef", OutboundBinding.class, new GHttpBinding());
048            InboundBinding inboundBinding = resolveAndRemoveReferenceParameter(
049                    parameters, "inboundBindingRef", InboundBinding.class, new GHttpBinding());
050            GHttpEndpoint endpoint = (GHttpEndpoint)super.createEndpoint(uri, remaining, parameters);
051            endpoint.setThrowExceptionOnFailure(throwException);
052            endpoint.setBridgeEndpoint(bridgeEndpoint);
053            endpoint.setOutboundBinding(outboundBinding);
054            endpoint.setInboundBinding(inboundBinding);
055            return endpoint;
056        }
057    
058        @Override
059        protected ServletEndpoint createServletEndpoint(String endpointUri,
060                ServletComponent component, URI httpUri, HttpClientParams params,
061                HttpConnectionManager httpConnectionManager,
062                HttpClientConfigurer clientConfigurer) throws Exception {
063            return new GHttpEndpoint(endpointUri, component, httpUri, params,
064                    httpConnectionManager, clientConfigurer);
065        }
066    }