1 17 package org.apache.servicemix.components.wsif; 18 19 20 import org.springframework.beans.factory.InitializingBean; 21 import org.springframework.jms.core.JmsTemplate; 22 import org.springframework.jms.core.MessageCreator; 23 24 import javax.jms.JMSException ; 25 import javax.jms.Message ; 26 import javax.jms.MessageListener ; 27 import javax.jms.Session ; 28 import javax.jms.TextMessage ; 29 30 40 public class SampleServiceMessageListener implements MessageListener , InitializingBean { 41 private JmsTemplate template; 42 43 public JmsTemplate getTemplate() { 44 return template; 45 } 46 47 public void setTemplate(JmsTemplate template) { 48 this.template = template; 49 } 50 51 public void afterPropertiesSet() throws Exception { 52 if (template == null) { 53 throw new IllegalArgumentException ("The template property is not set"); 54 } 55 } 56 57 public void onMessage(Message msg) { 58 try { 59 TextMessage message = (TextMessage ) msg; 60 String text = message.getText(); 62 System.out.println("Text: " + text); 63 int zipCode = new Integer (text).intValue(); 64 if (zipCode < 50000) { 66 sendMessage(message, "true"); 67 } 68 else { 69 sendMessage(message, "false"); 70 } 71 } 72 catch (Exception e) { 73 System.out.println(e); 75 e.printStackTrace(); 76 } 77 } 78 79 public void sendMessage(final TextMessage requestMsg, final String serviceAvailable) throws JMSException { 80 template.send(requestMsg.getJMSReplyTo(), new MessageCreator() { 81 public Message createMessage(Session session) throws JMSException { 82 TextMessage message = session.createTextMessage(); 83 message.setJMSCorrelationID(requestMsg.getJMSMessageID()); 85 message.setText(serviceAvailable); 87 return message; 88 } 89 }); 90 } 91 } 92 93 | Popular Tags |