From b7ef236c5dc239610e247471529f60c09aef6917 Mon Sep 17 00:00:00 2001 From: Arend-Jan Kauffmann Date: Wed, 11 Dec 2024 14:09:23 +0100 Subject: [PATCH] Refactor HttpClientHandler and HttpContentImpl to improve variable naming and remove the usage of this for clarity and readability. --- .../HttpClientHandler.Codeunit.al | 4 +- .../HttpClientHandler.Interface.al | 2 +- .../src/HttpContentImpl.Codeunit.al | 64 +++++++------- .../src/HttpRequestMessageImpl.Codeunit.al | 86 +++++++++---------- .../src/HttpResponseMessageImpl.Codeunit.al | 64 +++++++------- .../src/RestClientImpl.Codeunit.al | 62 ++++++------- 6 files changed, 141 insertions(+), 141 deletions(-) diff --git a/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Codeunit.al b/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Codeunit.al index edd33ee443..41f24996e3 100644 --- a/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Codeunit.al +++ b/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Codeunit.al @@ -10,11 +10,11 @@ codeunit 2360 "Http Client Handler" implements "Http Client Handler" InherentEntitlements = X; InherentPermissions = X; - procedure Send(HttpClient: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean; + procedure Send(CurrHttpClientInstance: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean; var ResponseMessage: HttpResponseMessage; begin - Success := HttpClient.Send(HttpRequestMessage.GetHttpRequestMessage(), ResponseMessage); + Success := CurrHttpClientInstance.Send(HttpRequestMessage.GetHttpRequestMessage(), ResponseMessage); HttpResponseMessage := HttpResponseMessage.Create(ResponseMessage); end; } \ No newline at end of file diff --git a/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Interface.al b/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Interface.al index 849a4605ea..b4d492dfd2 100644 --- a/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Interface.al +++ b/src/System Application/App/Rest Client/src/HttpClientHandler/HttpClientHandler.Interface.al @@ -6,5 +6,5 @@ namespace System.RestClient; interface "Http Client Handler" { - procedure Send(HttpClient: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean; + procedure Send(CurrHttpClientInstance: HttpClient; HttpRequestMessage: Codeunit "Http Request Message"; var HttpResponseMessage: Codeunit "Http Response Message") Success: Boolean; } \ No newline at end of file diff --git a/src/System Application/App/Rest Client/src/HttpContentImpl.Codeunit.al b/src/System Application/App/Rest Client/src/HttpContentImpl.Codeunit.al index fb4409d007..8b1488e5c5 100644 --- a/src/System Application/App/Rest Client/src/HttpContentImpl.Codeunit.al +++ b/src/System Application/App/Rest Client/src/HttpContentImpl.Codeunit.al @@ -13,7 +13,7 @@ codeunit 2355 "Http Content Impl." InherentPermissions = X; var - HttpContent: HttpContent; + CurrHttpContentInstance: HttpContent; ContentTypeEmptyErr: Label 'The value of the Content-Type header must be specified.'; MimeTypeTextPlainTxt: Label 'text/plain', Locked = true; MimeTypeTextXmlTxt: Label 'text/xml', Locked = true; @@ -114,58 +114,58 @@ codeunit 2355 "Http Content Impl." procedure AddContentEncoding(ContentEncoding: Text) var - Headers: HttpHeaders; + ContentHeaders: HttpHeaders; begin - if not this.HttpContent.GetHeaders(Headers) then begin - this.HttpContent.Clear(); - this.HttpContent.GetHeaders(Headers); + if not CurrHttpContentInstance.GetHeaders(ContentHeaders) then begin + CurrHttpContentInstance.Clear(); + CurrHttpContentInstance.GetHeaders(ContentHeaders); end; - Headers.Add('Content-Encoding', ContentEncoding); + ContentHeaders.Add('Content-Encoding', ContentEncoding); end; procedure SetHeader(Name: Text; Value: Text) var - Headers: HttpHeaders; + ContentHeaders: HttpHeaders; begin - if not this.HttpContent.GetHeaders(Headers) then begin - this.HttpContent.Clear(); - this.HttpContent.GetHeaders(Headers); + if not CurrHttpContentInstance.GetHeaders(ContentHeaders) then begin + CurrHttpContentInstance.Clear(); + CurrHttpContentInstance.GetHeaders(ContentHeaders); end; - if Headers.Contains(Name) or Headers.ContainsSecret(Name) then - Headers.Remove(Name); + if ContentHeaders.Contains(Name) or ContentHeaders.ContainsSecret(Name) then + ContentHeaders.Remove(Name); - Headers.Add(Name, Value); + ContentHeaders.Add(Name, Value); end; procedure SetHeader(Name: Text; Value: SecretText) var - Headers: HttpHeaders; + ContentHeaders: HttpHeaders; begin - if not this.HttpContent.GetHeaders(Headers) then begin - this.HttpContent.Clear(); - this.HttpContent.GetHeaders(Headers); + if not CurrHttpContentInstance.GetHeaders(ContentHeaders) then begin + CurrHttpContentInstance.Clear(); + CurrHttpContentInstance.GetHeaders(ContentHeaders); end; - if Headers.Contains(Name) or Headers.ContainsSecret(Name) then - Headers.Remove(Name); + if ContentHeaders.Contains(Name) or ContentHeaders.ContainsSecret(Name) then + ContentHeaders.Remove(Name); - Headers.Add(Name, Value); + ContentHeaders.Add(Name, Value); end; procedure GetHttpContent() ReturnValue: HttpContent begin - ReturnValue := this.HttpContent; + ReturnValue := CurrHttpContentInstance; end; procedure AsText() ReturnValue: Text begin - this.HttpContent.ReadAs(ReturnValue); + CurrHttpContentInstance.ReadAs(ReturnValue); end; procedure AsSecretText() ReturnValue: SecretText begin - this.HttpContent.ReadAs(ReturnValue); + CurrHttpContentInstance.ReadAs(ReturnValue); end; procedure AsBlob() ReturnValue: Codeunit "Temp Blob" @@ -173,14 +173,14 @@ codeunit 2355 "Http Content Impl." InStr: InStream; OutStr: OutStream; begin - this.HttpContent.ReadAs(InStr); + CurrHttpContentInstance.ReadAs(InStr); ReturnValue.CreateOutStream(OutStr); CopyStream(OutStr, InStr); end; procedure AsInStream(var InStr: InStream) begin - this.HttpContent.ReadAs(InStr); + CurrHttpContentInstance.ReadAs(InStr); end; procedure AsXmlDocument() ReturnValue: XmlDocument @@ -227,8 +227,8 @@ codeunit 2355 "Http Content Impl." procedure SetContent(Content: Text; ContentType: Text) begin - this.HttpContent.Clear(); - this.HttpContent.WriteFrom(Content); + CurrHttpContentInstance.Clear(); + CurrHttpContentInstance.WriteFrom(Content); if ContentType = '' then ContentType := MimeTypeTextPlainTxt; SetContentTypeHeader(ContentType); @@ -236,8 +236,8 @@ codeunit 2355 "Http Content Impl." procedure SetContent(Content: SecretText; ContentType: Text) begin - this.HttpContent.Clear(); - this.HttpContent.WriteFrom(Content); + CurrHttpContentInstance.Clear(); + CurrHttpContentInstance.WriteFrom(Content); if ContentType = '' then ContentType := MimeTypeTextPlainTxt; SetContentTypeHeader(ContentType); @@ -245,8 +245,8 @@ codeunit 2355 "Http Content Impl." procedure SetContent(Content: InStream; ContentType: Text) begin - this.HttpContent.Clear(); - this.HttpContent.WriteFrom(Content); + CurrHttpContentInstance.Clear(); + CurrHttpContentInstance.WriteFrom(Content); if ContentType = '' then ContentType := MimeTypeApplicationOctetStreamTxt; SetContentTypeHeader(ContentType); @@ -282,7 +282,7 @@ codeunit 2355 "Http Content Impl." procedure SetContent(var Value: HttpContent) begin - this.HttpContent := Value; + CurrHttpContentInstance := Value; end; local procedure ThrowInvalidJsonException() diff --git a/src/System Application/App/Rest Client/src/HttpRequestMessageImpl.Codeunit.al b/src/System Application/App/Rest Client/src/HttpRequestMessageImpl.Codeunit.al index 1da949178b..6ac1c89795 100644 --- a/src/System Application/App/Rest Client/src/HttpRequestMessageImpl.Codeunit.al +++ b/src/System Application/App/Rest Client/src/HttpRequestMessageImpl.Codeunit.al @@ -11,7 +11,7 @@ codeunit 2353 "Http Request Message Impl." InherentPermissions = X; var - HttpRequestMessage: HttpRequestMessage; + CurrHttpRequestMessageInstance: HttpRequestMessage; procedure Create(Method: Enum "Http Method"; RequestUri: Text; Content: Codeunit "Http Content"): Codeunit "Http Request Message Impl." begin @@ -24,7 +24,7 @@ codeunit 2353 "Http Request Message Impl." procedure SetHttpMethod(Method: Text) begin - HttpRequestMessage.Method := Method; + CurrHttpRequestMessageInstance.Method := Method; end; procedure SetHttpMethod(Method: Enum "Http Method") @@ -34,52 +34,52 @@ codeunit 2353 "Http Request Message Impl." procedure GetHttpMethod() ReturnValue: Text begin - ReturnValue := HttpRequestMessage.Method; + ReturnValue := CurrHttpRequestMessageInstance.Method; end; procedure SetRequestUri(Uri: Text) begin - HttpRequestMessage.SetRequestUri(Uri); + CurrHttpRequestMessageInstance.SetRequestUri(Uri); end; procedure GetRequestUri() Uri: Text begin - Uri := HttpRequestMessage.GetRequestUri(); + Uri := CurrHttpRequestMessageInstance.GetRequestUri(); end; procedure SetHeader(HeaderName: Text; HeaderValue: Text) var - HttpHeaders: HttpHeaders; + RequestHttpHeaders: HttpHeaders; begin - HttpRequestMessage.GetHeaders(HttpHeaders); - if HttpHeaders.Contains(HeaderName) or HttpHeaders.ContainsSecret(HeaderName) then - HttpHeaders.Remove(HeaderName); - HttpHeaders.Add(HeaderName, HeaderValue); + CurrHttpRequestMessageInstance.GetHeaders(RequestHttpHeaders); + if RequestHttpHeaders.Contains(HeaderName) or RequestHttpHeaders.ContainsSecret(HeaderName) then + RequestHttpHeaders.Remove(HeaderName); + RequestHttpHeaders.Add(HeaderName, HeaderValue); end; procedure SetHeader(HeaderName: Text; HeaderValue: SecretText) var - HttpHeaders: HttpHeaders; + RequestHttpHeaders: HttpHeaders; begin - HttpRequestMessage.GetHeaders(HttpHeaders); - if HttpHeaders.Contains(HeaderName) or HttpHeaders.ContainsSecret(HeaderName) then - HttpHeaders.Remove(HeaderName); - HttpHeaders.Add(HeaderName, HeaderValue); + CurrHttpRequestMessageInstance.GetHeaders(RequestHttpHeaders); + if RequestHttpHeaders.Contains(HeaderName) or RequestHttpHeaders.ContainsSecret(HeaderName) then + RequestHttpHeaders.Remove(HeaderName); + RequestHttpHeaders.Add(HeaderName, HeaderValue); end; procedure GetHeaders() ReturnValue: HttpHeaders begin - HttpRequestMessage.GetHeaders(ReturnValue); + CurrHttpRequestMessageInstance.GetHeaders(ReturnValue); end; procedure GetHeaderValue(HeaderName: Text) Value: Text var - HttpHeaders: HttpHeaders; + RequestHttpHeaders: HttpHeaders; Values: List of [Text]; begin - HttpRequestMessage.GetHeaders(HttpHeaders); - if HttpHeaders.Contains(HeaderName) then begin - HttpHeaders.GetValues(HeaderName, Values); + CurrHttpRequestMessageInstance.GetHeaders(RequestHttpHeaders); + if RequestHttpHeaders.Contains(HeaderName) then begin + RequestHttpHeaders.GetValues(HeaderName, Values); if Values.Count > 0 then Value := Values.Get(1); end; @@ -87,75 +87,75 @@ codeunit 2353 "Http Request Message Impl." procedure GetHeaderValues(HeaderName: Text) Values: List of [Text] var - HttpHeaders: HttpHeaders; + RequestHttpHeaders: HttpHeaders; begin - HttpRequestMessage.GetHeaders(HttpHeaders); - if HttpHeaders.Contains(HeaderName) then - HttpHeaders.GetValues(HeaderName, Values); + CurrHttpRequestMessageInstance.GetHeaders(RequestHttpHeaders); + if RequestHttpHeaders.Contains(HeaderName) then + RequestHttpHeaders.GetValues(HeaderName, Values); end; procedure GetSecretHeaderValues(HeaderName: Text) Values: List of [SecretText] var - HttpHeaders: HttpHeaders; + RequestHttpHeaders: HttpHeaders; begin - HttpRequestMessage.GetHeaders(HttpHeaders); - if HttpHeaders.ContainsSecret(HeaderName) then - HttpHeaders.GetSecretValues(HeaderName, Values); + CurrHttpRequestMessageInstance.GetHeaders(RequestHttpHeaders); + if RequestHttpHeaders.ContainsSecret(HeaderName) then + RequestHttpHeaders.GetSecretValues(HeaderName, Values); end; procedure SetCookie(Name: Text; Value: Text) Success: Boolean begin - Success := HttpRequestMessage.SetCookie(Name, Value); + Success := CurrHttpRequestMessageInstance.SetCookie(Name, Value); end; - procedure SetCookie(Cookie: Cookie) Success: Boolean + procedure SetCookie(TheCookie: Cookie) Success: Boolean begin - Success := HttpRequestMessage.SetCookie(Cookie); + Success := CurrHttpRequestMessageInstance.SetCookie(TheCookie); end; procedure GetCookieNames() CookieNames: List of [Text] begin - CookieNames := HttpRequestMessage.GetCookieNames(); + CookieNames := CurrHttpRequestMessageInstance.GetCookieNames(); end; procedure GetCookies() Cookies: List of [Cookie] var CookieName: Text; - Cookie: Cookie; + TheCookie: Cookie; begin - foreach CookieName in HttpRequestMessage.GetCookieNames() do begin - HttpRequestMessage.GetCookie(CookieName, Cookie); - Cookies.Add(Cookie); + foreach CookieName in CurrHttpRequestMessageInstance.GetCookieNames() do begin + CurrHttpRequestMessageInstance.GetCookie(CookieName, TheCookie); + Cookies.Add(TheCookie); end; end; procedure GetCookie(Name: Text) ReturnValue: Cookie begin - if HttpRequestMessage.GetCookie(Name, ReturnValue) then; + if CurrHttpRequestMessageInstance.GetCookie(Name, ReturnValue) then; end; - procedure GetCookie(Name: Text; var Cookie: Cookie) Success: Boolean + procedure GetCookie(Name: Text; var TheCookie: Cookie) Success: Boolean begin - Success := HttpRequestMessage.GetCookie(Name, Cookie); + Success := CurrHttpRequestMessageInstance.GetCookie(Name, TheCookie); end; procedure RemoveCookie(Name: Text) Success: Boolean begin - Success := HttpRequestMessage.RemoveCookie(Name); + Success := CurrHttpRequestMessageInstance.RemoveCookie(Name); end; procedure SetHttpRequestMessage(var RequestMessage: HttpRequestMessage) begin - HttpRequestMessage := RequestMessage; + CurrHttpRequestMessageInstance := RequestMessage; end; procedure SetContent(HttpContent: Codeunit "Http Content") begin - HttpRequestMessage.Content := HttpContent.GetHttpContent(); + CurrHttpRequestMessageInstance.Content := HttpContent.GetHttpContent(); end; procedure GetRequestMessage() ReturnValue: HttpRequestMessage begin - ReturnValue := HttpRequestMessage; + ReturnValue := CurrHttpRequestMessageInstance; end; } \ No newline at end of file diff --git a/src/System Application/App/Rest Client/src/HttpResponseMessageImpl.Codeunit.al b/src/System Application/App/Rest Client/src/HttpResponseMessageImpl.Codeunit.al index f58045ee9a..c6117a53e1 100644 --- a/src/System Application/App/Rest Client/src/HttpResponseMessageImpl.Codeunit.al +++ b/src/System Application/App/Rest Client/src/HttpResponseMessageImpl.Codeunit.al @@ -24,12 +24,12 @@ codeunit 2357 "Http Response Message Impl." procedure SetIsBlockedByEnvironment(Value: Boolean) begin - this.IsBlockedByEnvironment := Value; + IsBlockedByEnvironment := Value; end; procedure GetIsBlockedByEnvironment() ReturnValue: Boolean begin - ReturnValue := this.IsBlockedByEnvironment; + ReturnValue := IsBlockedByEnvironment; end; #endregion @@ -39,13 +39,13 @@ codeunit 2357 "Http Response Message Impl." procedure SetHttpStatusCode(Value: Integer) begin - this.HttpStatusCode := Value; - this.IsSuccessStatusCode := Value in [200 .. 299]; + HttpStatusCode := Value; + IsSuccessStatusCode := Value in [200 .. 299]; end; procedure GetHttpStatusCode() ReturnValue: Integer begin - ReturnValue := this.HttpStatusCode + ReturnValue := HttpStatusCode end; #endregion @@ -55,12 +55,12 @@ codeunit 2357 "Http Response Message Impl." procedure GetIsSuccessStatusCode() Result: Boolean begin - Result := this.IsSuccessStatusCode; + Result := IsSuccessStatusCode; end; procedure SetIsSuccessStatusCode(Value: Boolean) begin - this.IsSuccessStatusCode := Value; + IsSuccessStatusCode := Value; end; #endregion @@ -70,12 +70,12 @@ codeunit 2357 "Http Response Message Impl." procedure SetReasonPhrase(Value: Text) begin - this.ReasonPhrase := Value; + ReasonPhrase := Value; end; procedure GetReasonPhrase() ReturnValue: Text begin - ReturnValue := this.ReasonPhrase; + ReturnValue := ReasonPhrase; end; #endregion @@ -85,18 +85,18 @@ codeunit 2357 "Http Response Message Impl." procedure SetContent(Content: Codeunit "Http Content") begin - this.HttpContent := Content; + HttpContent := Content; end; procedure GetContent() ReturnValue: Codeunit "Http Content" begin - ReturnValue := this.HttpContent; + ReturnValue := HttpContent; end; #endregion #region HttpResponseMessage var - HttpResponseMessage: HttpResponseMessage; + CurrHttpResponseMessageInstance: HttpResponseMessage; procedure SetResponseMessage(var ResponseMessage: HttpResponseMessage) var @@ -105,7 +105,7 @@ codeunit 2357 "Http Response Message Impl." CookieName: Text; begin ClearAll(); - this.HttpResponseMessage := ResponseMessage; + CurrHttpResponseMessageInstance := ResponseMessage; SetIsBlockedByEnvironment(ResponseMessage.IsBlockedByEnvironment); SetHttpStatusCode(ResponseMessage.HttpStatusCode); SetReasonPhrase(ResponseMessage.ReasonPhrase); @@ -121,22 +121,22 @@ codeunit 2357 "Http Response Message Impl." procedure GetResponseMessage() ReturnValue: HttpResponseMessage begin - ReturnValue := this.HttpResponseMessage; + ReturnValue := CurrHttpResponseMessageInstance; end; #endregion #region HttpHeaders var - HttpHeaders: HttpHeaders; + ResponseHttpHeaders: HttpHeaders; procedure SetHeaders(Headers: HttpHeaders) begin - this.HttpHeaders := Headers; + ResponseHttpHeaders := Headers; end; procedure GetHeaders() ReturnValue: HttpHeaders begin - ReturnValue := this.HttpHeaders; + ReturnValue := ResponseHttpHeaders; end; #endregion @@ -146,27 +146,27 @@ codeunit 2357 "Http Response Message Impl." procedure SetCookies(Cookies: Dictionary of [Text, Cookie]) begin - this.GlobalCookies := Cookies; + GlobalCookies := Cookies; end; procedure GetCookies() Cookies: Dictionary of [Text, Cookie] begin - Cookies := this.GlobalCookies; + Cookies := GlobalCookies; end; procedure GetCookieNames() CookieNames: List of [Text] begin - CookieNames := this.GlobalCookies.Keys; + CookieNames := GlobalCookies.Keys; end; - procedure GetCookie(Name: Text) Cookie: Cookie + procedure GetCookie(Name: Text) TheCookie: Cookie begin - if this.GlobalCookies.Get(Name, Cookie) then; + if GlobalCookies.Get(Name, TheCookie) then; end; - procedure GetCookie(Name: Text; var Cookie: Cookie) Success: Boolean + procedure GetCookie(Name: Text; var TheCookie: Cookie) Success: Boolean begin - Success := this.GlobalCookies.Get(Name, Cookie); + Success := GlobalCookies.Get(Name, TheCookie); end; #endregion @@ -177,33 +177,33 @@ codeunit 2357 "Http Response Message Impl." procedure SetErrorMessage(Value: Text) begin - this.ErrorMessage := Value; + ErrorMessage := Value; end; procedure GetErrorMessage(): Text begin - if this.GlobalException.Message <> '' then - exit(this.GlobalException.Message); + if GlobalException.Message <> '' then + exit(GlobalException.Message); - if this.ErrorMessage <> '' then - exit(this.ErrorMessage); + if ErrorMessage <> '' then + exit(ErrorMessage); exit(GetLastErrorText()); end; procedure SetException(Exception: ErrorInfo) begin - this.GlobalException := Exception; + GlobalException := Exception; end; procedure GetException() Exception: ErrorInfo var RestClientExceptionBuilder: Codeunit "Rest Client Exception Builder"; begin - if this.GlobalException.Message = '' then + if GlobalException.Message = '' then Exception := RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::UnknownException, GetErrorMessage()) else - Exception := this.GlobalException; + Exception := GlobalException; end; #endregion } \ No newline at end of file diff --git a/src/System Application/App/Rest Client/src/RestClientImpl.Codeunit.al b/src/System Application/App/Rest Client/src/RestClientImpl.Codeunit.al index 183bf3ebdd..6ba4f969ae 100644 --- a/src/System Application/App/Rest Client/src/RestClientImpl.Codeunit.al +++ b/src/System Application/App/Rest Client/src/RestClientImpl.Codeunit.al @@ -16,7 +16,7 @@ codeunit 2351 "Rest Client Impl." RestClientExceptionBuilder: Codeunit "Rest Client Exception Builder"; HttpAuthentication: Interface "Http Authentication"; HttpClientHandler: Interface "Http Client Handler"; - HttpClient: HttpClient; + CurrHttpClientInstance: HttpClient; IsInitialized: Boolean; EnvironmentBlocksErr: Label 'The outgoing HTTP request to "%1" was blocked by the environment.', Comment = '%1 = url, e.g. https://microsoft.com'; ConnectionErr: Label 'Connection to the remote service "%1" could not be established.', Comment = '%1 = url, e.g. https://microsoft.com'; @@ -27,17 +27,17 @@ codeunit 2351 "Rest Client Impl." #region Constructors procedure Create() RestClientImpl: Codeunit "Rest Client Impl." begin - RestClientImpl := RestClientImpl.Create(this.DefaultHttpClientHandler, this.HttpAuthenticationAnonymous); + RestClientImpl := RestClientImpl.Create(DefaultHttpClientHandler, HttpAuthenticationAnonymous); end; procedure Create(HttpClientHandlerInstance: Interface "Http Client Handler") RestClientImpl: Codeunit "Rest Client Impl." begin - RestClientImpl := RestClientImpl.Create(HttpClientHandlerInstance, this.HttpAuthenticationAnonymous); + RestClientImpl := RestClientImpl.Create(HttpClientHandlerInstance, HttpAuthenticationAnonymous); end; procedure Create(HttpAuthenticationInstance: Interface "Http Authentication") RestClientImpl: Codeunit "Rest Client Impl." begin - RestClientImpl := RestClientImpl.Create(this.DefaultHttpClientHandler, HttpAuthenticationInstance); + RestClientImpl := RestClientImpl.Create(DefaultHttpClientHandler, HttpAuthenticationInstance); end; procedure Create(HttpClientHandlerInstance: Interface "Http Client Handler"; HttpAuthenticationInstance: Interface "Http Authentication"): Codeunit "Rest Client Impl." @@ -50,56 +50,56 @@ codeunit 2351 "Rest Client Impl." #region Initialization procedure Initialize() begin - Initialize(this.DefaultHttpClientHandler, this.HttpAuthenticationAnonymous); + Initialize(DefaultHttpClientHandler, HttpAuthenticationAnonymous); end; procedure Initialize(HttpClientHandlerInstance: Interface "Http Client Handler") begin - Initialize(HttpClientHandlerInstance, this.HttpAuthenticationAnonymous); + Initialize(HttpClientHandlerInstance, HttpAuthenticationAnonymous); end; procedure Initialize(HttpAuthenticationInstance: Interface "Http Authentication") begin - Initialize(this.DefaultHttpClientHandler, HttpAuthenticationInstance); + Initialize(DefaultHttpClientHandler, HttpAuthenticationInstance); end; procedure Initialize(HttpClientHandlerInstance: Interface "Http Client Handler"; HttpAuthenticationInstance: Interface "Http Authentication") begin ClearAll(); - this.HttpClient.Clear(); - this.HttpClientHandler := HttpClientHandlerInstance; - this.HttpAuthentication := HttpAuthenticationInstance; - this.IsInitialized := true; + CurrHttpClientInstance.Clear(); + HttpClientHandler := HttpClientHandlerInstance; + HttpAuthentication := HttpAuthenticationInstance; + IsInitialized := true; SetDefaultUserAgentHeader(); end; procedure SetDefaultRequestHeader(Name: Text; Value: Text) begin CheckInitialized(); - if this.HttpClient.DefaultRequestHeaders.Contains(Name) then - this.HttpClient.DefaultRequestHeaders.Remove(Name); - this.HttpClient.DefaultRequestHeaders.Add(Name, Value); + if CurrHttpClientInstance.DefaultRequestHeaders.Contains(Name) then + CurrHttpClientInstance.DefaultRequestHeaders.Remove(Name); + CurrHttpClientInstance.DefaultRequestHeaders.Add(Name, Value); end; procedure SetDefaultRequestHeader(Name: Text; Value: SecretText) begin CheckInitialized(); - if this.HttpClient.DefaultRequestHeaders.Contains(Name) then - this.HttpClient.DefaultRequestHeaders.Remove(Name); - this.HttpClient.DefaultRequestHeaders.Add(Name, Value); + if CurrHttpClientInstance.DefaultRequestHeaders.Contains(Name) then + CurrHttpClientInstance.DefaultRequestHeaders.Remove(Name); + CurrHttpClientInstance.DefaultRequestHeaders.Add(Name, Value); end; procedure SetBaseAddress(Url: Text) begin CheckInitialized(); - this.HttpClient.SetBaseAddress(Url); + CurrHttpClientInstance.SetBaseAddress(Url); end; procedure GetBaseAddress() Url: Text begin CheckInitialized(); - Url := this.HttpClient.GetBaseAddress; + Url := CurrHttpClientInstance.GetBaseAddress; end; procedure SetTimeOut(TimeOut: Duration) @@ -107,25 +107,25 @@ codeunit 2351 "Rest Client Impl." CheckInitialized(); if TimeOut <= 0 then Error(TimeoutOutOfRangeErr); - this.HttpClient.Timeout := TimeOut; + CurrHttpClientInstance.Timeout := TimeOut; end; procedure GetTimeOut() TimeOut: Duration begin CheckInitialized(); - TimeOut := this.HttpClient.Timeout; + TimeOut := CurrHttpClientInstance.Timeout; end; procedure AddCertificate(Certificate: Text) begin CheckInitialized(); - this.HttpClient.AddCertificate(Certificate); + CurrHttpClientInstance.AddCertificate(Certificate); end; procedure AddCertificate(Certificate: Text; Password: SecretText) begin CheckInitialized(); - this.HttpClient.AddCertificate(Certificate, Password); + CurrHttpClientInstance.AddCertificate(Certificate, Password); end; procedure SetAuthorizationHeader(Value: SecretText) @@ -141,7 +141,7 @@ codeunit 2351 "Rest Client Impl." procedure SetUseResponseCookies(Value: Boolean) begin CheckInitialized(); - this.HttpClient.UseResponseCookies(Value); + CurrHttpClientInstance.UseResponseCookies(Value); end; #endregion @@ -255,7 +255,7 @@ codeunit 2351 "Rest Client Impl." #region Local Methods local procedure CheckInitialized() begin - if not this.IsInitialized then + if not IsInitialized then Initialize(); end; @@ -281,24 +281,24 @@ codeunit 2351 "Rest Client Impl." begin Clear(HttpResponseMessage); - if this.HttpAuthentication.IsAuthenticationRequired() then + if HttpAuthentication.IsAuthenticationRequired() then Authorize(HttpRequestMessage); - if not this.HttpClientHandler.Send(this.HttpClient, HttpRequestMessage, HttpResponseMessage) then begin + if not HttpClientHandler.Send(CurrHttpClientInstance, HttpRequestMessage, HttpResponseMessage) then begin if HttpResponseMessage.GetIsBlockedByEnvironment() then HttpResponseMessage.SetException( - this.RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::BlockedByEnvironment, + RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::BlockedByEnvironment, StrSubstNo(EnvironmentBlocksErr, HttpRequestMessage.GetRequestUri()))) else HttpResponseMessage.SetException( - this.RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::ConnectionFailed, + RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::ConnectionFailed, StrSubstNo(ConnectionErr, HttpRequestMessage.GetRequestUri()))); exit(false); end; if not HttpResponseMessage.GetIsSuccessStatusCode() then HttpResponseMessage.SetException( - this.RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::RequestFailed, + RestClientExceptionBuilder.CreateException(Enum::"Rest Client Exception"::RequestFailed, StrSubstNo(RequestFailedErr, HttpRequestMessage.GetRequestUri(), HttpResponseMessage.GetHttpStatusCode(), HttpResponseMessage.GetReasonPhrase()))); exit(true); @@ -310,7 +310,7 @@ codeunit 2351 "Rest Client Impl." HeaderName: Text; HeaderValue: SecretText; begin - AuthorizationHeaders := this.HttpAuthentication.GetAuthorizationHeaders(); + AuthorizationHeaders := HttpAuthentication.GetAuthorizationHeaders(); foreach HeaderName in AuthorizationHeaders.Keys do begin HeaderValue := AuthorizationHeaders.Get(HeaderName); HttpRequestMessage.SetHeader(HeaderName, HeaderValue);