Pattern statusChangePattern = Pattern.compile("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>([^<]*)</resource></bind>");
public void onMessage(ChannelHandlerContext ctx, MessageEvent e, Status status, String message, Document document) {
String id = document.getDocumentElement().getAttribute("id");
String from = document.getDocumentElement().getAttribute("from");
Jid jid = new Jid(from);
String to = document.getDocumentElement().getAttribute("to");
final Matcher matcher = statusChangePattern.matcher(message);
if (matcher.find()) {
String resource = matcher.group(1);
logger.info("change status: " + resource);
String reply = "<iq id='" + id + "' type='result'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>" +
"<jid>" + jid.getUser() + "@" + jid.getServer() + "/" + resource + "</jid></bind></iq>";
write(e.getChannel(), reply);
jid.setResource(resource);
status.setJid(jid);
status.onEvent(new Event(message, Event.Type.BIND_RESOURCE));
} else if (message.contains("<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>")) {
String reply = "<iq id='" + id + "' type='result' from='" + to + "'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>";