Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Our file copy implementation so far does the required functionality, however if something is wrong (e.g. the source file doesn't exist), it doesn't tell you what's wrong. So we are going to add the code to retrieve the error message from our Java code.

The Java code sends out a JSON object at the end of the copy operation that indicates the status of the invocation. When you are creating your own service later on, make sure that you follow the same pattern. The status consists of two values:

  • A boolean value that indicates if the service completes successfully.
  • A string value that indicates the error message if the service fails to complete.

We are going to create a reusable part called ExternalServiceInvocationStatus to represent the invocation status. You will use this reusable part in all your services.Image Removed

 Image Added 

Place the following code in the new reusable part:Function

     Function Options(*DIRECT)
Begin     Begin_Com Role(*EXTENDS #PRIM_OBJT)

     * Variables to hold the OK & ErrorMessage values

...

        Define_Com Class(#PRIM_BOLN) Name(#gOK)

...

        Define_Com Class(#PRIM_DC.UnicodeString) Name(#gErrorMessage)

...

        * Properties: OK & ErrorMessage

...

        Define_Pty Name(OK) Get(*AUTO #gOK) Set(*AUTO #gOK)

...

        Define_Pty Name(ErrorMessage) Get(*AUTO #gErrorMessage) Set(*AUTO #gErrorMessage)

...

        * Routine to read the OK status & error message from the HTTP response object

...

        Mthroutine Name(FromHttpResponse)

...

           Define_Map For(*INPUT) Class(#XPRIM_HttpResponse) Name(#HttpResponse) Pass(*BY_REFERENCE)

...

           Define_Com Class(#XPRIM_RandomAccessJsonReader) Name(#Json)

...

           * Initiaiize properties

...

           #gOK := False

...

           #gErrorMessage := ''

...

           * Check if any response…

...

           If (#HttpResponse.IsSuccessfulRequest)

...

              * Read the response JSON

...

              #Json.SetSourceHttpResponse HttpResponse(#HttpResponse)

...

              * Check if request returns OK status code

...

              If (#HttpResponse.IsSuccessHttpStatusCode)

...

                 #gOK := True

...

              Else
                 * Read error message from the JSON response

...

                 #gErrorMessage := #Json.ReadStringWithName( 'errorMessage' )

...

              Endif
           Else
              #gErrorMessage := #HttpResponse.ErrorMessage

...

           Endif
        Endroutine
     End_Com

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