Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 44 additions & 38 deletions dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public GXRouting(string baseURL)
}

static public List<ControllerInfo> GetRouteController(Dictionary<string, string> apiPaths,
Dictionary<string, List<string>> sValid,
Dictionary<string, Dictionary<string, SingleMap>> sMap,
Dictionary<string, Dictionary<Tuple<string, string>, string>> sMapData,
string basePath, string verb, string path)
Dictionary<string, List<string>> sValid,
Dictionary<string, Dictionary<string, SingleMap>> sMap,
Dictionary<string, Dictionary<Tuple<string, string>, string>> sMapData,
string basePath, string verb, string path)
{
List<ControllerInfo> result = new List<ControllerInfo>();
string parms = string.Empty;
Expand All @@ -78,10 +78,10 @@ static public List<ControllerInfo> GetRouteController(Dictionary<string, string>
int questionMarkIdx = path.IndexOf(QUESTIONMARK);
string controller;
if (apiPaths.ContainsKey(basePath)
&& sValid.ContainsKey(basePath)
&& sMap.ContainsKey(basePath)
&& sMapData.ContainsKey(basePath)
)
&& sValid.ContainsKey(basePath)
&& sMap.ContainsKey(basePath)
&& sMapData.ContainsKey(basePath)
)
{
if (sValid[basePath].Contains(path.ToLower()))
{
Expand Down Expand Up @@ -174,12 +174,12 @@ internal async Task RouteHttpService(HttpContext context)
HandlerFactory handlerFactory = new HandlerFactory();
await handlerFactory.Invoke(context);
}
catch (Exception ex)
catch
{
await Task.FromException(ex);
throw;
}
}
public Task ProcessRestRequest(HttpContext context)
public async Task ProcessRestRequest(HttpContext context)
{
try
{
Expand All @@ -188,7 +188,6 @@ public Task ProcessRestRequest(HttpContext context)
IHttpContextAccessor contextAccessor = context.RequestServices.GetService<IHttpContextAccessor>();
context = new GxHttpContextAccesor(contextAccessor);
}
Task result = Task.CompletedTask;
string path = context.Request.Path.ToString();
string actualPath = string.Empty;
bool isServiceInPath = ServiceInPath(path, out actualPath);
Expand All @@ -214,43 +213,46 @@ public Task ProcessRestRequest(HttpContext context)
}
string controllerPath = path.ToLower().Split(actualPath).Last<string>();
controllerWithParms = controllerPath.Split(QUESTIONMARK).First<string>();

}
}
else
{
if (path.Contains(oauthRoute) && (AzureDeploy.GAM == "true"))
return (RouteHttpService(context));
if (path.Contains(oauthRoute) && (AzureDeploy.GAM == "true"))
{
await (RouteHttpService(context));
return;
}
controllerWithParms = GetGxRouteValue(path);
GXLogging.Debug(log, $"Running Azure functions. ControllerWithParms :{controllerWithParms} path:{path}");
}

List<ControllerInfo> controllers = GetRouteController(servicesPathUrl, servicesValidPath, servicesMap, servicesMapData, actualPath, context.Request.Method, controllerWithParms);
GxRestWrapper controller = null;
ControllerInfo controllerInfo = controllers.FirstOrDefault(c => (controller = GetController(context, c)) != null);


if (controller != null)
{
if (HttpMethods.IsGet(context.Request.Method) && (controllerInfo.Verb == null || HttpMethods.IsGet(controllerInfo.Verb)))
{
result = controller.Get(controllerInfo.Parameters);
await controller.Get(controllerInfo.Parameters);
}
else if (HttpMethods.IsPost(context.Request.Method) && (controllerInfo.Verb == null || HttpMethods.IsPost(controllerInfo.Verb)))
{
result = controller.Post();
await controller.Post();
}
else if (HttpMethods.IsDelete(context.Request.Method) && (controllerInfo.Verb == null || HttpMethods.IsDelete(controllerInfo.Verb)))
{
result = controller.Delete(controllerInfo.Parameters);
await controller.Delete(controllerInfo.Parameters);
}
else if (HttpMethods.IsPut(context.Request.Method) && (controllerInfo.Verb == null || HttpMethods.IsPut(controllerInfo.Verb)))
{
result = controller.Put(controllerInfo.Parameters);
await controller.Put(controllerInfo.Parameters);
}
else if (HttpMethods.IsPatch(context.Request.Method) && (controllerInfo.Verb == null || HttpMethods.IsPatch(controllerInfo.Verb)))
{
result = controller.Patch(controllerInfo.Parameters);
await controller.Patch(controllerInfo.Parameters);
}
else if (HttpMethods.IsOptions(context.Request.Method))
{
Expand Down Expand Up @@ -284,18 +286,20 @@ public Task ProcessRestRequest(HttpContext context)
{
GXLogging.Error(log, $"ProcessRestRequest controller not found path:{path} controllerWithParms:{controllerWithParms}");
context.Response.Headers.Clear();
result = Task.FromException(new PageNotFoundException(path));
throw new PageNotFoundException(path);
}
}
context.CommitSession();

return result;

}
catch (Exception ex)
{
GXLogging.Error(log, "ProcessRestRequest", ex);
HttpHelper.SetUnexpectedError(context, HttpStatusCode.InternalServerError, ex);
return Task.FromException(ex);
throw;
}
finally
{
await context.CommitSessionAsync();
}
}

Expand Down Expand Up @@ -374,20 +378,21 @@ public bool ServiceInPath(String path, out String actualPath)
return true;
}
}
else {
else
{
return true;
}
}
}

private String FindPath(string innerPath, Dictionary<string,string > servicesPathUrl, bool startTxt)
private String FindPath(string innerPath, Dictionary<string, string> servicesPathUrl, bool startTxt)
{
string actualPath = String.Empty;
foreach (string subPath in from String subPath in servicesPathUrl.Keys
select subPath)
foreach (string subPath in from String subPath in servicesPathUrl.Keys
select subPath)
{
bool match = false;
innerPath = innerPath.ToLower();
match = (startTxt)? innerPath.StartsWith($"/{subPath.ToLower()}"): innerPath.Contains($"/{subPath.ToLower()}");
match = (startTxt) ? innerPath.StartsWith($"/{subPath.ToLower()}") : innerPath.Contains($"/{subPath.ToLower()}");
if (match)
{
actualPath = subPath.ToLower();
Expand Down Expand Up @@ -431,7 +436,7 @@ public GxRestWrapper GetController(HttpContext context, ControllerInfo controlle
bool privateDirExists = Directory.Exists(privateDir);

GXLogging.Debug(log, $"PrivateDir:{privateDir} asssemblycontroller:{asssemblycontroller}");
string svcFile=null;
string svcFile = null;
if (privateDirExists && File.Exists(Path.Combine(privateDir, $"{asssemblycontroller.ToLower()}.grp.json")))
{
controller = tmpController;
Expand Down Expand Up @@ -498,7 +503,7 @@ string SvcFile(string controller)
GXLogging.Warn(log, "Service file not found:" + controllerFullName);
return null;
}

}
public void ServicesGroupSetting()
{
Expand All @@ -524,7 +529,7 @@ public void ServicesGroupSetting()
string mapPath = (m.BasePath.EndsWith("/")) ? m.BasePath : m.BasePath + "/";
string mapPathLower = mapPath.ToLower();
string mNameLower = m.Name.ToLower();
servicesPathUrl[mapPathLower]= mNameLower;
servicesPathUrl[mapPathLower] = mNameLower;
if (!RestAPIHelpers.ServiceAsController())
{
GXLogging.Debug(log, $"addServicesPathUrl key:{mapPathLower} value:{mNameLower}");
Expand Down Expand Up @@ -575,7 +580,8 @@ public void ServicesGroupSetting()
}
}
}
}catch (Exception ex)
}
catch (Exception ex)
{
GXLogging.Error(log, $"Error Loading Services Group Settings", ex);
throw;
Expand Down Expand Up @@ -676,7 +682,7 @@ public class Binding

[DataContract()]
public class MapGroup
{
{
String _objectType;
String _name;
String _basePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public async Task Invoke(HttpContext context)
}
else
{
await Task.FromException(new PageNotFoundException(url));
throw new PageNotFoundException(url);
}
}
catch (Exception ex)
{
GXLogging.Error(log, $"Handler Factory failed creating {url}", ex);
await Task.FromException(ex);
throw;
}
}
private static string ObjectUrl(string requestPath, string basePath)
Expand Down
31 changes: 6 additions & 25 deletions dotnet/src/dotnetcore/GxClasses/Domain/HttpSessionState.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using Microsoft.AspNetCore.Http;

namespace GeneXus.Http
Expand Down Expand Up @@ -32,34 +34,13 @@ public static CookieCollection GetCookies(this CookieContainer container)
return allCookies;
}
}
internal class LockTracker : IDisposable
public static class LockTracker
{
private static Dictionary<string, LockTracker> _locks = new Dictionary<string, LockTracker>();
private int _activeUses = 0;
private readonly string _id;
private static readonly ConcurrentDictionary<string, SemaphoreSlim> _locks = new();

private LockTracker(string id) => _id = id;

internal static LockTracker Get(string id)
{
lock (_locks)
{
if (!_locks.ContainsKey(id))
_locks.Add(id, new LockTracker(id));
var res = _locks[id];
res._activeUses += 1;
return res;
}
}

void IDisposable.Dispose()
public static SemaphoreSlim Get(string sessionId)
{
lock (_locks)
{
_activeUses--;
if (_activeUses == 0)
_locks.Remove(_id);
}
return _locks.GetOrAdd(sessionId, _ => new SemaphoreSlim(1, 1));
}
}
internal class HttpSyncSessionState : HttpSessionState
Expand Down
1 change: 0 additions & 1 deletion dotnet/src/dotnetcore/GxNetCoreStartup/SessionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public async Task Invoke(HttpContext context)
if (!string.IsNullOrEmpty(subdomain))
context.Items[AppContext.TENANT_ID] = subdomain;
}

await _next(context);
}
}
Expand Down
Loading
Loading