Coverage Report - org.mule.transport.xmpp.XmppMuleMessageFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppMuleMessageFactory
0%
0/20
0%
0/4
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.xmpp;
 8  
 
 9  
 import org.mule.DefaultMuleMessage;
 10  
 import org.mule.api.MuleContext;
 11  
 import org.mule.transport.AbstractMuleMessageFactory;
 12  
 
 13  
 import java.util.HashMap;
 14  
 import java.util.Map;
 15  
 
 16  
 import org.jivesoftware.smack.packet.Message;
 17  
 import org.jivesoftware.smack.packet.Packet;
 18  
 
 19  
 public class XmppMuleMessageFactory extends AbstractMuleMessageFactory
 20  
 {
 21  
     public XmppMuleMessageFactory(MuleContext context)
 22  
     {
 23  0
         super(context);
 24  0
     }
 25  
 
 26  
     @Override
 27  
     protected Class<?>[] getSupportedTransportMessageTypes()
 28  
     {
 29  0
         return new Class[] { Packet.class };
 30  
     }
 31  
 
 32  
     @Override
 33  
     protected Object extractPayload(Object transportMessage, String encoding) throws Exception
 34  
     {
 35  0
         return transportMessage;
 36  
     }
 37  
 
 38  
     @Override
 39  
     protected void addProperties(DefaultMuleMessage message, Object transportMessage) throws Exception
 40  
     {
 41  0
         super.addProperties(message, transportMessage);
 42  
         
 43  0
         Packet packet = (Packet) transportMessage;
 44  
 
 45  0
         message.setUniqueId(packet.getPacketID());
 46  
         
 47  0
         Map<String, Object> properties = new HashMap<String, Object>();
 48  0
         addXmppPacketProperties(packet, properties);
 49  
 
 50  0
         if (packet instanceof Message)
 51  
         {
 52  0
             Message xmppMessage = (Message) packet;
 53  0
             addXmppMessageProperties(xmppMessage, properties);
 54  
         }
 55  
         
 56  0
         message.addInboundProperties(properties);
 57  0
     }
 58  
 
 59  
     private void addXmppPacketProperties(Packet packet, Map<String, Object> properties)
 60  
     {
 61  0
         for (String key : packet.getPropertyNames())
 62  
         {
 63  0
             properties.put(key, packet.getProperty(key));
 64  
         }        
 65  0
     }
 66  
 
 67  
     private void addXmppMessageProperties(Message message, Map<String, Object> properties)
 68  
     {
 69  0
         properties.put(XmppConnector.XMPP_SUBJECT, message.getSubject());
 70  0
         properties.put(XmppConnector.XMPP_THREAD, message.getThread());
 71  0
     }
 72  
 }
 73  
 
 74