Add a parameter called InvocationStatus in the Authenticate method. This parameter receives an object of type ExternalServiceInvocationStatus, which we previously defined.
Define_Map For(*INPUT) Class(#ExternalServiceInvocationStatus) Name(#InvocationStatus) Pass(*BY_REFERENCE) Mandatory(*NULL)
And add the following code to read the status from the response object after #Request.DoGet:
* Get the request status If (#InvocationStatus *IsNot *Null) #InvocationStatus.FromHttpResponse( #Request.Response ) Endif
The complete source code of the Authenticate method after the adjustments (new lines are highlighted in yellow):
Mthroutine Name(Authenticate) * Parameters Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#Domain) Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#UserName) Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#Password) Define_Map For(*RESULT) Class(#PRIM_DC.UnicodeString) Name(#Result) Define_Map For(*INPUT) Class(#ExternalServiceInvocationStatus) Name(#InvocationStatus) Mandatory(*NULL) Pass(*BY_REFERENCE) * Variables Define_Com Class(#XPRIM_UriBuilder) Name(#Url) Define_Com Class(#XPRIM_HttpRequest) Name(#Request) Define_Com Class(#XPRIM_RandomAccessJsonReader) Name(#Json) * Setup the URL's base properties #COM_SELF.SetupUrlBuilder Urlbuilder(#Url) * Add the 'authenticate' path component #Url.AddPathComponent Pathcomponent('authenticate') * Add the form parameters #Url.AddQueryString( 'domain' 'syd' ) #Url.AddQueryString( 'username' 'tony' ) #Url.AddQueryString( 'password' 'test' ) * Execute the HTTP request #Request.DoGet Url(#Url) * Get the authentication result #Json.SetSourceHttpResponse( #Request.Response ) #Result := #Json.ReadStringWithName( 'result' ) * Get request status If (#InvocationStatus *IsNot *Null) #InvocationStatus.FromHttpResponse( #Request.Response ) Endif Endroutine
Next: Testing the User Authenticate Service