Hi Misko,
Am intercepting the packets and adding it to custom table,
public class MessagePacketInterceptor implements PacketInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(MessagePacketInterceptor.class);
private static final String INSERT_msgs = “INSERT INTO CUSTOMTABLE (packetid, messageid, username, creationDate, stanza) VALUES (?,?,?,?,?)”;
private static final String DELETE_MSG = “DELETE FROM CUSTOMTABLE WHERE packetid = ?”;
/* Method intercepts the packet. If it is message store it in server database.
- If the package is ACK from client delete the message from server database.
*/
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
if (packet instanceof Message && incoming && !processed) {
Message message = (Message) packet;
try {
// If the packet is for ack ignore it
isACKPacket(message); // THIS THROWS MsgSaverAckException
// Store message in to OpenFire database
storeMessage(message);
} catch (MsgSaverAckException e) {
// Delete the message from table based on the acknowledgment
deleteMsg(message);
// @PacketRejectedException is thrown to avoid sending back the ACK package.
throw new PacketRejectedException();
} catch (MsgSaverException e) {
LOG.error("" , e.getMessage());
}
}
}