Coverage Report - org.mule.transport.xmpp.XmppMessageDispatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppMessageDispatcher
0%
0/20
0%
0/2
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.MuleEvent;
 11  
 import org.mule.api.MuleMessage;
 12  
 import org.mule.api.endpoint.OutboundEndpoint;
 13  
 import org.mule.transformer.types.DataTypeFactory;
 14  
 import org.mule.transport.AbstractMessageDispatcher;
 15  
 import org.mule.transport.NullPayload;
 16  
 
 17  
 import org.jivesoftware.smack.packet.Message;
 18  
 
 19  
 /**
 20  
  * Allows Mule events to be sent over Xmpp
 21  
  */
 22  
 public class XmppMessageDispatcher extends AbstractMessageDispatcher
 23  
 {
 24  
     private final XmppConnector connector;
 25  
     private XmppConversation conversation;
 26  
 
 27  
     public XmppMessageDispatcher(OutboundEndpoint endpoint)
 28  
     {
 29  0
         super(endpoint);
 30  0
         connector = (XmppConnector) endpoint.getConnector();
 31  0
         conversation = connector.getConversationFactory().create(endpoint);
 32  0
     }
 33  
 
 34  
     @Override
 35  
     protected void doConnect() throws Exception
 36  
     {
 37  0
         conversation.connect();
 38  0
     }
 39  
 
 40  
     @Override
 41  
     protected void doDisconnect() throws Exception
 42  
     {
 43  0
         conversation.disconnect();
 44  0
     }
 45  
 
 46  
     @Override
 47  
     protected void doDispose()
 48  
     {
 49  0
         conversation = null;
 50  0
     }
 51  
 
 52  
     @Override
 53  
     protected void doDispatch(MuleEvent event) throws Exception
 54  
     {
 55  0
         sendMessage(event);
 56  0
     }
 57  
 
 58  
     @Override
 59  
     protected MuleMessage doSend(MuleEvent event) throws Exception
 60  
     {
 61  0
         sendMessage(event);
 62  
 
 63  
         // TODO xmpp: even sync endpoints do not wait for a reply. Look at how the JMS transport handles replies, use reply handler
 64  
 //        if (returnResponse(event, false))
 65  
 //        {
 66  
 //            Message response = conversation.receive(event.getTimeout());
 67  
 //
 68  
 ////            if (groupChat != null)
 69  
 ////            {
 70  
 ////                response = groupChat.nextMessage(event.getTimeout());
 71  
 ////            }
 72  
 //
 73  
 //            if (response != null)
 74  
 //            {
 75  
 //                return createMuleMessage(response);
 76  
 //            }
 77  
 //        }
 78  0
         return new DefaultMuleMessage(NullPayload.getInstance(), connector.getMuleContext());
 79  
     }
 80  
 
 81  
     protected void sendMessage(MuleEvent event) throws Exception
 82  
     {
 83  0
         Message jabberMessage = event.getMessage().getPayload(DataTypeFactory.create(Message.class));
 84  0
         conversation.dispatch(jabberMessage);
 85  
 
 86  0
         if (logger.isDebugEnabled())
 87  
         {
 88  0
             String recipient = XmppConnector.getRecipient(endpoint);
 89  0
             logger.debug("Message \"" + jabberMessage.getBody()
 90  
                 + "\" successfully sent to " + recipient);
 91  
         }
 92  0
     }
 93  
 }