Coverage Report - org.apache.camel.component.http.HttpEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpEndpoint
77% 
67% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.http;
 19  
 
 20  
 import java.net.URI;
 21  
 import java.net.URISyntaxException;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import javax.servlet.http.HttpServletResponse;
 25  
 
 26  
 import org.apache.camel.Consumer;
 27  
 import org.apache.camel.Processor;
 28  
 import org.apache.camel.Producer;
 29  
 import org.apache.camel.RuntimeCamelException;
 30  
 import org.apache.camel.impl.DefaultEndpoint;
 31  
 
 32  
 /**
 33  
  * Represents a <a href="http://activemq.apache.org/camel/http.html">HTTP endpoint</a>
 34  
  *
 35  
  * @version $Revision: 550760 $
 36  
  */
 37  2
 public class HttpEndpoint extends DefaultEndpoint<HttpExchange> {
 38  
 
 39  
     private HttpBinding binding;
 40  
         private HttpComponent component;
 41  
         private URI httpUri;
 42  
         
 43  
     protected HttpEndpoint(String uri, HttpComponent component) throws URISyntaxException {
 44  2
         super(uri, component);
 45  2
                 this.component = component;
 46  2
                 this.httpUri = new URI(uri);
 47  2
     }
 48  
 
 49  
     public HttpProducer createProducer() throws Exception {
 50  1
             return new HttpProducer(this);
 51  
     }
 52  
 
 53  
     public Consumer<HttpExchange> createConsumer(Processor processor) throws Exception {
 54  2
         return new HttpConsumer(this, processor);
 55  
     }
 56  
 
 57  
     public HttpExchange createExchange() {
 58  1
         return new HttpExchange(this);
 59  
     }
 60  
 
 61  
     public HttpExchange createExchange(HttpServletRequest request, HttpServletResponse response) {
 62  0
         return new HttpExchange(this, request, response);
 63  
     }
 64  
 
 65  
     public HttpBinding getBinding() {
 66  4
         if (binding == null) {
 67  2
             binding = new HttpBinding();
 68  
         }
 69  4
         return binding;
 70  
     }
 71  
 
 72  
     public void setBinding(HttpBinding binding) {
 73  0
         this.binding = binding;
 74  0
     }
 75  
     
 76  
         public boolean isSingleton() {
 77  2
                 return true;
 78  
         }
 79  
 
 80  
         public void connect(HttpConsumer consumer) throws Exception {
 81  2
                 component.connect(consumer);
 82  2
         }
 83  
 
 84  
         public void disconnect(HttpConsumer consumer) throws Exception {
 85  2
                 component.disconnect(consumer);
 86  2
         }
 87  
 
 88  
         public String getPath() {
 89  4
                 return httpUri.getPath();
 90  
         }
 91  
 
 92  
         public int getPort() {
 93  6
                 if( httpUri.getPort() == -1 ) {
 94  0
                         if( "https".equals(getProtocol() ) ) {
 95  0
                                 return 443;
 96  
                         } else {
 97  0
                                 return 80;
 98  
                         }
 99  
                 }
 100  6
                 return httpUri.getPort();
 101  
         }
 102  
 
 103  
         public String getProtocol() {
 104  6
                 return httpUri.getScheme(); 
 105  
         }
 106  
 }