Coverage Report - org.apache.camel.component.xmpp.XmppBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppBinding
0% 
0% 
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.xmpp;
 19  
 
 20  
 import org.jivesoftware.smack.packet.Message;
 21  
 import org.apache.camel.Exchange;
 22  
 
 23  
 import java.util.Map;
 24  
 import java.util.Set;
 25  
 
 26  
 /**
 27  
  * A Strategy used to convert between a Camel {@XmppExchange} and {@XmppMessage} to and from a
 28  
  * XMPP {@link Message}
 29  
  *
 30  
  * @version $Revision: 534145 $
 31  
  */
 32  0
 public class XmppBinding {
 33  
     /**
 34  
      * Populates the given XMPP message from the inbound exchange
 35  
      */
 36  
     public void populateXmppMessage(Message message, Exchange exchange) {
 37  0
         message.setBody(exchange.getIn().getBody(String.class));
 38  
 
 39  0
         Set<Map.Entry<String, Object>> entries = exchange.getIn().getHeaders().entrySet();
 40  0
         for (Map.Entry<String, Object> entry : entries) {
 41  0
             String name = entry.getKey();
 42  0
             Object value = entry.getValue();
 43  0
             if (shouldOutputHeader(exchange, name, value)) {
 44  0
                 message.setProperty(name, value);
 45  
             }
 46  0
         }
 47  0
         String id = exchange.getExchangeId();
 48  0
         if (id != null) {
 49  0
             message.setProperty("exchangeId", id);
 50  
         }
 51  0
     }
 52  
 
 53  
     /**
 54  
      * Extracts the body from the XMPP message
 55  
      *
 56  
      * @param exchange
 57  
      * @param message
 58  
      */
 59  
     public Object extractBodyFromXmpp(XmppExchange exchange, Message message) {
 60  0
         return message.getBody();
 61  
     }
 62  
 
 63  
     /**
 64  
      * Strategy to allow filtering of headers which are put on the XMPP message
 65  
      */
 66  
     protected boolean shouldOutputHeader(Exchange exchange, String headerName, Object headerValue) {
 67  0
         return true;
 68  
     }
 69  
 }