JSONRequest request = new JSONRequest(json);
JSONResponse response = agentFactory.receive(agentId,
request, params);
// reply to message
Message msg = new MessageBuilder().withRecipientJids(from)
.withFromJid(to).withBody(response.toString())
.build();
xmpp.sendMessage(msg);
} else {
throw new Exception(
"Request does not contain a valid JSON-RPC request or response");
}
} catch (Exception err) {
// generate JSON error response
JSONRPCException jsonError = new JSONRPCException(
JSONRPCException.CODE.INTERNAL_ERROR, err.getMessage());
JSONResponse response = new JSONResponse(jsonError);
// send exception as response
Message msg = new MessageBuilder().withRecipientJids(from)
.withFromJid(to).withBody(response.toString()).build();
xmpp.sendMessage(msg);
}
}
}