xmppSession.addIQListener(new IQListener() {
@Override
public void handle(final IQEvent e) {
final IQ iq = e.getIQ();
if (e.isIncoming() && isEnabled() && !e.isConsumed() && iq.getType() == IQ.Type.SET) {
Rpc rpc = iq.getExtension(Rpc.class);
// If there's an incoming RPC
if (rpc != null) {
synchronized (RpcManager.this) {
if (rpcHandler != null) {
final Rpc.MethodCall methodCall = rpc.getMethodCall();
final List<Value> parameters = new ArrayList<>();
for (Value parameter : methodCall.getParameters()) {
parameters.add(parameter);
}
executorService.execute(new Runnable() {
@Override
public void run() {
try {
Value value = rpcHandler.process(iq.getFrom(), methodCall.getMethodName(), parameters);
IQ result = iq.createResult();
result.setExtension(new Rpc(value));
xmppSession.send(result);
} catch (RpcException e1) {
IQ result = iq.createResult();
result.setExtension(new Rpc(new Rpc.MethodResponse.Fault(e1.getFaultCode(), e1.getFaultString())));
xmppSession.send(result);
} catch (Throwable e1) {
logger.log(Level.WARNING, e1.getMessage(), e1);
xmppSession.send(iq.createError(new StanzaError(new InternalServerError())));
}