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.jhc;
018    
019    import java.net.URI;
020    import java.util.Map;
021    
022    import org.apache.camel.Endpoint;
023    import org.apache.camel.HeaderFilterStrategyAware;
024    import org.apache.camel.impl.DefaultComponent;
025    import org.apache.camel.impl.DefaultHeaderFilterStrategy;
026    import org.apache.camel.spi.HeaderFilterStrategy;
027    import org.apache.commons.logging.Log;
028    import org.apache.commons.logging.LogFactory;
029    import org.apache.http.params.BasicHttpParams;
030    import org.apache.http.params.HttpConnectionParams;
031    import org.apache.http.params.HttpParams;
032    import org.apache.http.params.HttpProtocolParams;
033    
034    public class JhcComponent extends DefaultComponent<JhcExchange> implements HeaderFilterStrategyAware {
035    
036        private static final Log LOG = LogFactory.getLog(JhcComponent.class);
037    
038        private HttpParams params;
039    
040        private HeaderFilterStrategy headerFilterStrategy;
041    
042        public JhcComponent() {
043         
044            setHeaderFilterStrategy(new JhcHeaderFilterStrategy());
045            
046            params = new BasicHttpParams()
047                .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000)
048                .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000)
049                .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
050                .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
051                .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
052                .setParameter(HttpProtocolParams.USER_AGENT, "Camel-JhcComponent/1.1");
053        }
054    
055        public HttpParams getParams() {
056            return params;
057        }
058    
059        public void setParams(HttpParams params) {
060            this.params = params;
061        }
062    
063        protected Endpoint<JhcExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
064            return new JhcEndpoint(uri, this, new URI(uri.substring(uri.indexOf(':') + 1)));
065        }
066    
067        public HeaderFilterStrategy getHeaderFilterStrategy() {
068            return headerFilterStrategy;
069        }
070    
071        public void setHeaderFilterStrategy(HeaderFilterStrategy strategy) {
072            headerFilterStrategy = strategy;
073        }
074    
075    }