55using System . Net ;
66using System . Net . Http ;
77using System . Text ;
8+ using System . Threading . Tasks ;
89using GeneXus . Application ;
910using GeneXus . Configuration ;
1011using GeneXus . Data ;
1415using Microsoft . AspNetCore . Http ;
1516using Microsoft . AspNetCore . Mvc ;
1617using Microsoft . AspNetCore . Mvc . Filters ;
17- using Microsoft . AspNetCore . Mvc . ModelBinding . Binders ;
1818using Microsoft . AspNetCore . Mvc . ModelBinding ;
19- using System . Threading . Tasks ;
19+ using Microsoft . AspNetCore . Mvc . ModelBinding . Binders ;
2020
2121
2222namespace GeneXus . Utils
@@ -82,7 +82,7 @@ protected GxRestService()
8282 [ NonAction ]
8383 internal void Initialize ( )
8484 {
85- context . HttpContext = HttpContext ;
85+ context . HttpContext = GetHttpContext ( ) ;
8686 context . HttpContext . NewSessionCheck ( ) ;
8787 ServiceHeaders ( ) ;
8888 }
@@ -127,7 +127,7 @@ protected string RestStringParameter(string parameterName, string parameterValue
127127 {
128128 try
129129 {
130- if ( HttpContext . Request . Query . TryGetValue ( parameterName , out var value ) )
130+ if ( GetHttpContext ( ) . Request . Query . TryGetValue ( parameterName , out var value ) )
131131 return value . FirstOrDefault ( ) ;
132132 else
133133 return parameterValue ;
@@ -141,7 +141,7 @@ protected bool RestParameter(string parameterName, string parameterValue)
141141 {
142142 try
143143 {
144- if ( HttpContext . Request . Query . TryGetValue ( parameterName , out var value ) )
144+ if ( GetHttpContext ( ) . Request . Query . TryGetValue ( parameterName , out var value ) )
145145 return value . FirstOrDefault ( ) . Equals ( parameterValue , StringComparison . OrdinalIgnoreCase ) ;
146146 return false ;
147147 }
@@ -157,9 +157,9 @@ protected ActionResult UploadImpl()
157157 string fileToken ;
158158 using ( Stream stream = Request . Body )
159159 {
160- fileToken = gxobject . ReadFileFromStream ( stream , Request . ContentType , Request . ContentLength . GetValueOrDefault ( ) , Request . Headers [ HttpHeader . XGXFILENAME ] , out fileGuid ) ;
160+ fileToken = gxobject . ReadFileFromStream ( stream , GetHttpContext ( ) . Request . ContentType , GetHttpContext ( ) . Request . ContentLength . GetValueOrDefault ( ) , GetHttpContext ( ) . Request . Headers [ HttpHeader . XGXFILENAME ] , out fileGuid ) ;
161161 }
162- Response . Headers . Append ( HttpHeader . GX_OBJECT_ID , fileGuid ) ;
162+ GetHttpContext ( ) . Response . Headers . Append ( HttpHeader . GX_OBJECT_ID , fileGuid ) ;
163163 SetStatusCode ( HttpStatusCode . Created ) ;
164164 return GetResponse ( new { object_id = fileToken } ) ;
165165 }
@@ -251,12 +251,12 @@ protected ObjectResult HandleException(Exception ex)
251251
252252 if ( ex is FormatException || ex is NullReferenceException )
253253 {
254- WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( HttpContext , HttpStatusCode . BadRequest , ex ) ;
254+ WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . BadRequest , ex ) ;
255255 return BadRequest ( jsonError ) ;
256256 }
257257 else
258258 {
259- WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( HttpContext , HttpStatusCode . InternalServerError , ex ) ;
259+ WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . InternalServerError , ex ) ;
260260 return StatusCode ( ( int ) HttpStatusCode . InternalServerError , jsonError ) ;
261261 }
262262 }
@@ -266,11 +266,11 @@ protected void WebException(Exception ex)
266266
267267 if ( ex is FormatException )
268268 {
269- HttpHelper . SetUnexpectedError ( HttpContext , HttpStatusCode . BadRequest , ex ) ;
269+ HttpHelper . SetUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . BadRequest , ex ) ;
270270 }
271271 else
272272 {
273- HttpHelper . SetUnexpectedError ( HttpContext , HttpStatusCode . InternalServerError , ex ) ;
273+ HttpHelper . SetUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . InternalServerError , ex ) ;
274274 }
275275 }
276276
@@ -376,21 +376,21 @@ private bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool o
376376 internal WrappedJsonError HandleGamError ( string code , string message , HttpStatusCode defaultCode = HttpStatusCode . Unauthorized )
377377 {
378378 HttpStatusCode httpStatusCode = HttpHelper . GamCodeToHttpStatus ( code , defaultCode ) ;
379- SetErrorHeaders ( HttpContext , httpStatusCode , message ) ;
379+ SetErrorHeaders ( GetHttpContext ( ) , httpStatusCode , message ) ;
380380 return HttpHelper . GetJsonError ( code , message ) ;
381381 }
382382 internal WrappedJsonError HandleError ( string code , string message )
383383 {
384384 HttpStatusCode httpStatusCode = HttpHelper . MapStatusCode ( code ) ;
385- SetErrorHeaders ( HttpContext , httpStatusCode , message ) ;
385+ SetErrorHeaders ( GetHttpContext ( ) , httpStatusCode , message ) ;
386386 return HttpHelper . GetJsonError ( code , message ) ;
387387 }
388388 private void SetErrorHeaders ( HttpContext httpContext , HttpStatusCode httpStatusCode , string message )
389389 {
390- if ( httpContext != null )
390+ if ( GetHttpContext ( ) != null )
391391 {
392392 SetStatusCode ( httpStatusCode ) ;
393- HttpHelper . HandleUnauthorized ( httpStatusCode , httpContext ) ;
393+ HttpHelper . HandleUnauthorized ( httpStatusCode , GetHttpContext ( ) ) ;
394394 httpContext . SetReasonPhrase ( message ) ;
395395 GXLogging . Error ( log , String . Format ( "ErrCode {0}, ErrDsc {1}" , httpStatusCode , message ) ) ;
396396 }
@@ -409,33 +409,33 @@ protected void SetStatusCode(HttpStatusCode code)
409409 }
410410 IHeaderDictionary GetHeaders ( )
411411 {
412- if ( HttpContext != null )
412+ if ( GetHttpContext ( ) != null )
413413 {
414- return HttpContext . Request . Headers ;
414+ return GetHttpContext ( ) . Request . Headers ;
415415 }
416416 else return null ;
417417 }
418418 string GetHeader ( string header )
419419 {
420- if ( HttpContext != null )
420+ if ( GetHttpContext ( ) != null )
421421 {
422- return HttpContext . Request . Headers [ header ] ;
422+ return GetHttpContext ( ) . Request . Headers [ header ] ;
423423 }
424424 else return null ;
425425 }
426426 bool IsPost ( )
427427 {
428- if ( HttpContext != null )
428+ if ( GetHttpContext ( ) != null )
429429 {
430- return HttpMethod . Post . Method == HttpContext . Request . GetMethod ( ) ;
430+ return HttpMethod . Post . Method == GetHttpContext ( ) . Request . GetMethod ( ) ;
431431 }
432432 else return false ;
433433 }
434434 void AddHeader ( string header , string value )
435435 {
436- if ( HttpContext != null )
436+ if ( GetHttpContext ( ) != null )
437437 {
438- HttpContext . Response . Headers [ header ] = value ;
438+ GetHttpContext ( ) . Response . Headers [ header ] = value ;
439439 }
440440 }
441441 protected bool ProcessHeaders ( string queryId )
@@ -490,9 +490,9 @@ private void SendCacheHeaders()
490490 private void ServiceHeaders ( )
491491 {
492492 SendCacheHeaders ( ) ;
493- if ( HttpContext != null )
493+ if ( GetHttpContext ( ) != null )
494494 {
495- HttpHelper . CorsHeaders ( HttpContext ) ;
495+ HttpHelper . CorsHeaders ( GetHttpContext ( ) ) ;
496496 }
497497
498498 }
@@ -508,6 +508,11 @@ string dateTimeToHTMLDate(DateTime dt)
508508 {
509509 return dt . ToUniversalTime ( ) . ToString ( DateTimeFormatInfo . InvariantInfo . RFC1123Pattern , DateTimeFormatInfo . InvariantInfo ) ;
510510 }
511+
512+ protected virtual HttpContext GetHttpContext ( )
513+ {
514+ return base . HttpContext ;
515+ }
511516 protected virtual bool IsSynchronizer { get { return false ; } }
512517 protected virtual bool IntegratedSecurityEnabled { get { return false ; } }
513518 protected virtual GAMSecurityLevel ApiIntegratedSecurityLevel ( string gxMethod ) { return IntegratedSecurityLevel ; }
0 commit comments