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    
021    import org.apache.camel.Consumer;
022    import org.apache.camel.HeaderFilterStrategyAware;
023    import org.apache.camel.Processor;
024    import org.apache.camel.Producer;
025    import org.apache.camel.impl.DefaultEndpoint;
026    import org.apache.camel.spi.HeaderFilterStrategy;
027    import org.apache.http.params.BasicHttpParams;
028    import org.apache.http.params.HttpParams;
029    
030    /**
031     * Created by IntelliJ IDEA.
032     * User: gnodet
033     * Date: Sep 7, 2007
034     * Time: 8:06:42 PM
035     * To change this template use File | Settings | File Templates.
036     */
037    public class JhcEndpoint extends DefaultEndpoint<JhcExchange> {
038    
039        private HttpParams params;
040        private URI httpUri;
041    
042        public JhcEndpoint(String endpointUri, JhcComponent component, URI httpUri) {
043            super(endpointUri, component);
044            params = component.getParams().copy();
045            this.httpUri = httpUri;
046        }
047    
048        public JhcEndpoint(String endpointUri, URI httpUri, HttpParams params) {
049            super(endpointUri);
050            this.httpUri = httpUri;
051            this.params = params;
052        }
053    
054        public HttpParams getParams() {
055            return params;
056        }
057    
058        public void setParams(HttpParams params) {
059            this.params = params;
060        }
061    
062        public URI getHttpUri() {
063            return httpUri;
064        }
065    
066        public void setHttpUri(URI httpUri) {
067            this.httpUri = httpUri;
068        }
069    
070        public String getProtocol() {
071            return httpUri.getScheme();
072        }
073    
074        public String getHost() {
075            return httpUri.getHost();
076        }
077    
078        public int getPort() {
079            if (httpUri.getPort() == -1) {
080                if ("https".equals(getProtocol())) {
081                    return 443;
082                } else {
083                    return 80;
084                }
085            }
086            return httpUri.getPort();
087        }
088    
089        public String getPath() {
090            return httpUri.getPath();
091        }
092    
093        public boolean isSingleton() {
094            return true;
095        }
096    
097        public Producer<JhcExchange> createProducer() throws Exception {
098            return new JhcProducer(this);
099        }
100    
101        public Consumer<JhcExchange> createConsumer(Processor processor) throws Exception {
102            return new JhcConsumer(this, processor);
103        }
104    
105        public HeaderFilterStrategy getHeaderFilterStrategy() {
106            if (getComponent() instanceof HeaderFilterStrategyAware) {
107                return ((HeaderFilterStrategyAware)getComponent()).getHeaderFilterStrategy();
108            } else {
109                return new JhcHeaderFilterStrategy();
110            }
111        }
112    }