Skip to content

Commit 49361d1

Browse files
committed
7.0.6 release
[BUG FIX] trace method and params not being recorded if cache trace disable [ENHANCEMENT] changed when trace gets its correlationID [ENHANCEMENT] removed threadAbortException as performance thread abort is handled in its own try catch. removed from middleware,static, jsonrpc and RESTful [BUG FIX] added try catch around dictionary tryadd function use [ENHANCEMENT] improved logging for jsonrpc and restful requests [BUG FIX] returnResponseAsync now raises OperationCanceledException rather than TaskCanceledException [ENHANCEMENT] wrap performance thread creation in existing try catch block [BUG FIX] change from sending e.message to "Bad Request" in restful and static exception response [ENHANCEMENT] changing attribute dictionarys to be ConcurrentDictionary
1 parent a0304e5 commit 49361d1

File tree

10 files changed

+103
-80
lines changed

10 files changed

+103
-80
lines changed
67 KB
Binary file not shown.

src/API.Library/API.Library.csproj

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
<PackageId>API.Library</PackageId>
1313
<Product>API Library</Product>
1414
<Copyright>Central Statistics Office, Ireland</Copyright>
15-
<Version>7.0.5</Version>
15+
<Version>7.0.6</Version>
1616
<Authors>Central Statistics Office, Ireland</Authors>
1717
<SignAssembly>False</SignAssembly>
1818
<RepositoryUrl>https://github.com/CSOIreland/Server-API-Library</RepositoryUrl>
1919
<PackageReleaseNotes>
2020
- [BUG FIX] trace method and params not being recorded if cache trace disable
21+
- [ENHANCEMENT] changed when trace gets its correlationID
22+
- [ENHANCEMENT] removed threadAbortException as performance thread abort is handled in its own try catch. removed from middleware,static, jsonrpc and RESTful
23+
- [BUG FIX] added try catch around dictionary tryadd function use
24+
- [ENHANCEMENT] improved logging for jsonrpc and restful requests
25+
- [BUG FIX] returnResponseAsync now raises OperationCanceledException rather than TaskCanceledException
26+
- [ENHANCEMENT] wrap performance thread creation in existing try catch block
27+
- [BUG FIX] change from sending e.message to "Bad Request" in restful and static exception response
2128
</PackageReleaseNotes>
2229
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
2330
<RestoreLockedMode>true</RestoreLockedMode>
@@ -26,14 +33,16 @@
2633
<ItemGroup>
2734
<Compile Remove="bin\**" />
2835
<EmbeddedResource Remove="bin\**" />
29-
<None Remove="bin\**" />
36+
<None Remove="
37+
-bin\**" />
3038
</ItemGroup>
3139

3240
<ItemGroup>
3341
<None Remove="Config\CommonConfig.cs~RF52c4cb0.TMP" />
3442
<None Remove="Entities\ADO.cs~RF5780ef96.TMP" />
3543
<None Remove="Entities\API.Common.cs~RF1e6b9c0d.TMP" />
3644
<None Remove="Entities\MemCacheD.cs~RFcba3198.TMP" />
45+
<None Remove="Entities\MethodReader.cs~RF8645ca5e.TMP" />
3746
<None Remove="log4net.config" />
3847
</ItemGroup>
3948

src/API.Library/Entities/API.Common.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ internal async Task returnResponseAsync(HttpContext context, string message, Can
421421
//check if already cancelled
422422
if (sourceToken.IsCancellationRequested)
423423
{
424-
throw new TaskCanceledException();
424+
throw new OperationCanceledException();
425425
}
426426

427427
if (context.Response.HasStarted)
@@ -430,7 +430,7 @@ internal async Task returnResponseAsync(HttpContext context, string message, Can
430430

431431
if (sourceToken.IsCancellationRequested)
432432
{
433-
throw new TaskCanceledException();
433+
throw new OperationCanceledException();
434434
}
435435
}
436436
else
@@ -450,7 +450,7 @@ internal async Task returnResponseAsync(HttpContext context, string message, Can
450450

451451
if (sourceToken.IsCancellationRequested)
452452
{
453-
throw new TaskCanceledException();
453+
throw new OperationCanceledException();
454454
}
455455
}
456456
}
@@ -545,10 +545,19 @@ internal static MethodInfo CheckAPICallsAllowed(string methodName, string method
545545
RuntimeMethodHandle handle = methodInfo.MethodHandle;
546546

547547
//add handle to dictionary for future lookup
548-
if (!AttributeDictionary.AllowedAPIDictionary.TryAdd(serializedAPIInfo, handle))
549-
{
550-
Log.Instance.Debug("Adding : " + serializedAPIInfo + " to dictionary 'CheckAPICallsAllowed' failed");
551-
}
548+
549+
try
550+
{
551+
if (!AttributeDictionary.AllowedAPIDictionary.TryAdd(serializedAPIInfo, handle))
552+
{
553+
Log.Instance.Debug("Adding : " + serializedAPIInfo + " to dictionary 'CheckAPICallsAllowed' failed");
554+
}
555+
}
556+
catch (Exception ex)
557+
{
558+
Log.Instance.Error(ex);
559+
}
560+
552561
return methodInfo;
553562
}
554563
}

src/API.Library/Entities/API.JSONRPC.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
5656
{
5757
Log.Instance.Info("Starting JSONRPC processing");
5858

59+
5960
// Set HTTP Requests
6061
httpGET = GetHttpGET(httpContext);
6162
httpPOST = await GetHttpPOST(httpContext);
@@ -115,10 +116,12 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
115116
}
116117
catch (Exception e)
117118
{
119+
Log.Instance.Error(e);
120+
Log.Instance.Error(Utility.JsonSerialize_IgnoreLoopingReference(trace));
118121
JSONRPC_Error error = new JSONRPC_Error { code = -32603 };
119122
await ParseError(httpContext, JSONRPC_Request.id, error, apiCancellationToken, trace);
120123
}
121-
124+
122125

123126
if (result == null)
124127
{
@@ -178,13 +181,9 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
178181
{
179182
//don't need to do anything here as operation has been cancelled
180183
}
181-
catch (ThreadAbortException e)
182-
{
183-
// Thread aborted, do nothing
184-
// The finally block will take care of everything safely
185-
}
186184
catch (Exception e)
187185
{
186+
Log.Instance.Fatal(Utility.JsonSerialize_IgnoreLoopingReference(trace));
188187
Log.Instance.Fatal(e);
189188
Log.Instance.Fatal(e.StackTrace);
190189
await returnResponseAsync(httpContext, "", apiCancellationToken, HttpStatusCode.InternalServerError);
@@ -405,6 +404,7 @@ private dynamic GetResult(HttpContext context, JSONRPC_Request JSONRPC_Request,
405404

406405
// Verify the method exists
407406
MethodInfo methodInfo = MapMethod(JSONRPC_Request);
407+
408408
//Invoke the API Method
409409
return methodInfo.Invoke(null, new object[] { apiRequest });
410410
}

src/API.Library/Entities/API.RESTful.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
9898
}
9999
catch (Exception e)
100100
{
101+
Log.Instance.Error(e);
102+
Log.Instance.Error(Utility.JsonSerialize_IgnoreLoopingReference(trace));
101103
await ParseError(httpContext, HttpStatusCode.InternalServerError, apiCancellationToken, "Internal Error");
102104
}
103105

@@ -125,14 +127,14 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
125127
httpContext.Response.StatusCode = (int)HttpStatusCode.OK;
126128
httpContext.Response.Headers["expires"] = DateTime.Now.AddDays(1).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
127129
httpContext.Response.Headers.Add("Last-Modified", DateTime.Now.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture));
128-
// httpContext.Response.Headers["Cache-Control"] = "86400"; //one day
130+
// httpContext.Response.Headers["Cache-Control"] = "86400"; //one day
129131
httpContext.Response.ContentLength = 0;
130132
await returnResponseAsync(httpContext, result.response, apiCancellationToken, result.statusCode);
131133
}
132134
else
133135
{
134136
httpContext.Response.StatusCode = (int)result.statusCode;
135-
await ParseError(httpContext, result.statusCode, apiCancellationToken,result.response);
137+
await ParseError(httpContext, result.statusCode, apiCancellationToken, result.response);
136138
}
137139
}
138140
else if (result.statusCode == HttpStatusCode.OK)
@@ -178,20 +180,16 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
178180
await ParseError(httpContext, result.statusCode, apiCancellationToken, result.response);
179181
}
180182
}
181-
182183
}
183184
catch (OperationCanceledException e)
184185
{
185186
//don't need to do anything here as operation has been cancelled
186187
}
187-
catch (ThreadAbortException e)
188-
{
189-
// Thread aborted, do nothing
190-
// The finally block will take care of everything safely
191-
}
192188
catch (Exception e)
193189
{
190+
Log.Instance.Fatal(Utility.JsonSerialize_IgnoreLoopingReference(trace));
194191
Log.Instance.Fatal(e);
192+
Log.Instance.Fatal(e.StackTrace);
195193
await returnResponseAsync(httpContext, "", apiCancellationToken, HttpStatusCode.InternalServerError);
196194
}
197195
}
@@ -287,7 +285,7 @@ Value of HttpContext.Current.Request.Url.PathAndQuery
287285
{
288286
Log.Instance.Fatal("Request params: " + Utility.JsonSerialize_IgnoreLoopingReference(RequestParams));
289287
Log.Instance.Fatal(e);
290-
await ParseError(context, HttpStatusCode.BadRequest, sourceToken, e.Message);
288+
await ParseError(context, HttpStatusCode.BadRequest, sourceToken, "Bad Request");
291289
}
292290
}
293291

src/API.Library/Entities/API.Static.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,11 @@ public async Task ProcessRequest(HttpContext httpContext, CancellationTokenSourc
107107
{
108108
//don't need to do anything here as operation has been cancelled
109109
}
110-
catch (ThreadAbortException e)
111-
{
112-
// Thread aborted, do nothing
113-
// The finally block will take care of everything safely
114-
}
115110
catch (Exception e)
116111
{
112+
Log.Instance.Fatal(Utility.JsonSerialize_IgnoreLoopingReference(trace));
113+
Log.Instance.Fatal(e);
114+
Log.Instance.Fatal(e.StackTrace);
117115
await returnResponseAsync(httpContext, "", apiCancellationToken, HttpStatusCode.InternalServerError);
118116
}
119117
}
@@ -197,7 +195,7 @@ Value of HttpContext.Current.Request.Url.PathAndQuery
197195
{
198196
Log.Instance.Fatal("Request params: " + Utility.JsonSerialize_IgnoreLoopingReference(RequestParams));
199197
Log.Instance.Fatal(e);
200-
await ParseError(context, HttpStatusCode.BadRequest, sourceToken, e.Message);
198+
await ParseError(context, HttpStatusCode.BadRequest, sourceToken, "Bad Request");
201199
}
202200
}
203201

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11

2+
using System.Collections.Concurrent;
23
using System.Reflection;
34

45
namespace API
56
{
67
/// <summary>
7-
/// Static implementation of the Log4Net
8+
/// Static dictionarys for attributes to reduce need for reflection
89
/// </summary>
910
public static class AttributeDictionary
1011
{
11-
/// <summary>
12-
/// Initiate Log4Net
13-
/// </summary>
14-
internal static Dictionary<string, RuntimeMethodHandle> AllowedAPIDictionary = new Dictionary<string, RuntimeMethodHandle>();
1512

13+
public static ConcurrentDictionary<string, RuntimeMethodHandle> AllowedAPIDictionary = new ConcurrentDictionary<string, RuntimeMethodHandle>();
1614

17-
internal static Dictionary<string, RuntimeMethodHandle> DictMethodAttributeValue = new Dictionary<string, RuntimeMethodHandle>();
18-
19-
20-
internal static Dictionary<string, RuntimeMethodHandle> DictMethodHasAttribute = new Dictionary<string, RuntimeMethodHandle>();
15+
public static ConcurrentDictionary<string, RuntimeMethodHandle> DictMethodAttributeValue = new ConcurrentDictionary<string, RuntimeMethodHandle>();
2116

17+
public static ConcurrentDictionary<string, RuntimeMethodHandle> DictMethodHasAttribute = new ConcurrentDictionary<string, RuntimeMethodHandle>();
2218

2319
}
2420
}

src/API.Library/Entities/MethodReader.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,22 @@ public static CustomAttributeData MethodAttributeValue(string method, string att
9090
//get the methods handle
9191
RuntimeMethodHandle handle = methodInfo.MethodHandle;
9292

93-
//add handle to dictionary for future lookup
94-
95-
if (!AttributeDictionary.DictMethodAttributeValue.TryAdd(serializedAPIInfo, handle))
93+
try
9694
{
97-
Log.Instance.Debug("Adding : " + serializedAPIInfo + " to dictionary 'DictMethodAttributeValue' failed");
95+
//add handle to dictionary for future lookup
96+
if (!AttributeDictionary.DictMethodAttributeValue.TryAdd(serializedAPIInfo, handle))
97+
{
98+
Log.Instance.Debug("Adding : " + serializedAPIInfo + " to dictionary 'DictMethodAttributeValue' failed");
99+
}
98100
}
99-
101+
catch (Exception ex)
102+
{
103+
Log.Instance.Error(ex);
104+
}
105+
100106

101-
//Return true or false depending on whether the attribute was found
102-
return searchedAttribute;
107+
//Return true or false depending on whether the attribute was found
108+
return searchedAttribute;
103109
}
104110
catch
105111
{
@@ -189,13 +195,18 @@ public static bool MethodHasAttribute(string method, string attributeName, Type[
189195

190196
//get the methods handle
191197
RuntimeMethodHandle handle = methodInfo.MethodHandle;
192-
193-
//add handle to dictionary for future lookup
194-
if (!AttributeDictionary.DictMethodHasAttribute.TryAdd(serializedAPIInfo, handle))
198+
try
199+
{
200+
//add handle to dictionary for future lookup
201+
if (!AttributeDictionary.DictMethodHasAttribute.TryAdd(serializedAPIInfo, handle))
202+
{
203+
Log.Instance.Debug("Adding : " + serializedAPIInfo + " to dictionary 'DictMethodHasAttribute' failed");
204+
}
205+
}
206+
catch (Exception ex)
195207
{
196-
Log.Instance.Debug("Adding : " + serializedAPIInfo + " to dictionary 'DictMethodHasAttribute' failed");
208+
Log.Instance.Error(ex);
197209
}
198-
199210

200211
//Return true or false depending on whether the attribute was found
201212
return searchedAttribute != null;

src/API.Library/Entities/Utility.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,14 @@ public static bool TryParseJson<T>(this string @this, out T result)
331331
result = JsonConvert.DeserializeObject<T>(@this, settings);
332332
return success;
333333
}
334-
#endregion
334+
335335

336336
public static decimal StopWatchToSeconds(Stopwatch sw)
337337
{
338338
return decimal.Round((decimal)sw.Elapsed.TotalMilliseconds / 1000, 3);
339339
}
340340

341-
}
341+
#endregion
342+
343+
}
342344
}

0 commit comments

Comments
 (0)