protected void dispatchBatch(JsonArray batch, HttpResponse response, ISecurityToken token) { // Use linked hash map to preserve order List <IAsyncResult> responses = new List <IAsyncResult>(batch.Length); // Gather all Futures. We do this up front so that // the first call to get() comes after all futures are created, // which allows for implementations that batch multiple Futures // into single requests. for (int i = 0; i < batch.Length; i++) { JsonObject batchObj = batch.GetObject(i); RpcRequestItem requestItem = new RpcRequestItem(batchObj, token, jsonConverter); responses.Add(HandleRequestItem(requestItem)); } // Resolve each Future into a response. // TODO: should use shared deadline across each request List <Object> result = new List <object>(); for (int i = 0; i < batch.Length; i++) { JsonObject batchObj = batch.GetObject(i); String key = null; if (batchObj.Contains("id")) { key = batchObj["id"] as String; } result.Add(getJsonResponse(key, getResponseItem(responses[i]), null)); } response.Output.Write(jsonConverter.ConvertToString(result)); }
private void dispatch(JsonObject request, HttpResponse servletResponse, ISecurityToken token) { String key = null; if (request.Contains("id")) { key = request["id"] as String; } RpcRequestItem requestItem = new RpcRequestItem(request, token, jsonConverter); // Resolve each Future into a response. // TODO: should use shared deadline across each request ResponseItem response = getResponseItem(HandleRequestItem(requestItem)); Object result = getJsonResponse(key, response, requestItem); servletResponse.Output.Write(jsonConverter.ConvertToString(result)); }
Object getJsonResponse(String key, ResponseItem responseItem, RpcRequestItem requestItem) { var result = new Dictionary <string, object>(); if (key != null) { result.Add("id", key); } if (responseItem.getErrorCode() < 200 || responseItem.getErrorCode() >= 400) { result.Add("error", getErrorJson(responseItem)); } else { Object response = responseItem.getResponse(); if (response != null && response is DataCollection) { result.Add("data", ((DataCollection)response).entry); } else if (response != null && (response is IRestfulCollection)) { var map = new Dictionary <string, object>(); var collection = (IRestfulCollection)response; map.Add("startIndex", collection.startIndex); map.Add("totalResults", collection.totalResults); if (requestItem != null && requestItem.getCount() != null) { map.Add("itemsPerPage", requestItem.getCount()); } map.Add("list", collection.getEntry()); result.Add("data", map); } else { result.Add("data", response); } } return(result); }
Object getJsonResponse(String key, ResponseItem responseItem, RpcRequestItem requestItem) { var result = new Dictionary<string, object>(); if (key != null) { result.Add("id", key); } if (responseItem.getErrorCode() < 200 || responseItem.getErrorCode() >= 400) { result.Add("error", getErrorJson(responseItem)); } else { Object response = responseItem.getResponse(); if (response != null && response is DataCollection) { result.Add("data", ((DataCollection)response).entry); } else if (response != null && (response is IRestfulCollection)) { var map = new Dictionary<string, object>(); var collection = (IRestfulCollection)response; map.Add("startIndex", collection.startIndex); map.Add("totalResults", collection.totalResults); if (requestItem != null && requestItem.getCount() != null) { map.Add("itemsPerPage", requestItem.getCount()); } map.Add("list", collection.getEntry()); result.Add("data", map); } else { result.Add("data", response); } } return result; }
private void dispatch(JsonObject request, HttpResponse servletResponse, ISecurityToken token) { String key = null; if (request.Contains("id")) { key = request["id"] as String; } RpcRequestItem requestItem = new RpcRequestItem(request, token, jsonConverter); // Resolve each Future into a response. // TODO: should use shared deadline across each request ResponseItem response = getResponseItem(HandleRequestItem(requestItem)); Object result = getJsonResponse(key, response, requestItem); servletResponse.Output.Write(jsonConverter.ConvertToString(result)); }
protected void dispatchBatch(JsonArray batch, HttpResponse response, ISecurityToken token) { // Use linked hash map to preserve order List<IAsyncResult> responses = new List<IAsyncResult>(batch.Length); // Gather all Futures. We do this up front so that // the first call to get() comes after all futures are created, // which allows for implementations that batch multiple Futures // into single requests. for (int i = 0; i < batch.Length; i++) { JsonObject batchObj = batch.GetObject(i); RpcRequestItem requestItem = new RpcRequestItem(batchObj, token, jsonConverter); responses.Add(HandleRequestItem(requestItem)); } // Resolve each Future into a response. // TODO: should use shared deadline across each request List<Object> result = new List<object>(); for (int i = 0; i < batch.Length; i++) { JsonObject batchObj = batch.GetObject(i); String key = null; if (batchObj.Contains("id")) { key = batchObj["id"] as String; } result.Add(getJsonResponse(key, getResponseItem(responses[i]), null)); } response.Output.Write(jsonConverter.ConvertToString(result)); }