@SuppressWarnings("unchecked")
private JsonRpcResponse dispatchJsonRpcRequest(JsonRpcRequest rpcRequest, OrangeContext cxt) {
JsonRpcResponse jsonResponse = new JsonRpcResponse(rpcRequest.getId(), JsonNull.INSTANCE,
JsonNull.INSTANCE, HttpServletResponse.SC_OK);
try {
ServiceMethodHandler handler = handlers.getMethodHandler(rpcRequest.getMethod());
Message innerRequest = convertJsonToProtobuf(handler, rpcRequest);
JsonElement idElement = rpcRequest.getId();
if (idElement == null) {
jsonResponse.setId(new JsonPrimitive(-1));
}
Message innerResponse = invokeHandlerChain(rpcRequest.getMethod(), handler, innerRequest, cxt);
jsonResponse.setResult(ProtobufUtil.protobufToJson(innerResponse));
} catch (RpcCallException rpcEx) {
logger.debug("Error processing request", rpcEx);
jsonResponse.setError(rpcEx.toJson());
jsonResponse.setStatusCode(rpcEx.getCategory().getHttpStatus());
} catch (Exception ex) {
logger.warn("Error processing request", ex);
if (ex.getMessage() != null) {
jsonResponse.setError(new JsonPrimitive(ex.getMessage()));
}
jsonResponse.setStatusCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
return jsonResponse;
}