Coverage Report - org.mule.transport.xmpp.XmppMessageDispatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
XmppMessageDispatcher
0%
0/21
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: XmppMessageDispatcher.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.xmpp;
 12  
 
 13  
 import org.mule.DefaultMuleMessage;
 14  
 import org.mule.api.MuleEvent;
 15  
 import org.mule.api.MuleMessage;
 16  
 import org.mule.api.endpoint.OutboundEndpoint;
 17  
 import org.mule.transformer.types.DataTypeFactory;
 18  
 import org.mule.transport.AbstractMessageDispatcher;
 19  
 import org.mule.transport.NullPayload;
 20  
 
 21  
 import org.jivesoftware.smack.packet.Message;
 22  
 
 23  
 /**
 24  
  * Allows Mule events to be sent over Xmpp
 25  
  */
 26  
 public class XmppMessageDispatcher extends AbstractMessageDispatcher
 27  
 {
 28  
     private final XmppConnector connector;
 29  
     private XmppConversation conversation;
 30  
 
 31  
     public XmppMessageDispatcher(OutboundEndpoint endpoint)
 32  
     {
 33  0
         super(endpoint);
 34  0
         connector = (XmppConnector) endpoint.getConnector();
 35  0
         conversation = connector.getConversationFactory().create(endpoint);
 36  0
     }
 37  
 
 38  
     @Override
 39  
     protected void doConnect() throws Exception
 40  
     {
 41  0
         conversation.connect();
 42  0
     }
 43  
 
 44  
     @Override
 45  
     protected void doDisconnect() throws Exception
 46  
     {
 47  0
         conversation.disconnect();
 48  0
     }
 49  
 
 50  
     @Override
 51  
     protected void doDispose()
 52  
     {
 53  0
         conversation = null;
 54  0
     }
 55  
 
 56  
     @Override
 57  
     protected void doDispatch(MuleEvent event) throws Exception
 58  
     {
 59  0
         sendMessage(event);
 60  0
     }
 61  
 
 62  
     @Override
 63  
     protected MuleMessage doSend(MuleEvent event) throws Exception
 64  
     {
 65  0
         sendMessage(event);
 66  
 
 67  
         // TODO xmpp: even sync endpoints do not wait for a reply. Look at how the JMS transport handles replies, use reply handler
 68  
 //        if (returnResponse(event, false))
 69  
 //        {
 70  
 //            Message response = conversation.receive(event.getTimeout());
 71  
 //
 72  
 ////            if (groupChat != null)
 73  
 ////            {
 74  
 ////                response = groupChat.nextMessage(event.getTimeout());
 75  
 ////            }
 76  
 //
 77  
 //            if (response != null)
 78  
 //            {
 79  
 //                return createMuleMessage(response);
 80  
 //            }
 81  
 //        }
 82  0
         return new DefaultMuleMessage(NullPayload.getInstance(), connector.getMuleContext());
 83  
     }
 84  
 
 85  
     protected void sendMessage(MuleEvent event) throws Exception
 86  
     {
 87  0
         Object payload = event.getMessage().getPayload();
 88  
         
 89  0
         Message jabberMessage = (Message) event.getMessage().getPayload(DataTypeFactory.create(Message.class));
 90  
 
 91  0
         conversation.dispatch(jabberMessage);
 92  
         
 93  0
         if (logger.isDebugEnabled())
 94  
         {
 95  0
             String recipient = XmppConnector.getRecipient(endpoint);
 96  0
             logger.debug("Message \"" + jabberMessage.getBody() 
 97  
                 + "\" successfully sent to " + recipient);
 98  
         }
 99  0
     }
 100  
 }