throws IOException {
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
// receive message
Message message = xmpp.parseMessage(req);
JID from = message.getFromJid();
JID[] recipients = message.getRecipientJids();
JID to = (recipients.length > 0) ? recipients[0] : null;
String body = message.getBody();
if (body != null && body.startsWith("{") || body.trim().startsWith("{")) {
// the body contains a JSON object
ObjectNode json = null;
try {
String agentUrl = "xmpp:" + to.getId();
String agentId = xmppService != null ? xmppService
.getAgentId(agentUrl) : null;
json = JOM.getInstance().readValue(body, ObjectNode.class);
if (isResponse(json)) {