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 }
@@ -158,7 +158,7 @@ protected string RestStringParameter(string parameterName, string parameterValue
158158 {
159159 try
160160 {
161- if ( HttpContext . Request . Query . TryGetValue ( parameterName , out var value ) )
161+ if ( GetHttpContext ( ) . Request . Query . TryGetValue ( parameterName , out var value ) )
162162 return value . FirstOrDefault ( ) ;
163163 else
164164 return parameterValue ;
@@ -172,7 +172,7 @@ protected bool RestParameter(string parameterName, string parameterValue)
172172 {
173173 try
174174 {
175- if ( HttpContext . Request . Query . TryGetValue ( parameterName , out var value ) )
175+ if ( GetHttpContext ( ) . Request . Query . TryGetValue ( parameterName , out var value ) )
176176 return value . FirstOrDefault ( ) . Equals ( parameterValue , StringComparison . OrdinalIgnoreCase ) ;
177177 return false ;
178178 }
@@ -188,9 +188,9 @@ protected ActionResult UploadImpl()
188188 string fileToken ;
189189 using ( Stream stream = Request . Body )
190190 {
191- fileToken = gxobject . ReadFileFromStream ( stream , Request . ContentType , Request . ContentLength . GetValueOrDefault ( ) , Request . Headers [ HttpHeader . XGXFILENAME ] , out fileGuid ) ;
191+ fileToken = gxobject . ReadFileFromStream ( stream , GetHttpContext ( ) . Request . ContentType , GetHttpContext ( ) . Request . ContentLength . GetValueOrDefault ( ) , GetHttpContext ( ) . Request . Headers [ HttpHeader . XGXFILENAME ] , out fileGuid ) ;
192192 }
193- Response . Headers . Append ( HttpHeader . GX_OBJECT_ID , fileGuid ) ;
193+ GetHttpContext ( ) . Response . Headers . Append ( HttpHeader . GX_OBJECT_ID , fileGuid ) ;
194194 SetStatusCode ( HttpStatusCode . Created ) ;
195195 return GetResponse ( new { object_id = fileToken } ) ;
196196 }
@@ -282,12 +282,12 @@ protected ObjectResult HandleException(Exception ex)
282282
283283 if ( ex is FormatException || ex is NullReferenceException )
284284 {
285- WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( HttpContext , HttpStatusCode . BadRequest , ex ) ;
285+ WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . BadRequest , ex ) ;
286286 return BadRequest ( jsonError ) ;
287287 }
288288 else
289289 {
290- WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( HttpContext , HttpStatusCode . InternalServerError , ex ) ;
290+ WrappedJsonError jsonError = HttpHelper . HandleUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . InternalServerError , ex ) ;
291291 return StatusCode ( ( int ) HttpStatusCode . InternalServerError , jsonError ) ;
292292 }
293293 }
@@ -297,11 +297,11 @@ protected void WebException(Exception ex)
297297
298298 if ( ex is FormatException )
299299 {
300- HttpHelper . SetUnexpectedError ( HttpContext , HttpStatusCode . BadRequest , ex ) ;
300+ HttpHelper . SetUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . BadRequest , ex ) ;
301301 }
302302 else
303303 {
304- HttpHelper . SetUnexpectedError ( HttpContext , HttpStatusCode . InternalServerError , ex ) ;
304+ HttpHelper . SetUnexpectedError ( GetHttpContext ( ) , HttpStatusCode . InternalServerError , ex ) ;
305305 }
306306 }
307307
@@ -407,21 +407,21 @@ private bool IsAuthenticated(GAMSecurityLevel objIntegratedSecurityLevel, bool o
407407 internal WrappedJsonError HandleGamError ( string code , string message , HttpStatusCode defaultCode = HttpStatusCode . Unauthorized )
408408 {
409409 HttpStatusCode httpStatusCode = HttpHelper . GamCodeToHttpStatus ( code , defaultCode ) ;
410- SetErrorHeaders ( HttpContext , httpStatusCode , message ) ;
410+ SetErrorHeaders ( GetHttpContext ( ) , httpStatusCode , message ) ;
411411 return HttpHelper . GetJsonError ( code , message ) ;
412412 }
413413 internal WrappedJsonError HandleError ( string code , string message )
414414 {
415415 HttpStatusCode httpStatusCode = HttpHelper . MapStatusCode ( code ) ;
416- SetErrorHeaders ( HttpContext , httpStatusCode , message ) ;
416+ SetErrorHeaders ( GetHttpContext ( ) , httpStatusCode , message ) ;
417417 return HttpHelper . GetJsonError ( code , message ) ;
418418 }
419419 private void SetErrorHeaders ( HttpContext httpContext , HttpStatusCode httpStatusCode , string message )
420420 {
421- if ( httpContext != null )
421+ if ( GetHttpContext ( ) != null )
422422 {
423423 SetStatusCode ( httpStatusCode ) ;
424- HttpHelper . HandleUnauthorized ( httpStatusCode , httpContext ) ;
424+ HttpHelper . HandleUnauthorized ( httpStatusCode , GetHttpContext ( ) ) ;
425425 httpContext . SetReasonPhrase ( message ) ;
426426 GXLogging . Error ( log , String . Format ( "ErrCode {0}, ErrDsc {1}" , httpStatusCode , message ) ) ;
427427 }
@@ -440,33 +440,33 @@ protected void SetStatusCode(HttpStatusCode code)
440440 }
441441 IHeaderDictionary GetHeaders ( )
442442 {
443- if ( HttpContext != null )
443+ if ( GetHttpContext ( ) != null )
444444 {
445- return HttpContext . Request . Headers ;
445+ return GetHttpContext ( ) . Request . Headers ;
446446 }
447447 else return null ;
448448 }
449449 string GetHeader ( string header )
450450 {
451- if ( HttpContext != null )
451+ if ( GetHttpContext ( ) != null )
452452 {
453- return HttpContext . Request . Headers [ header ] ;
453+ return GetHttpContext ( ) . Request . Headers [ header ] ;
454454 }
455455 else return null ;
456456 }
457457 bool IsPost ( )
458458 {
459- if ( HttpContext != null )
459+ if ( GetHttpContext ( ) != null )
460460 {
461- return HttpMethod . Post . Method == HttpContext . Request . GetMethod ( ) ;
461+ return HttpMethod . Post . Method == GetHttpContext ( ) . Request . GetMethod ( ) ;
462462 }
463463 else return false ;
464464 }
465465 void AddHeader ( string header , string value )
466466 {
467- if ( HttpContext != null )
467+ if ( GetHttpContext ( ) != null )
468468 {
469- HttpContext . Response . Headers [ header ] = value ;
469+ GetHttpContext ( ) . Response . Headers [ header ] = value ;
470470 }
471471 }
472472 protected bool ProcessHeaders ( string queryId )
@@ -521,9 +521,9 @@ private void SendCacheHeaders()
521521 private void ServiceHeaders ( )
522522 {
523523 SendCacheHeaders ( ) ;
524- if ( HttpContext != null )
524+ if ( GetHttpContext ( ) != null )
525525 {
526- HttpHelper . CorsHeaders ( HttpContext ) ;
526+ HttpHelper . CorsHeaders ( GetHttpContext ( ) ) ;
527527 }
528528
529529 }
@@ -539,6 +539,11 @@ string dateTimeToHTMLDate(DateTime dt)
539539 {
540540 return dt . ToUniversalTime ( ) . ToString ( DateTimeFormatInfo . InvariantInfo . RFC1123Pattern , DateTimeFormatInfo . InvariantInfo ) ;
541541 }
542+
543+ protected virtual HttpContext GetHttpContext ( )
544+ {
545+ return base . HttpContext ;
546+ }
542547 protected virtual bool IsSynchronizer { get { return false ; } }
543548 protected virtual bool IntegratedSecurityEnabled { get { return false ; } }
544549 protected virtual GAMSecurityLevel ApiIntegratedSecurityLevel ( string gxMethod ) { return IntegratedSecurityLevel ; }
0 commit comments