Coverage Report - org.apache.camel.component.http.HttpMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpMessage
89% 
100% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.http;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.util.Enumeration;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 
 25  
 import org.apache.camel.RuntimeCamelException;
 26  
 import org.apache.camel.impl.DefaultMessage;
 27  
 
 28  
 /**
 29  
  * @version $Revision: 563665 $
 30  
  */
 31  2
 public class HttpMessage extends DefaultMessage {
 32  
     private HttpServletRequest request;
 33  
 
 34  2
     public HttpMessage(HttpExchange exchange, HttpServletRequest request) {
 35  2
         setExchange(exchange);
 36  2
         this.request = request;
 37  
 
 38  
         // lets force a parse of the body and headers
 39  2
         getBody();
 40  2
         getHeaders();
 41  2
     }
 42  
 
 43  
     @Override
 44  
     public HttpExchange getExchange() {
 45  4
         return (HttpExchange)super.getExchange();
 46  
     }
 47  
 
 48  
     public HttpServletRequest getRequest() {
 49  2
         return request;
 50  
     }
 51  
 
 52  
     @Override
 53  
     protected Object createBody() {
 54  
         try {
 55  2
             return getExchange().getEndpoint().getBinding().parseBody(this);
 56  0
         } catch (IOException e) {
 57  0
             throw new RuntimeCamelException(e);
 58  
         }
 59  
     }
 60  
 
 61  
     @Override
 62  
     protected void populateInitialHeaders(Map<String, Object> map) {
 63  2
         Enumeration names = request.getHeaderNames();
 64  14
         while (names.hasMoreElements()) {
 65  12
             String name = (String)names.nextElement();
 66  12
             Object value = request.getHeader(name);
 67  12
             map.put(name, value);
 68  12
         }
 69  2
     }
 70  
 }