public void TestProcRestParameters() { string parameters = "{\"Geolocations\":[{\"Description\":\"LocationInfo(fused)\",\"Heading\":\" - 1\",\"Location\":\" - 34.8782486,-56.0789207\",\"Precision\":\"17.585\",\"Speed\":\" - 1\",\"Time\":\"2019 - 10 - 23 16:43:45\"},{\"Description\":\"LocationInfo(fused)\",\"Heading\":\" - 1\",\"Location\":\" - 34.8782486,-56.0789207\",\"Precision\":\"17.585\",\"Speed\":\" - 1\",\"Time\":\"2019 - 10 - 23 16:44:05\"},{\"Description\":\"LocationInfo(fused)\",\"Heading\":\" - 1\",\"Location\":\" - 34.8783232,-56.0788582\",\"Precision\":\"14.999\",\"Speed\":\" - 1\",\"Time\":\"2019 - 10 - 23 16:44:25\"},{\"Description\":\"LocationInfo(fused)\",\"Heading\":\" - 1\",\"Location\":\" - 34.8783232,-56.0788582\",\"Precision\":\"14.999\",\"Speed\":\" - 1\",\"Time\":\"2019 - 10 - 23 16:44:46\"}], \"SDT1\":{\"a\":1, \"b\":\"hola\"}, \"charcollection\":[\"uno\", \"dos\", \"tres\"]}"; GxRestWrapper service = new GxRestWrapper(null, null); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(parameters)); Dictionary <string, object> parms = service.ReadRequestParameters(stream); Assert.Equal(3, parms.Count); }
public override void webExecute() { #if NETCORE GxRestWrapper handler = null; #else Utils.GxRestService handler = null; #endif try { HttpRequest req = context.HttpContext.Request; string gxobj = GetNextPar().ToLower(); string jsonStr = (new StreamReader(req.GetInputStream())).ReadToEnd(); GxSimpleCollection <JArray> parmsColl = new GxSimpleCollection <JArray>(); if (!string.IsNullOrEmpty(jsonStr)) { parmsColl.FromJSonString(jsonStr); } string nspace; if (!Config.GetValueOf("AppMainNamespace", out nspace)) { nspace = "GeneXus.Programs"; } #if NETCORE var controllerInstance = ClassLoader.FindInstance(gxobj, nspace, gxobj, new Object[] { context }, Assembly.GetEntryAssembly()); GXProcedure proc = controllerInstance as GXProcedure; if (proc != null) { handler = new GxRestWrapper(proc, localHttpContext, context as GxContext); } else { var sdtInstance = ClassLoader.FindInstance(Config.CommonAssemblyName, nspace, $"Sdt{gxobj}", new Object[] { context }, Assembly.GetEntryAssembly()) as GxSilentTrnSdt; if (sdtInstance != null) { handler = new GXBCRestService(sdtInstance, localHttpContext, context as GxContext); } } #else handler = (Utils.GxRestService)ClassLoader.FindInstance(gxobj, nspace, gxobj + "_services", null, null); #endif handler.RunAsMain = false; ParameterInfo[] pars = handler.GetType().GetMethod(EXECUTE_METHOD).GetParameters(); int ParmsCount = pars.Length; object[] convertedparms = new object[ParmsCount]; if (parmsColl.Count > 0) { foreach (JArray parmValues in parmsColl) { int idx = 0; for (int i = 0; i < ParmsCount; i++) { if (!pars[i].IsOut) { convertedparms[i] = convertparm(pars, i, parmValues[idx]); } idx++; } handler.GetType().InvokeMember(EXECUTE_METHOD, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, handler, convertedparms); } } } catch (GxClassLoaderException cex) { SendResponseStatus(404, cex.Message); HttpHelper.SetResponseStatusAndJsonError(context.HttpContext, "404", cex.Message); } catch (Exception ex) { SendResponseStatus(500, ex.Message); HttpHelper.SetResponseStatusAndJsonError(context.HttpContext, "500", ex.Message); } finally { if (handler != null) { handler.RunAsMain = true; handler.Cleanup(); } } }