1 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.UMOException; 17 import org.mule.umo.UMOMessage; 18 import org.mule.umo.endpoint.UMOImmutableEndpoint; 19 20 import javax.jbi.messaging.ExchangeStatus; 21 import javax.jbi.messaging.Fault; 22 import javax.jbi.messaging.InOnly; 23 import javax.jbi.messaging.InOut; 24 import javax.jbi.messaging.MessageExchange; 25 import javax.jbi.messaging.MessagingException; 26 import javax.jbi.messaging.NormalizedMessage; 27 28 34 35 public class JbiMessageDispatcher extends AbstractMessageDispatcher 36 { 37 private JbiConnector connector; 38 39 public JbiMessageDispatcher(UMOImmutableEndpoint endpoint) 40 { 41 super(endpoint); 42 this.connector = (JbiConnector)endpoint.getConnector(); 43 } 44 45 protected void doDispose() 46 { 47 } 49 50 protected void doDispatch(UMOEvent event) throws Exception 51 { 52 InOnly exchange = connector.getExchangeFactory().createInOnlyExchange(); 53 NormalizedMessage message = exchange.createMessage(); 54 exchange.setInMessage(message); 55 JbiUtils.populateNormalizedMessage(event.getMessage(), message); 56 done(exchange); 57 } 58 59 protected UMOMessage doSend(UMOEvent event) throws Exception 60 { 61 InOut exchange = connector.getExchangeFactory().createInOutExchange(); 62 NormalizedMessage message = exchange.createMessage(); 63 exchange.setInMessage(message); 64 JbiUtils.populateNormalizedMessage(event.getMessage(), message); 65 NormalizedMessage nm = exchange.getOutMessage(); 66 UMOMessage response = null; 67 if (nm != null) 68 { 69 response = new MuleMessage(connector.getMessageAdapter(nm)); 70 } 71 done(exchange); 72 return response; 73 } 74 75 87 protected UMOMessage doReceive(UMOImmutableEndpoint endpoint, long timeout) throws Exception 88 { 89 throw new UnsupportedOperationException ("doReceive"); 90 } 91 92 public Object getDelegateSession() throws UMOException 93 { 94 return null; 95 } 96 97 protected void error(MessageExchange me, Fault fault) throws MessagingException 98 { 99 me.setFault(fault); 100 me.setStatus(ExchangeStatus.ERROR); 101 connector.getDeliveryChannel().send(me); 102 } 103 104 protected void done(MessageExchange me) throws MessagingException 105 { 106 me.setStatus(ExchangeStatus.DONE); 107 connector.getDeliveryChannel().send(me); 108 } 109 110 protected void doConnect(UMOImmutableEndpoint endpoint) throws Exception 111 { 112 } 114 115 protected void doDisconnect() throws Exception 116 { 117 } 119 120 } 121 | Popular Tags |