JMQXid xid = null;
try {
props = msg.getProperties();
Long ttid = (Long)props.get("JMQTransactionID");
if (ttid == null) {
throw new BrokerException("Bad/Missing transaction id");
}
ByteBuffer body = msg.getMessageBodyByteBuffer();
if (body != null) {
JMQByteBufferInputStream bbis = new JMQByteBufferInputStream(body);
try {
xid = JMQXid.read(new DataInputStream(bbis));
} catch (IOException e) {
logger.log(Logger.ERROR,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"Could not decode xid from packet " +
PacketType.getString(msg.getPacketType())+":"+e);
BrokerException bex = new BrokerException(e.getMessage(), Status.BAD_REQUEST);
bex.initCause(e);
throw bex;
}
}
long tid = ttid.longValue();
if (tid != 0) {
tuid = new TransactionUID(tid);
} else if (xid != null) {
tuid = translist.xidToUID(xid);
if (tuid == null) {
String emsg = Globals.getBrokerResources().getKString(
BrokerResources.W_UNKNOWN_XID, ""+xid,
PacketType.getString(msg.getPacketType()));
logger.log(Logger.WARNING, emsg);
throw new BrokerException("Unknown XID "+xid, Status.NOT_FOUND);
}
} else {
logger.log(Logger.ERROR,
BrokerResources.E_INTERNAL_BROKER_ERROR,
"No transaction ID in " +
PacketType.getString(msg.getPacketType()));
throw new BrokerException("No transaction ID" , Status.BAD_REQUEST);
}
TransactionState ts = translist.retrieveState(tuid, true);
if (ts == null) {
status = Status.GONE;
} else {
int realstate = ts.getState();
if (realstate != TransactionState.PREPARED) {
// LKS - XXX
// for now return GONE because it seems to work
// better for the client - revisit
throw new BrokerException("Transaction " + tuid +
" is not PREPARED " + ts, Status.GONE);
}
Hashtable m = translist.getTransactionMap(tuid, true);
// write it to the body