public async Task <HttpResponse> Process(string request, HttpClientInfo clientInfo) { Logger.Info($"REQ RECIEVED"); if (string.IsNullOrWhiteSpace(request)) { Logger.Error("BAD REQ - Empty Command"); return(HttpResponse.BadRequest()); } var parsedRequest = requestParser.Parse(request); Logger.Info("REQ PARSED", parsedRequest); if (!parsedRequest.Success) { Logger.Error("Could not parse request", parsedRequest); return(HttpResponse.BadRequest("Could not parse RPC Request")); } var command = commandLocator.Locate(parsedRequest.Request.Method); if (command == null) { Logger.Error("Could not locate method", parsedRequest); return(HttpResponse.NotFound("Could not locate requested method")); } Logger.Trace("command located", command); var response = await translator.ExecuteCommand(command, parsedRequest.Request, clientInfo); Logger.Info("REQ COMPLETE", response); return(converter.Convert(response)); }
public void ReturnsProperlyTrackedData() { var expected = new JsonRpcRequest { Id = "1", Method = "what", Params = new { parameter = "yes" } }; var body = JsonConvert.SerializeObject(expected); var result = classUnderTest.Parse(body); Assert.True(result.Success); Assert.Equal(expected.Id, result.Request.Id); Assert.Equal(expected.Method, result.Request.Method); var p = (dynamic)expected.Params; Assert.Equal("yes", p.parameter); }
public JsonRpcModule(IJsonSerializer jsonSerializer, IJsonRpcRequestParser requestParser, IRequestHandler requestHandler) { Post["/jsonrpc"] = _ => { this.RequiresAuthentication(); using (var ms = new MemoryStream()) { Request.Body.CopyTo(ms); var json = Encoding.UTF8.GetString(ms.ToArray()); var request = requestParser.Parse(json); var response = requestHandler.Handle(request); return(Response.AsText(jsonSerializer.SerializeObject(response), "application/json")); } }; }
public JsonRpcModule(IJsonSerializer jsonSerializer, IJsonRpcRequestParser requestParser, IRequestHandler requestHandler) { Post["/jsonrpc"] = _ => { this.RequiresAuthentication(); using (var ms = new MemoryStream()) { Request.Body.CopyTo(ms); var json = Encoding.UTF8.GetString(ms.ToArray()); var request = requestParser.Parse(json); var response = requestHandler.Handle(request); return Response.AsText(jsonSerializer.SerializeObject(response), "application/json"); } }; }