}
public HashMap constructMessageInfo(SysMessageID sysMsgID, boolean getBody,
HashMap destNameType) {
HashMap h = new HashMap();
PacketReference pr = getPacketReference(sysMsgID);
Packet pkt = pr.getPacket();
HashMap msgHeaders = pr.getHeaders();
Destination d = pr.getDestination();
String corrID = pkt.getCorrelationID(), errMsg;
int typeMask = DestType.DEST_TYPE_QUEUE;
byte b[] = null;
h.put("CorrelationID", corrID);
if (corrID != null) {
try {
b = corrID.getBytes("UTF8");
} catch(Exception e) {
}
}
h.put("CorrelationIDAsBytes", b);
h.put("DeliveryMode", (pkt.getPersistent()) ?
new Integer(javax.jms.DeliveryMode.PERSISTENT) :
new Integer(javax.jms.DeliveryMode.NON_PERSISTENT));
h.put("DestinationName", pkt.getDestination());
if (pkt.getIsQueue()) {
typeMask = DestType.DEST_TYPE_QUEUE;
} else {
typeMask = DestType.DEST_TYPE_TOPIC;
}
h.put("DestinationType", new Integer(typeMask));
h.put("Expiration", new Long(pkt.getExpiration()));
h.put("MessageID", msgHeaders.get("JMSMessageID"));
h.put("Priority", new Integer(pkt.getPriority()));
h.put("Redelivered", new Boolean(pkt.getRedelivered()));
/*
* The ReplyTo information in the packet contains
* the destination name and class name (i.e. dest class
* name), which the broker cannot really use.
* We need to query/check if:
* - the destination exists
* - what it's type is
*/
String replyToDestName = pkt.getReplyTo();
if (replyToDestName != null) {
boolean destFound = false, isQueue = true;
if (destNameType != null) {
Boolean isQ = (Boolean)destNameType.get(replyToDestName);
if (isQ != null) {
isQueue = isQ.booleanValue();
destFound = true;
}
}
if (!destFound) {
try {
Destination topic, queue;
queue = Destination.findDestination(replyToDestName, true);
topic = Destination.findDestination(replyToDestName, false);
if ((queue != null) && (topic != null)) {
errMsg = "Cannot determine type of ReplyTo destination."
+ " There is a topic and queue with the name: "
+ replyToDestName;
logger.log(Logger.WARNING, errMsg);
} else if (queue != null) {
destFound = true;
isQueue = true;
} else if (topic != null) {
destFound = true;
isQueue = false;
}
if (destFound) {
/*
* Cache dest name/type so that we can look it up there
* next time.
*/
destNameType.put(replyToDestName, new Boolean(isQueue));
} else {
/*
* It is possible that this destination no longer exists.
* e.g. Temporary destination, whose connection has gone away.
* Not sure how to proceed at this point.
*/
}
} catch (Exception e) {
errMsg = "Caught exception while determining ReplyTo destination type";
logger.log(Logger.WARNING, errMsg, e);
}
}
h.put("ReplyToDestinationName", replyToDestName);
if (destFound) {
if (isQueue) {
typeMask = DestType.DEST_TYPE_QUEUE;
} else {
typeMask = DestType.DEST_TYPE_TOPIC;
}
h.put("ReplyToDestinationType", new Integer(typeMask));
}
}
h.put("Timestamp", new Long(pkt.getTimestamp()));
h.put("Type", pkt.getMessageType());
Hashtable msgProps;
try {
msgProps = pr.getProperties();
} catch (Exception e) {
msgProps = null;
}
h.put("MessageProperties", msgProps);
int packetType = pr.getPacket().getPacketType();
h.put("MessageBodyType", new Integer(packetType));
if (getBody) {
ByteBuffer bb = pr.getPacket().getMessageBodyByteBuffer();
byte[] msgBody = null;
if (bb.hasArray()) {
msgBody = bb.array();
}