1 17 package org.apache.servicemix.components.jms; 18 19 import javax.jbi.messaging.MessageExchange; 20 import javax.jbi.messaging.NormalizedMessage; 21 import javax.jms.JMSException ; 22 import javax.jms.Message ; 23 import javax.jms.Session ; 24 import javax.xml.transform.TransformerException ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.servicemix.components.util.OutBinding; 29 import org.springframework.jms.core.JmsTemplate; 30 import org.springframework.jms.core.MessageCreator; 31 32 38 public class JmsSenderComponent extends OutBinding { 39 40 private static final Log log = LogFactory.getLog(JmsSenderComponent.class); 41 42 private JmsTemplate template; 43 private JmsMarshaler marshaler = new JmsMarshaler(); 44 45 46 public JmsTemplate getTemplate() { 49 return template; 50 } 51 52 public void setTemplate(JmsTemplate template) { 53 this.template = template; 54 } 55 56 public JmsMarshaler getMarshaler() { 57 return marshaler; 58 } 59 60 public void setMarshaler(JmsMarshaler marshaler) { 61 this.marshaler = marshaler; 62 } 63 64 67 public boolean isNeedJavaIdentifiers() { 68 return this.marshaler.isNeedJavaIdentifiers(); 69 } 70 71 74 public void setNeedJavaIdentifiers(boolean needJavaIdentifiers) { 75 this.marshaler.setNeedJavaIdentifiers(needJavaIdentifiers); 76 } 77 78 protected void process(MessageExchange exchange, final NormalizedMessage inMessage) throws Exception { 81 template.send(new MessageCreator() { 82 public Message createMessage(Session session) throws JMSException { 83 try { 84 Message message = marshaler.createMessage(inMessage, session); 85 if (log.isTraceEnabled()) { 86 log.trace("Sending message to: " + template.getDefaultDestinationName() + " message: " + message); 87 } 88 return message; 89 } 90 catch (TransformerException e) { 91 JMSException jmsEx = new JMSException ("Failed to create JMS Message: " + e); 92 jmsEx.setLinkedException(e); 93 throw jmsEx; 94 } 95 } 96 }); 97 done(exchange); 98 } 99 } 100 | Popular Tags |