sb.append("\"id\":" + request.getParameter("id"));
sb.append("}");
root = JacksonHelper.MAPPER.readTree(sb.toString());
} catch (Throwable e) {
JsonRpc10Response error =
new JsonRpc10Response(JsonNodeFactory.instance.textNode(request.getParameter("id")), e);
error.write(response.getWriter());
return;
}
} else {
root = JacksonHelper.MAPPER.readTree(request.getReader());
}
try {
if (root.isArray()) {
ArrayNode input = (ArrayNode)root;
JsonRpc20BatchRequest batchReq = new JsonRpc20BatchRequest(input);
for (int i = 0; i < batchReq.getRequests().size(); i++) {
JsonRpcResponse result = batchReq.getBatchResponse().getResponses().get(i);
if (result == null) {
result = invoke(batchReq.getRequests().get(i));
batchReq.getBatchResponse().getResponses().set(i, result);
}
}
ArrayNode responses = batchReq.getBatchResponse().toJSONArray();
JacksonHelper.MAPPER.writeValue(response.getWriter(), responses);
} else {
if (root.has("jsonrpc")) {
JsonRpc20Request jsonReq = new JsonRpc20Request((ObjectNode)root);
JsonRpcResponse jsonResult = invoke(jsonReq);
if (jsonResult != null) {
jsonResult.write(response.getWriter());
}
} else {
JsonRpc10Request jsonReq = new JsonRpc10Request((ObjectNode)root);
JsonRpc10Response jsonResult = invoke(jsonReq);
if (jsonResult != null) {
jsonResult.write(response.getWriter());
}
}
}
} catch (Throwable e) {
throw new ServletException(e);