Coverage Report - org.mule.providers.jbi.JbiMessageDispatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
JbiMessageDispatcher
0%
0/30
0%
0/1
1.222
 
 1  
 /*
 2  
  * $Id: JbiMessageDispatcher.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.jbi;
 12  
 
 13  
 import org.mule.impl.MuleMessage;
 14  
 import org.mule.providers.AbstractMessageDispatcher;
 15  
 import org.mule.umo.UMOEvent;
 16  
 import org.mule.umo.UMOMessage;
 17  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 18  
 
 19  
 import javax.jbi.messaging.ExchangeStatus;
 20  
 import javax.jbi.messaging.Fault;
 21  
 import javax.jbi.messaging.InOnly;
 22  
 import javax.jbi.messaging.InOut;
 23  
 import javax.jbi.messaging.MessageExchange;
 24  
 import javax.jbi.messaging.MessagingException;
 25  
 import javax.jbi.messaging.NormalizedMessage;
 26  
 
 27  
 /**
 28  
  * <code>TcpMessageDispatcher</code> will send transformed mule events over tcp.
 29  
  * 
 30  
  * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
 31  
  * @version $Revision: 7976 $
 32  
  */
 33  
 
 34  
 public class JbiMessageDispatcher extends AbstractMessageDispatcher
 35  
 {
 36  
     private JbiConnector connector;
 37  
 
 38  
     public JbiMessageDispatcher(UMOImmutableEndpoint endpoint)
 39  
     {
 40  0
         super(endpoint);
 41  0
         this.connector = (JbiConnector)endpoint.getConnector();
 42  0
     }
 43  
 
 44  
     protected void doDispose()
 45  
     {
 46  
         // nothing to do
 47  0
     }
 48  
 
 49  
     protected void doDispatch(UMOEvent event) throws Exception
 50  
     {
 51  0
         InOnly exchange = connector.getExchangeFactory().createInOnlyExchange();
 52  0
         NormalizedMessage message = exchange.createMessage();
 53  0
         exchange.setInMessage(message);
 54  0
         JbiUtils.populateNormalizedMessage(event.getMessage(), message);
 55  0
         done(exchange);
 56  0
     }
 57  
 
 58  
     protected UMOMessage doSend(UMOEvent event) throws Exception
 59  
     {
 60  0
         InOut exchange = connector.getExchangeFactory().createInOutExchange();
 61  0
         NormalizedMessage message = exchange.createMessage();
 62  0
         exchange.setInMessage(message);
 63  0
         JbiUtils.populateNormalizedMessage(event.getMessage(), message);
 64  0
         NormalizedMessage nm = exchange.getOutMessage();
 65  0
         UMOMessage response = null;
 66  0
         if (nm != null)
 67  
         {
 68  0
             response = new MuleMessage(connector.getMessageAdapter(nm));
 69  
         }
 70  0
         done(exchange);
 71  0
         return response;
 72  
     }
 73  
 
 74  
     /**
 75  
      * Make a specific request to the underlying transport
 76  
      * 
 77  
      * @param endpoint the endpoint to use when connecting to the resource
 78  
      * @param timeout the maximum time the operation should block before returning.
 79  
      *            The call should return immediately if there is data available. If
 80  
      *            no data becomes available before the timeout elapses, null will be
 81  
      *            returned
 82  
      * @return the result of the request wrapped in a UMOMessage object. Null will be
 83  
      *         returned if no data was avaialable
 84  
      * @throws Exception if the call to the underlying protocal cuases an exception
 85  
      */
 86  
     protected UMOMessage doReceive(long timeout) throws Exception
 87  
     {
 88  0
         throw new UnsupportedOperationException("doReceive");
 89  
     }
 90  
 
 91  
     protected void error(MessageExchange me, Fault fault) throws MessagingException
 92  
     {
 93  0
         me.setFault(fault);
 94  0
         me.setStatus(ExchangeStatus.ERROR);
 95  0
         connector.getDeliveryChannel().send(me);
 96  0
     }
 97  
 
 98  
     protected void done(MessageExchange me) throws MessagingException
 99  
     {
 100  0
         me.setStatus(ExchangeStatus.DONE);
 101  0
         connector.getDeliveryChannel().send(me);
 102  0
     }
 103  
 
 104  
     protected void doConnect() throws Exception
 105  
     {
 106  
         // no op
 107  0
     }
 108  
 
 109  
     protected void doDisconnect() throws Exception
 110  
     {
 111  
         // no op
 112  0
     }
 113  
 
 114  
 }