RIGHT:[[目次>Hestia Hacks]]|[[前>本ガイドとサンプルについて]]|[[次>1アクションPIPの回答側処理]]
RIGHT:[[目次>Hestia Hacks#SDKDevDuide]]|[[前>本ガイドとサンプルについて]]|[[次>1アクションPIPの回答側処理]]
目次
#contents
*概要 [#i6e1057e]
1アクションPIPの開始側処理について解説します。
PIPの開始側ではオブジェクトが図のような連携を行います。
#ref(g01.gif,center)
PIPを開始するにはInitiationSessionを生成します。InitiationSessionはPIPプロセスのステータス情報を保持しており、StatusContainerを受け取ることにより役割を終えます。
EISとHestiaとの接続はDirectMessageExchangerを介して行います。EISとHestiaはJavaオブジェクトの形式でデータを送受信します。一方、Hestiaは、パートナーRosettaNetサーバと、RNIF仕様に基づきMIME形式にパックされたXMLデータを送受信します。
サンプルプログラム全体を以下に示します。
【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 : }
SampleUtilsは状態を標準出力するユーティリティクラスです。SampleUtilsを読み飛ばしてSDKの処理のみを理解することができます。
*RMIによる接続 [#wd97e796]
DirectMessageExchangerはRMIによる接続を行うクラスです。また、 Connectionコンストラクタには、RMIでの接続を意味するEXCHANGE_MODE_DIRECT を指定します。また、同コンストラクタにはハンドラIDを指定します。このハンドラIDはbridgehandlers.xmlに登録されているものを指定する必要があります。
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());
|関連クラス|機能|h
|com.ados.hestia.sdk.Connection|Hestiaのネットワークアドレス等のプロパティのラッピング。|
|com.ados.hestia.sdk.Configuration|SDKのコンフィギュレーションクラス。|
|com.ados.hestia.sdk.message.DirectMessageExchanger|HestiaとRMI接続を行う。|
*ServiceContentの生成 [#n5be4ae0]
PIPSender.javaでは、ServiceContentのサンプルデータを内部生成しています。ただし、実際の運用では、XMLやCSVの形式でビジネスデータをバックエンドから入力してServiceContentに構成するため、このような処理を通常行いません。
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で動的に生成して設定する必要があります。
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クラスの各設定メソッドは下記のパスに対応します。
|ServiceContentの設定メソッド|対応するXPath|入力値|h
|setGlobalDocumentFunctionCode|/*/GlobalDocumentFunctionCode|ドキュメントのタイプ('要求'または'回答')|
|setDocumentGenerationDateTime|/*/thisDocumentGenerationDateTime/DateTimeStamp|ドキュメント生成時間|
|setDocumentIdentifier|/*/thisDocumentIdentifier/ProprietaryDocumentIdentifier|ドキュメントID|
|setElementValue|任意のパスを、ルート要素の下から指定|*|
CENTER:&color(white){※};
|関連クラス|機能|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|RosettaNet形式の時間データを表すクラス。|
|com.ados.hestia.utils.UID|ユニークなIDを生成するクラス。|
*Sessionの生成 [#k23dfe24]
1つのSessionは1つのPIPプロセスを表します。SessionはPIPプロセスのステータス情報を保持するため、そのフラグを参照することによって疎通管理を行えます。
56 : Session session = new InitiationSession(new PayloadContainer(
57 : new Date(), SENDER, RECEIVER, (new UID()).toString(), sc,
58 : null));
|関連クラス|機能|h
|com.ados.hestia.sdk.session.Session|InitiationSessionの上位クラス。|
|com.ados.hestia.sdk.session.InitiationSession|自社から送信を開始(Initiation)するセッションを表すクラス。|
|com.ados.hestia.parser.rnbm.exchange.PayloadContainer|ServiceContentを保持し、Hestiaへ渡される。|
*PayloadContainerの送信 [#edf97b7e]
SessionからPayloadContainerを取り出します。それによりSessionのステータスが更新されます。
60 : PayloadContainer request = session.getMessageToSend();
メッセージの送信時にHestia側ではデータバリデーションを行わないため、EIS側でデータバリデーションを行う必要があります。なお、データバリデーションのルールは個々のPIP仕様に基づきます。
64 : new Validator(request.getServiceContent().getElement()).validate();
DirectMessageExchanger#sendMessageを呼び出してPayloadContainerを入力すると、Hestiaへの送信が待機されます。そして、DirectMessageExchanger#hitが呼び出されると、Hestiaへ送信されます。
65 : exchanger.sendMessage(request);
72 : exchanger.hit();
なお、HestiaからパートナーRosettaNetサーバへのメッセージ送信は、EISから管理できません。また、DirectMessageExchanger#hitを起動すると、1件のPIPメッセージ送信だけでなく、その時待機している全てのメッセージの送受信を行います。
|関連クラス|機能|h
|com.ados.hestia.parser.rnbm.access.Validator|データのバリデーションを行うクラス。|
*StatusContainerの受信 [#i71f86ae]
パートナーRosettaNetサーバから受信して待機しているメッセージを、DirectMessageExchanger#hitを起動して受け取ります。受信したメッセージがあると、DirectMessageExchanger#receiveMessageにより取得できます。
72 : exchanger.hit();
75 : Container container = exchanger.receiveMessage();
そして、Session#pushStatusを呼び出し、受信メッセージを入力します。それによりSessionのステータスが更新されます。
78 : session.pushStatus((StatusContainer) container);
RNIFの非同期通信においては、いつシグナルメッセージを受信するか予測できません。したがって、実際のEISプログラムにおいては、このような受信処理をループで周期的に実行させる必要があります。
|関連クラス|機能|h
|com.ados.hestia.parser.rnbm.exchange.Container|PayloadContainerおよびStatusContainerの上位クラス。|
|com.ados.hestia.parser.rnbm.exchange.StatusContainer|シグナル情報を運ぶクラス。|