private JsonRpcResponse buildExecutionResultResponse(JsonRpcRequest rpc, ExecutionResult executionResult) {
JsonRpcResponse response = null;
if (executionResult.getResultType() == ExecutionResult.ResultType.Success) {
response = JsonRpcSuccessResponse.buildSuccessResponse(rpc, executionResult.getResult());
} else if (executionResult.getResultType() == ExecutionResult.ResultType.Fault) {
Fault fault = executionResult.getFault().getFault();
HashMap<String,Object> detailMap = new HashMap<String,Object>();
FaultDetail detail = fault.getDetail();
if (FaultController.getInstance().isDetailedFaults()) {
detailMap.put("trace", detail.getStackTrace());
detailMap.put("message", detail.getDetailMessage());
}
List<String[]> faultMessages = detail.getFaultMessages();
if (faultMessages != null) {
detailMap.put("exceptionname", detail.getFaultName());
HashMap<String,Object> paramMap = new HashMap<String,Object>();
detailMap.put(detail.getFaultName(), paramMap);
for (String[] msg: faultMessages) {
paramMap.put(msg[0], msg[1]);
}
}
int jsonErrorCode = mapServerFaultCodeToJsonErrorCode(executionResult.getFault().getServerFaultCode());
JsonRpcError error = new JsonRpcError(jsonErrorCode, fault.getErrorCode(), !detailMap.isEmpty() ? detailMap : null);
response = JsonRpcErrorResponse.buildErrorResponse(rpc, error);
}
return response;
}