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
try {
String agentUrl = "xmpp:" + to.getId();
String agentId = xmppService != null ? xmppService
.getAgentId(new URI(agentUrl)) : null;
logger.info("request agentUrl =" + agentUrl + ", agentId="
+ agentId + " request=" + body + ", sender="