// Extract the arguments
args = methodUtil.transferToJavaParameters(jsonReq, this.serviceInterface);
} catch (Exception e) {
JSONRPCResult errorResult = new JSONRPCResult(
JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
return errorResult.toString().getBytes("UTF-8");
}
// invoke the request
Object result = null;
Object[] parameters = null;
if (null != args && hasSessionParam(jsonOperation)) {
parameters = new Object[args.length + 1];
parameters[0] = request.getSession(false);
for (int i = 0; i < args.length; i++) {
parameters[i + 1] = args[i];
}
} else {
parameters = args;
}
try {
JSONObject jsonResponse = new JSONObject();
// result = wire.invoke(jsonOperation, args);
result = jsonOperation.invoke(this.serviceInstance, parameters);
JavaBean2JSON transform = new JavaBean2JSON();
try {
// FIXME: this only checks for String and not primitive types
if (!(result instanceof java.lang.String)) {
jsonResponse.put("result", transform.toJSON(result));
} else {
jsonResponse.put("result", result);
}
jsonResponse.putOpt("id", id);
// get response to send to client
return jsonResponse.toString().getBytes("UTF-8");
} catch (Exception e) {
JSONRPCResult errorResult = new JSONRPCResult(
JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
return errorResult.toString().getBytes("UTF-8");
}
} catch (InvocationTargetException e) {
JSONRPCResult errorResult = new JSONRPCResult(
JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
return errorResult.toString().getBytes("UTF-8");
} catch (RuntimeException e) {
JSONRPCResult errorResult = new JSONRPCResult(
JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
return errorResult.toString().getBytes("UTF-8");
} catch (IllegalAccessException e) {
JSONRPCResult errorResult = new JSONRPCResult(
JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
return errorResult.toString().getBytes("UTF-8");
} catch (Exception e) {
JSONRPCResult errorResult = new JSONRPCResult(
JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause());
return errorResult.toString().getBytes("UTF-8");
}
}