Versions Compared

Key

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

[ Image Removed |../../index.htm#lansa/webserviceseng01_0260.htm]
You are here:

...

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:

...

  • 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
    [ Image Removed |../../index.htm#lansa/webserviceseng01_0260.htm]