You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Now you have completed your ExternalFileServices reusable part, it's time to test it.
Create a server module called TestFileServicesModule and add the following code to the server module:

  • Fields
    Define Field(#Fld_SourcePath) Type(*NVARCHAR) Length(1000)
    Define Field(#Fld_TargetPath) Type(*NVARCHAR) Length(1000)
    Define Field(#Fld_Message) Type(*NVARCHAR) Length(2000)
  • Server routine
    Srvroutine Name(TestFileCopy)
       Field_Map For(*INPUT) Field(#Fld_SourcePath) Parameter_Name(SourcePath)
       Field_Map For(*INPUT) Field(#Fld_TargetPath) Parameter_Name(TargetPath)
       Field_Map For(*OUTPUT) Field(#Fld_Message) Parameter_Name(Message)
       * Create an instance of the FileServices reusable part
       Define_Com Class(#ExternalFileServices) Name(#Services)
       * Create an instance of the invocation status object
       Define_Com Class(#ExternalServiceInvocationStatus) Name(#Status)
       * Invoke the Copy method
       #Services.Copy SourcePath(#Fld_SourcePath) TargetPath(#Fld_TargetPath) InvocationStatus(#Status)
       * If not OK status, get the error message
       If (*Not #Status.OK)
          #Fld_Message := #Status.ErrorMessage
       Endif
    Endroutine
    Create a webpage to invoke your server module:
    Evtroutine Handling(#Com_owner.Initialize)
       Define_Com Class(#TestFileServicesModule.TestFileCopy) Name(#FileCopy)
       Define_Com Class(#PRIM_DC.UnicodeString) Name(#Message)
       * Invoke the copy service via the server routine
       * Adjust the source & target file paths
       #FileCopy.Execute SourcePath('/home/tony/a.txt') TargetPath('/home/tony/b.txt') Message(#Message)
       * Check if the server routine returns any error message
       If (#Message.CurChars > 0)
          #SYS_WEB.Alert( #Message )
       Else
          #SYS_WEB.Alert( 'All good!' )
       Endif
    Endroutine
    Next: Starting up Tomcat Job in Batch Mode
  • No labels