[ADOS] ADOS Developer's Site - XML Stadium
ADOS Company slogan - XML Total Solution

 RIGHT:[[目次>Hestia Hacks]]|[[前>本ガイドとサンプルについて]]|[[次>1アクションPIPの回答側処理]]
 
 目次
 
 #contents
 
 *概要 [#i6e1057e]
 
 1アクションPIPの開始側処理について解説します。
 
 【PIPSender.java】
  1 : import java.io.FileInputStream;
  2 : import java.util.Date;
  3 : import java.util.Properties;
  4 : 
  5 : import com.ados.hestia.parser.rnbm.access.Validator;
  6 : import com.ados.hestia.parser.rnbm.exchange.Container;
  7 : import com.ados.hestia.parser.rnbm.exchange.PayloadContainer;
  8 : import com.ados.hestia.parser.rnbm.exchange.StatusContainer;
  9 : import com.ados.hestia.parser.rnbm.model.RootElement;
  10 : import com.ados.hestia.parser.rnbm.particle.DateTimeStamp;
  11 : import com.ados.hestia.parser.rnbm.particle.ServiceContent;
  12 : import com.ados.hestia.parser.rnbm.repository.Repository;
  13 : import com.ados.hestia.sdk.Configuration;
  14 : import com.ados.hestia.sdk.Connection;
  15 : import com.ados.hestia.sdk.message.DirectMessageExchanger;
  16 : import com.ados.hestia.sdk.rnbm.randomgenerator.RootElementGenerator;
  17 : import com.ados.hestia.sdk.session.InitiationSession;
  18 : import com.ados.hestia.sdk.session.Session;
  19 : import com.ados.hestia.utils.UID;
  20 : 
  21 : public class PIPSender {
  22 : 
  23 :   public static void main(String[] args) {
  24 :     try {
  25 :       Properties prop = new Properties();
  26 :       prop.load(new FileInputStream("sample.properties"));
  27 :       String HOST = prop.getProperty("HOST");
  28 :       String USER = prop.getProperty("USER");
  29 :       String PASS = prop.getProperty("PASS");
  30 :       String HANDLER_ID = prop.getProperty("HANDLER_ID");
  31 :       String SENDER = prop.getProperty("SENDER");
  32 :       String RECEIVER = prop.getProperty("RECEIVER");
  33 : 
  34 :       Connection connection = new Connection(HOST, USER, PASS,
  35 :           Connection.EXCHANGE_MODE_DIRECT, null, null, null,
  36 :           HANDLER_ID);
  37 :       DirectMessageExchanger exchanger = new DirectMessageExchanger(
  38 :           connection, Configuration.getInstance());
  39 : 
  40 :       RootElement re = Repository.getDefault().getResolver()
  41 :           .resolveByVersion("0C1",
  42 :               "Pip0C1AsynchronousTestNotification", "R01.01.00");
  43 :       RootElementGenerator reg = new RootElementGenerator(re);
  44 :       reg.process();
  45 :       ServiceContent sc = new ServiceContent("0C1", re);
  46 :       sc.setGlobalDocumentFunctionCode("Request");
  47 :       sc.setDocumentGenerationDateTime(new DateTimeStamp());
  48 :       sc.setDocumentIdentifier((new UID()).toString());
  49 :       sc.setElementValue(
  50 :           "fromRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier",
  51 :               SENDER);
  52 :       sc.setElementValue(
  53 :           "toRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier",
  54 :               RECEIVER);
  55 : 
  56 :       Session session = new InitiationSession(new PayloadContainer(
  57 :           new Date(), SENDER, RECEIVER, (new UID()).toString(), sc,
  58 :           null));
  59 :       SampleUtils.printSessionState("created", session);
  60 :       PayloadContainer request = session.getMessageToSend();
  61 :       SampleUtils.printSessionState("got", session);
  62 :       SampleUtils.printContainerInformation(request);
  63 :       SampleUtils.printServiceContent(request.getServiceContent());
  64 :       new Validator(request.getServiceContent().getElement()).validate();
  65 :       exchanger.sendMessage(request);
  66 :       SampleUtils.printSessionState("sent", session);
  67 : 
  68 :       int time = 0;
  69 :       boolean loop = true;
  70 :       while (loop) {
  71 :         Thread.sleep(5000);
  72 :         exchanger.hit();
  73 :         SampleUtils.printSessionState("loop=" + time++, session);
  74 : 
  75 :         Container container = exchanger.receiveMessage();
  76 :         if (container != null) {
  77 :           SampleUtils.printContainerInformation(container);
  78 :           session.pushStatus((StatusContainer) container);
  79 :           SampleUtils.printSessionState("pushed", session);
  80 :           loop = false;
  81 :         }
  82 :       }
  83 : 
  84 :     } catch (Exception e) {
  85 :       e.printStackTrace();
  86 :     }
  87 :   }
  88 : 
  89 : }
 
 
 *オブジェクトの関係 [#see246d9]
 
 PIPの開始側ではオブジェクトが図のような連携を行います。
 
 Hestiaとの疎通はDirectMessageExchangerが行います。なお、DirectMessageExchangerはRMIでHestiaと通信する場合のクラスです。JMSによって通信する場合はJMSMessageExchangerを使用します。これらはMessageExchanger型から継承されています。
 #ref(g01.gif,center)
 
 InitiationSessionオブジェクトはPIP開始側の1PIPプロセスを表します。
 PIPを開始するにはInitiationSessionを生成します。InitiationSessionはPIPプロセスのステータス情報を保持しており、StatusContainerを受け取ることにより役割を終えます。
 
 EISとHestiaとの接続はDirectMessageExchangerを介して行います。EISとHestiaはJavaオブジェクトの形式でデータを送受信します。一方、Hestiaは、パートナーRossetaNetサーバと、RNIF仕様に基づきMIME形式にパックされたXMLデータを送受信します。
 
 *RMIによる接続 [#wd97e796]
 
 RMIによる接続にはDirectMessageExchangerクラスを使用します。RMIを使用するため、 ConnectionコンストラクタにEXCHANGE_MODE_DIRECT を指定する必要があります。また、同コンストラクタにはハンドラIDを指定します(ここでは「EIS」)。このハンドラIDはbridgehandlers.xmlに登録されているものを指定する必要があります。
 DirectMessageExchangerはRMIによる接続を行うクラスです。また、 Connectionコンストラクタには、RMIでの接続を意味するEXCHANGE_MODE_DIRECT を指定します。また、同コンストラクタにはハンドラIDを指定します。このハンドラIDはbridgehandlers.xmlに登録されているものを指定する必要があります。
 
 String host = "localhost";
 String user = null;
 String password = null;
 int exchangeMode = Connection.EXCHANGE_MODE_DIRECT;
 String handlerid = "EIS";
 Connection connection = new Connection(host, user, password,exchangeMode, null, null, null, handlerid);
 DirectMessageExchanger exchanger = new DirectMessageExchanger(connection, Configuration.getInstance());
  34 :       Connection connection = new Connection(HOST, USER, PASS,
  35 :           Connection.EXCHANGE_MODE_DIRECT, null, null, null,
  36 :           HANDLER_ID);
  37 :       DirectMessageExchanger exchanger = new DirectMessageExchanger(
  38 :           connection, Configuration.getInstance());
 
 
 関連クラス
 機能
 com.ados.hestia.sdk.Connection
 Hestiaのネットワークアドレス等をパッケージしたオブジェクト。
 com.ados.hestia.sdk.Configuration
 |関連クラス|機能|h
 |com.ados.hestia.sdk.Connection|Hestiaのネットワークアドレス等をパッケージしたオブジェクト。|
 |com.ados.hestia.sdk.Configuration|SDKのコンフィギュレーションクラス|
 |com.ados.hestia.sdk.message.DirectMessageExchanger|HestiaとRMI接続を行う。|
 
 com.ados.hestia.sdk.message.DirectMessageExchanger
 RMI接続を行う。
 
 *ServiceContentの生成 [#n5be4ae0]
 
 ここでは、ServiceContentのサンプルデータを内部生成しています。通常、バックエンドから入力されたXMLやCSVから、ServiceContentを生成します。しかし、ビジネスデータ以外のドキュメントIDやドキュメント生成時間などの疎通管理情報は入力データに含まれないことも多いため、EISで動的に設定するケースがあります。
 PIPSender.javaでは、ServiceContentのサンプルデータを内部生成しています。ただし、実際の運用では、XMLやCSVの形式でビジネスデータをバックエンドから入力してServiceContentに構成するため、このような処理を通常行いません。
 
 RootElement re = Repository.getDefault().getResolver().resolveByVersion("0C1","Pip0C1AsynchronousTestNotification", "R01.02.00");
 RootElementGenerator reg = new RootElementGenerator(re);
 reg.process();
 ServiceContent sc = new ServiceContent("0C1", re);
 sc.setGlobalDocumentFunctionCode("Request");
 DateTimeStamp d1 = new DateTimeStamp();
 String uid1 = (new UID()).toString();
 sc.setDocumentGenerationDateTime(d1);
 sc.setDocumentIdentifier(uid1);
 sc.setElementValue("fromRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier","111111111");
 sc.setElementValue("toRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier","987654321");
  40 :       RootElement re = Repository.getDefault().getResolver()
  41 :           .resolveByVersion("0C1",
  42 :               "Pip0C1AsynchronousTestNotification", "R01.01.00");
  43 :       RootElementGenerator reg = new RootElementGenerator(re);
  44 :       reg.process();
  45 :       ServiceContent sc = new ServiceContent("0C1", re);
 
 一方、ビジネスデータ以外のドキュメントIDやドキュメント生成時間などが入力データに含まれない場合は、下記のようにEISで動的に生成して設定する必要があります。
 
 ServiceContentの設定メソッド
 対応するXPath
 setGlobalDocumentFunctionCode
 /*/GlobalDocumentFunctionCode
 setDocumentGenerationDateTime
 /*/thisDocumentGenerationDateTime/DateTimeStamp
 setDocumentIdentifier
 /*/thisDocumentIdentifier/ProprietaryDocumentIdentifier
 setElementValue
 任意のパスを、ルート要素の下から指定
  46 :       sc.setGlobalDocumentFunctionCode("Request");
  47 :       sc.setDocumentGenerationDateTime(new DateTimeStamp());
  48 :       sc.setDocumentIdentifier((new UID()).toString());
  49 :       sc.setElementValue(
  50 :           "fromRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier",
  51 :               SENDER);
  52 :       sc.setElementValue(
  53 :           "toRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier",
  54 :               RECEIVER);
 
 なお、ServiceContentクラスの各設定メソッドは下記のパスに対応します。
 
 関連クラス
 機能
 com.ados.hestia.parser.rnbm.particle.ServiceContent
 ServiceContentを表すクラス。
 com.ados.hestia.parser.rnbm.particle.DateTimeStamp
 RossetaNet形式の時間データを表すクラス。
 com.ados.hestia.utils.UID
 ユニークなIDを生成するクラス。
 |ServiceContentの設定メソッド|対応するXPath|入力値|h
 |setGlobalDocumentFunctionCode|/*/GlobalDocumentFunctionCode|ドキュメントのタイプ('要求'または'回答')|
 |setDocumentGenerationDateTime|/*/thisDocumentGenerationDateTime/DateTimeStamp|ドキュメント生成時間|
 |setDocumentIdentifier|/*/thisDocumentIdentifier/ProprietaryDocumentIdentifier|ドキュメントID|
 |setElementValue|任意のパスを、ルート要素の下から指定|*|
 
 CENTER:*
 
 |関連クラス|機能|h
 |com.ados.hestia.parser.rnbm.model.RootElement|ServiceContentのルート要素の抽象クラス|
 |com.ados.hestia.sdk.rnbm.randomgenerator.RootElementGenerator|ルート要素を生成するクラス|
 |com.ados.hestia.parser.rnbm.repository.Repository||
 |com.ados.hestia.parser.rnbm.particle.ServiceContent|ServiceContentを表すクラス|
 |com.ados.hestia.parser.rnbm.particle.DateTimeStamp|RossetaNet形式の時間データを表すクラス。|
 |com.ados.hestia.utils.UID|ユニークなIDを生成するクラス。|
 
 *セッションの生成 [#k23dfe24]
 
 一つのセッションオブジェクトはPIPの一組のプロセスを表します。具体的には、1アクションPIPの場合は、アクション-シグナルの2メッセージの送受信を表します。2アクションPIPの場合は、アクション-シグナル-アクション-シグナルの4メッセージの送受信を表します。セッションはPIPの進行状態の情報を保持し、そのフラグを参照することによって疎通管理を行えます。
 1つのセッションオブジェクトはPIPの一組のプロセスを表します。具体的には、1アクションPIPの場合は、アクション-シグナルの2メッセージの送受信を表します。2アクションPIPの場合は、アクション-シグナル-アクション-シグナルの4メッセージの送受信を表します。セッションはPIPの進行状態の情報を保持し、そのフラグを参照することによって疎通管理を行えます。
 
 Date d2 = new Date();
 String uid2 = (new UID()).toString();
 Session session = new InitiationSession(new PayloadContainer(d2, "111111111","987654321", uid2, sc, null));
  56 :       Session session = new InitiationSession(new PayloadContainer(
  57 :           new Date(), SENDER, RECEIVER, (new UID()).toString(), sc,
  58 :           null));
 
 |関連クラス|機能|h
 |com.ados.hestia.sdk.session.InitiationSession|自社から送信を開始(Initiation)するセッションを表すクラス。|
 |com.ados.hestia.sdk.session.Session|InitiationSessionの上位クラス。|
 
 関連クラス
 機能
 com.ados.hestia.utils.UID
 ユニークなIDを生成するクラス。
 com.ados.hestia.parser.rnbm.exchange.PayloadContainer
 ServiceContentを保持し、Hestiaへ渡されるオブジェクト。
 com.ados.hestia.sdk.session.InitiationSession
 com.ados.hestia.sdk.session.Session
 セッションクラス。InitiationSessionは、自社から送信を開始(Initiation)するセッションを表す。
 
 
 *PIPメッセージの送信 [#edf97b7e]
 
 PIPメッセージを送信する前に、ハンドラ側でデータバリデーションを行う必要があります。Hestia側では送信時にデータバリデーションを行いません。
 
 PayloadContainer request = session.getMessageToSend();
 new Validator(request.getServiceContent().getElement()).validate();
  60 :       PayloadContainer request = session.getMessageToSend();
 
  64 :       new Validator(request.getServiceContent().getElement()).validate();
 
 sendMessageメソッドを呼び出してPayloadContainerを入力すると、Hestiaへの送信が待機されます。そして、hitメソッドが呼び出されると、Hestiaへ送信されます。Hestiaからパートナーへのメッセージ送信は、ハンドラから管理できません。また、hitメソッドは、1件のPIPメッセージ送信だけでなく、送信待機された全てのメッセージ送信と、Hestiaから渡されたすべてのメッセージ受信を行います。
 
 exchanger.sendMessage(request);
 exchanger.hit();
  65 :       exchanger.sendMessage(request);
 
  72 :         exchanger.hit();
 
 関連クラス
 機能
 com.ados.hestia.parser.rnbm.access.Validator
 データのバリデーションを行うクラス。
 
 |関連クラス|機能|h
 |com.ados.hestia.parser.rnbm.exchange.PayloadContainer|ServiceContentを保持し、Hestiaへ渡されるオブジェクト。|
 |com.ados.hestia.parser.rnbm.access.Validator|データのバリデーションを行うクラス。|
 
 *シグナルの受信 [#i71f86ae]
 
 前述のようにhitメソッドは待機中の全てのメッセージ送受信を行います。そこでメッセージが受信されれば、receiveMessageメソッドにより取得できます。そして、pushStatusメソッドを呼び出し、受信メッセージを入力します。
 
 なお、pushStatusメソッドで入力するメッセージは、セッションの一部である必要があります。したがって、*によりIDが一致するか確認します。
 
 また、シグナルメッセージの受信を待機するため、受信処理をループで周期的に実行させる必要があります。
 
 exchanger.hit();
 Container container = exchanger.receiveMessage();
 session.pushStatus((StatusContainer) container);
  72 :         exchanger.hit();
 
  75 :         Container container = exchanger.receiveMessage();
 
  78 :           session.pushStatus((StatusContainer) container);
 

トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

Copyright 2005-2008. ADOS Co., Ltd. All Rights Reserved.