You are here: Web Services > Consuming Web Services > Tutorial 2 - Executing Java Code via Web Services > Adjusting the FileServices' Copy Method to Read Invocation Status in HTTP Response

Adjusting the FileServices' Copy Method to Read Invocation Status in HTTP Response

Add a parameter called InvocationStatus in the Copy 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.DoPost:

* Get the request status

If (#InvocationStatus *IsNot *Null)

   #InvocationStatus.FromHttpResponse( #Request.Response )

Endif

The complete source code of the Copy method after the adjustments (new lines are highlighted in yellow):

Mthroutine Name(Copy)

   * Parameters

   Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#SourcePath)

   Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#TargetPath)

   Define_Map For(*INPUT) Class(#ExternalServiceInvocationStatus) Name(#InvocationStatus) Pass(*BY_REFERENCE) Mandatory(*NULL)

   * Variables

   Define_Com Class(#XPRIM_UriBuilder) Name(#Url)

   Define_Com Class(#XPRIM_HttpRequest) Name(#Request)

   * Setup the URL's base properties

   #COM_SELF.SetupUrlBuilder Urlbuilder(#Url)

   * Add the 'copy' path component

   #Url.AddPathComponent Pathcomponent('copy')

   * Add the form parameters

   #Request.Content.AddUrlEncodedFormValue Name('sourcePath') Value(#SourcePath)

   #Request.Content.AddUrlEncodedFormValue Name('targetPath') Value(#TargetPath)

   * Execute the HTTP request

   #Request.DoPost Url(#Url)

   * Get the request status

   If (#InvocationStatus *IsNot *Null)

      #InvocationStatus.FromHttpResponse( #Request.Response )

   Endif

Endroutine

Next: Testing the Copy Service