}
private HashMap constructMessageInfo(SysMessageID sysMsgID, boolean getBody,
HashMap destNameType) throws BrokerException {
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;
String destType = DestinationType.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()) {
destType = DestinationType.QUEUE;
} else {
destType = DestinationType.TOPIC;
}
h.put("DestinationType", destType);
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;
throw new BrokerException(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";
throw new BrokerException(errMsg);
}
}
h.put("ReplyToDestinationName", replyToDestName);
if (destFound) {
if (isQueue) {
destType = DestinationType.QUEUE;
} else {
destType = DestinationType.TOPIC;
}
h.put("ReplyToDestinationType", destType);
}
}
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();
}