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.jetty;
018    
019    import java.net.URI;
020    import java.net.URISyntaxException;
021    import java.util.List;
022    
023    import org.apache.camel.Consumer;
024    import org.apache.camel.Processor;
025    import org.apache.camel.Producer;
026    import org.apache.camel.component.http.HttpConsumer;
027    import org.apache.camel.component.http.HttpEndpoint;
028    import org.mortbay.jetty.Handler;
029    import org.mortbay.jetty.client.HttpClient;
030    
031    /**
032     * @version $Revision: 834834 $
033     */
034    public class JettyHttpEndpoint extends HttpEndpoint {
035    
036        private boolean sessionSupport;
037        private List<Handler> handlers;
038        private HttpClient client;
039        private JettyHttpBinding jettyBinding;
040    
041        public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL) throws URISyntaxException {
042            super(uri, component, httpURL);
043        }
044    
045        @Override
046        public JettyHttpComponent getComponent() {
047            return (JettyHttpComponent) super.getComponent();
048        }
049    
050        @Override
051        public Producer createProducer() throws Exception {
052            JettyHttpProducer answer = new JettyHttpProducer(this, getClient());
053            answer.setBinding(getJettyBinding());
054            return answer;
055        }
056    
057        @Override
058        public Consumer createConsumer(Processor processor) throws Exception {
059            return new HttpConsumer(this, processor);
060        }   
061    
062        public void setSessionSupport(boolean support) {
063            sessionSupport = support;
064        }
065    
066        public boolean isSessionSupport() {
067            return sessionSupport;
068        }
069    
070        public List<Handler> getHandlers() {
071            return handlers;
072        }
073    
074        public void setHandlers(List<Handler> handlers) {
075            this.handlers = handlers;
076        }
077    
078        public HttpClient getClient() {
079            if (client == null) {
080                return getComponent().getHttpClient();
081            }
082            return client;
083        }
084    
085        public void setClient(HttpClient client) {
086            this.client = client;
087        }
088    
089        public synchronized JettyHttpBinding getJettyBinding() {
090            if (jettyBinding == null) {
091                jettyBinding = new DefaultJettyHttpBinding();
092                jettyBinding.setHeaderFilterStrategy(getHeaderFilterStrategy());
093                jettyBinding.setThrowExceptionOnFailure(isThrowExceptionOnFailure());
094            }
095            return jettyBinding;
096        }
097    
098        public void setJettyBinding(JettyHttpBinding jettyBinding) {
099            this.jettyBinding = jettyBinding;
100        }
101    }