再利用可能パーツExternalFileServices が完成したので、このテストを行います。

TestFileServicesModule という名前のサーバー・モジュールを作成し、次のコードをこのサーバー・モジュールに追加します。

 * フィールド
Define Field(#Fld_SourcePath) Type(*NVARCHAR) Length(1000)
Define Field(#Fld_TargetPath) Type(*NVARCHAR) Length(1000)
Define Field(#Fld_Message) Type(*NVARCHAR) Length(2000)

 * サーバー・ルーチン
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)

   * FileServices 再利用可能パーツのインスタンス作成
   Define_Com Class(#ExternalFileServices) Name(#Services)

   * 呼び出しステータス・オブジェクトのインスタンス作成
   Define_Com Class(#ExternalServiceInvocationStatus) Name(#Status)

   * Copy メソッドの起動
   #Services.Copy SourcePath(#Fld_SourcePath) TargetPath(#Fld_TargetPath) InvocationStatus(#Status)

   * ステータスが OK でない場合は、エラー・メッセージを取得
   If (*Not #Status.OK)
      #Fld_Message := #Status.ErrorMessage
   Endif
Endroutine


Web ページを作成して、サーバー・モジュールを呼び出します。

Evtroutine Handling(#Com_owner.Initialize)
   Define_Com Class(#TestFileServicesModule.TestFileCopy) Name(#FileCopy)
   Define_Com Class(#PRIM_DC.UnicodeString) Name(#Message)

   * サーバー・ルーチン経由で Copy サービスを起動
   * ソースとターゲット・ファイルのパスは要調整
   #FileCopy.Execute SourcePath('/home/tony/a.txt') TargetPath('/home/tony/b.txt') Message(#Message)

   * サーバー・ルーチンがエラー・メッセージを返しているか確認
   If (#Message.CurChars > 0)
      #SYS_WEB.Alert( #Message )
   Else
      #SYS_WEB.Alert( 'All good!')
   Endif
Endroutine

次は:Tomcat ジョブをバッチ・モードで開始

  • No labels