Coverage Report - org.apache.camel.component.http.HttpMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
HttpMessage
89% 
100% 
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 org.apache.camel.impl.DefaultMessage;
 21  
 import org.apache.camel.Exchange;
 22  
 import org.apache.camel.RuntimeCamelException;
 23  
 
 24  
 import javax.servlet.http.HttpServletRequest;
 25  
 import java.util.Map;
 26  
 import java.util.Enumeration;
 27  
 import java.io.IOException;
 28  
 
 29  
 /**
 30  
  * @version $Revision: 550444 $
 31  
  */
 32  2
 public class HttpMessage extends DefaultMessage {
 33  
     private HttpServletRequest request;
 34  
 
 35  
 
 36  2
     public HttpMessage(HttpExchange exchange, HttpServletRequest request) {
 37  2
         setExchange(exchange);
 38  2
         this.request = request;
 39  
 
 40  
         // lets force a parse of the body and headers
 41  2
         getBody();
 42  2
         getHeaders();
 43  2
     }
 44  
 
 45  
     @Override
 46  
     public HttpExchange getExchange() {
 47  4
         return (HttpExchange) super.getExchange();
 48  
     }
 49  
 
 50  
     public HttpServletRequest getRequest() {
 51  2
         return request;
 52  
     }
 53  
 
 54  
     @Override
 55  
     protected Object createBody() {
 56  
         try {
 57  2
             return getExchange().getEndpoint().getBinding().parseBody(this);
 58  
         }
 59  0
         catch (IOException e) {
 60  0
             throw new RuntimeCamelException(e);
 61  
         }
 62  
     }
 63  
 
 64  
     @Override
 65  
     protected void populateInitialHeaders(Map<String, Object> map) {
 66  2
         Enumeration names = request.getHeaderNames();
 67  14
         while (names.hasMoreElements()) {
 68  12
             String name = (String) names.nextElement();
 69  12
             Object value = request.getHeader(name);
 70  12
             map.put(name, value);
 71  12
         }
 72  2
     }
 73  
 }