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