1 17 package org.apache.servicemix.components.jms; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.messaging.ExchangeStatus; 21 import javax.jbi.messaging.InOnly; 22 import javax.jbi.messaging.MessageExchange; 23 import javax.jbi.messaging.MessagingException; 24 import javax.jbi.messaging.NormalizedMessage; 25 import javax.jms.JMSException ; 26 import javax.jms.Message ; 27 import javax.jms.MessageListener ; 28 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 import org.apache.servicemix.MessageExchangeListener; 32 import org.apache.servicemix.components.util.ComponentSupport; 33 import org.apache.servicemix.jbi.RuntimeJBIException; 34 35 41 public class JmsInBinding extends ComponentSupport implements MessageListener , MessageExchangeListener { 42 private static final Log log = LogFactory.getLog(JmsInBinding.class); 43 44 private JmsMarshaler marshaler = new JmsMarshaler(); 45 46 public JmsMarshaler getMarshaler() { 47 return marshaler; 48 } 49 50 public void setMarshaler(JmsMarshaler marshaler) { 51 this.marshaler = marshaler; 52 } 53 54 public void onMessage(Message jmsMessage) { 55 if (log.isTraceEnabled()) { 56 log.trace("Received: " + jmsMessage); 57 } 58 59 try { 60 InOnly messageExchange = getDeliveryChannel().createExchangeFactory().createInOnlyExchange(); 61 NormalizedMessage inMessage = messageExchange.createMessage(); 62 63 try { 64 marshaler.toNMS(inMessage, jmsMessage); 65 66 messageExchange.setInMessage(inMessage); 67 getDeliveryChannel().send(messageExchange); 68 } 69 catch (JMSException e) { 70 messageExchange.setError(e); 71 messageExchange.setStatus(ExchangeStatus.ERROR); 72 } 73 } 74 catch (JBIException e) { 75 throw new RuntimeJBIException(e); 76 } 77 } 78 79 public void onMessageExchange(MessageExchange exchange) throws MessagingException { 80 } 83 } 84 | Popular Tags |