Coverage Report - org.apache.camel.component.cxf.CxfBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
CxfBinding
20% 
20% 
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.cxf;
 19  
 
 20  
 import org.apache.cxf.message.Message;
 21  
 import org.apache.cxf.message.MessageImpl;
 22  
 
 23  
 import java.io.InputStream;
 24  
 import java.util.Set;
 25  
 
 26  
 /**
 27  
  * The binding of how Camel messages get mapped to Apache CXF and back again
 28  
  *
 29  
  * @version $Revision: 525898 $
 30  
  */
 31  1
 public class CxfBinding {
 32  
 
 33  
     public Object extractBodyFromCxf(CxfExchange exchange, Message message) {
 34  
         //  TODO how do we choose a format?
 35  0
         return getBody(message);
 36  
     }
 37  
 
 38  
     protected Object getBody(Message message) {
 39  0
         Set<Class<?>> contentFormats = message.getContentFormats();
 40  0
         for (Class<?> contentFormat : contentFormats) {
 41  0
             Object answer = message.getContent(contentFormat);
 42  0
             if (answer != null) {
 43  0
                 return answer;
 44  
             }
 45  0
         }
 46  0
         return null;
 47  
     }
 48  
 
 49  
     public MessageImpl createCxfMessage(CxfExchange exchange) {
 50  0
         MessageImpl answer = (MessageImpl) exchange.getInMessage();
 51  
 
 52  
         // TODO is InputStream the best type to give to CXF?
 53  0
         CxfMessage in = exchange.getIn();
 54  0
         Object body = in.getBody(InputStream.class);
 55  0
         if (body == null) {
 56  0
             body = in.getBody();
 57  
         }
 58  0
         answer.setContent(InputStream.class, body);
 59  
 
 60  
         // no need to process headers as we reuse the CXF message
 61  
         /*
 62  
         // set the headers
 63  
         Set<Map.Entry<String, Object>> entries = in.getHeaders().entrySet();
 64  
         for (Map.Entry<String, Object> entry : entries) {
 65  
             answer.put(entry.getKey(), entry.getValue());
 66  
         }
 67  
         */
 68  0
         return answer;
 69  
     }
 70  
 
 71  
     public void storeCxfResponse(CxfExchange exchange, Message response) {
 72  
         // no need to process headers as we use the CXF message
 73  0
         CxfMessage out = exchange.getOut();
 74  0
         if (response != null) {
 75  0
             out.setMessage(response);
 76  0
             out.setBody(getBody(response));
 77  
         }
 78  0
     }
 79  
 
 80  
     public void storeCxfResponse(CxfExchange exchange, Object response) {
 81  1
         CxfMessage out = exchange.getOut();
 82  1
         if (response != null) {
 83  1
             out.setBody(response);
 84  
         }
 85  1
     }
 86  
 }