int id = TypeUtil.toInt(json.get("id"));
String method = (String) json.get("method");
JSONArray params = (JSONArray) json.get("args");
RMIInterface interf = int2itf.get(id);
if (interf == null) {
sendError(RMIFault.ITF_ID_NOT_FOUND);
return;
}
try {
sendResult(interf.invoke(method, params.toArray()));
} catch (InvocationTargetException e) {
Throwable target = e.getTargetException();
if(target instanceof Exception) {
sendException((Exception) target);
} else {
e.printStackTrace();
sendError(RMIFault.INTERNAL_ERROR);
}
} catch (Exception e) {
e.printStackTrace();
sendError(RMIFault.INTERNAL_ERROR);
}
} else if (json.containsKey("request")) {
String itname = (String) json.get("request");
RMIInterface interf = server.interfaces.get(itname);
if (interf == null) {
sendError(RMIFault.ITF_NOT_IMPLEMENTED);
System.out.println("Got interfaces: ");
for (String s : server.interfaces.keySet()) {
System.out.print(s + ",");