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.apache.camel.impl.SynchronousDelegateProducer;
029    import org.eclipse.jetty.client.HttpClient;
030    import org.eclipse.jetty.server.Handler;
031    
032    /**
033     * @version $Revision: 987398 $
034     */
035    public class JettyHttpEndpoint extends HttpEndpoint {
036    
037        private boolean sessionSupport;
038        private List<Handler> handlers;
039        private HttpClient client;
040        private JettyHttpBinding jettyBinding;
041        private boolean enableJmx;
042        private boolean enableMultipartFilter;
043    
044        public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL) throws URISyntaxException {
045            super(uri, component, httpURL);
046        }
047    
048        @Override
049        public JettyHttpComponent getComponent() {
050            return (JettyHttpComponent) super.getComponent();
051        }
052    
053        @Override
054        public Producer createProducer() throws Exception {
055            JettyHttpProducer answer = new JettyHttpProducer(this, getClient());
056            answer.setBinding(getJettyBinding());
057            if (isSynchronous()) {
058                return new SynchronousDelegateProducer(answer);
059            } else {
060                return answer;
061            }
062        }
063    
064        @Override
065        public Consumer createConsumer(Processor processor) throws Exception {
066            return new HttpConsumer(this, processor);
067        }   
068    
069        public void setSessionSupport(boolean support) {
070            sessionSupport = support;
071        }
072    
073        public boolean isSessionSupport() {
074            return sessionSupport;
075        }
076       
077        public List<Handler> getHandlers() {
078            return handlers;
079        }
080    
081        public void setHandlers(List<Handler> handlers) {
082            this.handlers = handlers;
083        }
084    
085        public HttpClient getClient() {
086            if (client == null) {
087                return getComponent().getHttpClient();
088            }
089            return client;
090        }
091    
092        public void setClient(HttpClient client) {
093            this.client = client;
094        }
095    
096        public synchronized JettyHttpBinding getJettyBinding() {
097            if (jettyBinding == null) {
098                jettyBinding = new DefaultJettyHttpBinding();
099                jettyBinding.setHeaderFilterStrategy(getHeaderFilterStrategy());
100                jettyBinding.setThrowExceptionOnFailure(isThrowExceptionOnFailure());
101            }
102            return jettyBinding;
103        }
104    
105        public void setJettyBinding(JettyHttpBinding jettyBinding) {
106            this.jettyBinding = jettyBinding;
107        }
108    
109        public boolean isEnableJmx() {
110            return this.enableJmx;
111        }
112    
113        public void setEnableJmx(boolean enableJmx) {
114            this.enableJmx = enableJmx;
115        }
116        
117        public boolean isEnableMultipartFilter() {
118            return enableMultipartFilter;
119        }
120    
121        public void setEnableMultipartFilter(boolean enableMultipartFilter) {
122            this.enableMultipartFilter = enableMultipartFilter;
123        }    
124    }