01: package org.jbpm.msg.jms;
02:
03: import java.util.Enumeration;
04:
05: import javax.jms.Destination;
06: import javax.jms.JMSException;
07: import javax.jms.Message;
08: import javax.jms.ObjectMessage;
09: import javax.jms.Queue;
10: import javax.jms.Topic;
11:
12: import org.apache.commons.logging.Log;
13: import org.apache.commons.logging.LogFactory;
14:
15: public class JmsMessageUtils {
16:
17: public static String dump(Message message) {
18:
19: StringBuffer sb = new StringBuffer();
20:
21: sb.append("JMS Message Dump\n").append(
22: "Message type is " + message.getClass().getName()
23: + "\n");
24:
25: try {
26: if (message instanceof ObjectMessage)
27: sb.append("Message object type is "
28: + ((ObjectMessage) message).getObject()
29: .getClass().getName() + "\n");
30: sb.append("Reply to "
31: + getDestinationName(message.getJMSReplyTo())
32: + "\n");
33: Enumeration e = message.getPropertyNames();
34: while (e.hasMoreElements()) {
35: String propertyName = (String) e.nextElement();
36: Object property = message
37: .getObjectProperty(propertyName);
38: sb.append("Property " + propertyName + " value "
39: + property.toString() + "\n");
40: }
41: } catch (JMSException j) {
42: log.error("JMS exception while dumping message", j);
43: }
44:
45: return sb.toString();
46: }
47:
48: public static String getDestinationName(Destination d) {
49: try {
50: if (d instanceof Queue)
51: return ((Queue) d).getQueueName();
52: else if (d instanceof Topic)
53: return ((Topic) d).getTopicName();
54: } catch (JMSException j) {
55: }
56: ;
57:
58: return null;
59: }
60:
61: private static final Log log = LogFactory
62: .getLog(JmsMessageUtils.class);
63: }
|