[ADOS] ADOS Developer's Site - XML Stadium
ADOS Company slogan - XML Total Solution
RIGHT:[[目次>Hestia Hacks]]|[[前>ServiceContentのXMLファイルを入力して送信]]|[[次>XMLファイルを入力してServiceContentに変換し、送信]]

目次

#contents

*概要 [#o19d3b9f]

ServiceContentをXMLファイルに出力する方法について解説します。

サンプルプログラム全体を以下に示します。

【PIPReceiverXML.java】
 1 : import java.io.BufferedWriter;
 2 : import java.io.File;
 3 : import java.io.FileInputStream;
 4 : import java.io.FileWriter;
 5 : import java.io.Writer;
 6 : import java.util.Properties;
 7 : 
 8 : import com.ados.hestia.parser.rnbm.exchange.Container;
 9 : import com.ados.hestia.parser.rnbm.exchange.PayloadContainer;
 10 : import com.ados.hestia.parser.rnbm.exchange.StatusContainer;
 11 : import com.ados.hestia.parser.rnbm.particle.ServiceContent;
 12 : import com.ados.hestia.sdk.Configuration;
 13 : import com.ados.hestia.sdk.Connection;
 14 : import com.ados.hestia.sdk.message.DirectMessageExchanger;
 15 : import com.ados.hestia.sdk.session.RespondSession;
 16 : import com.ados.hestia.sdk.session.Session;
 17 : 
 18 : public class PIPReceiverXML {
 19 : 
 20 :   public static void main(String[] args) {
 21 :     try {
 22 :       Properties prop = new Properties();
 23 :       prop.load(new FileInputStream("sample.properties"));
 24 :       String HOST = prop.getProperty("HOST");
 25 :       String USER = prop.getProperty("USER");
 26 :       String PASS = prop.getProperty("PASS");
 27 :       String HANDLER_ID = prop.getProperty("HANDLER_ID");
 28 :       String DIR = System.getProperty("user.dir") + File.separator
 29 :           + "output" + File.separator + "xml";
 30 : 
 31 :       Connection connection = new Connection(HOST, USER, PASS,
 32 :           Connection.EXCHANGE_MODE_DIRECT, null, null, null,
 33 :           HANDLER_ID);
 34 :       DirectMessageExchanger exchanger = new DirectMessageExchanger(
 35 :           connection, Configuration.getInstance());
 36 : 
 37 :       new File(DIR).mkdirs();
 38 :       int time = 0;
 39 :       boolean loop = true;
 40 :       while (loop) {
 41 :         Thread.sleep(5000);
 42 :         SampleUtils.println("loop : " + time++);
 43 :         exchanger.hit();
 44 : 
 45 :         Container container = exchanger.receiveMessage();
 46 :         if (container != null) {
 47 :           SampleUtils.printContainerInformation(container);
 48 :           PayloadContainer request = (PayloadContainer) container;
 49 :           ServiceContent sc = request.getServiceContent();
 50 :           SampleUtils.printServiceContent(sc);
 51 :           Session session = new RespondSession(request
 52 :               .getRemotePartner(), request.getPIPID());
 53 :           SampleUtils.printSessionState("created", session);
 54 :           session.pushMessage(request);
 55 :           SampleUtils.printSessionState("pushed", session);
 56 :           session.acceptPartnerMessage();
 57 :           SampleUtils.printSessionState("accepted", session);
 58 :           StatusContainer status = session.getStatusToSend();
 59 :           SampleUtils.printSessionState("sent status", session);
 60 :           SampleUtils.printContainerInformation(status);
 61 :           exchanger.sendMessage(status);
 62 :           exchanger.hit();
 63 : 
 64 :           String filename = DIR
 65 :               + File.separator
 66 :               + sc.getPIPID()
 67 :               + "_"
 68 :               + sc.getVersion()
 69 :               + "_"
 70 :               + sc.getFromRole()
 71 :                   .getGlobalBusinessIdentifierNorm()
 72 :               + "_"
 73 :               + sc.getDocumentGenerationDateTime()
 74 :                   .getRNDateTime() + "_"
 75 :               + sc.getDocumentIdentifier()
 76 :               + "_ServiceContent.xml";
 77 :           SampleUtils.println(filename);
 78 :           Writer o = new BufferedWriter(new FileWriter(new File(
 79 :               filename)));
 80 :           sc.writeXML(o, false, false);
 81 :           o.flush();
 82 :           o.close();
 83 : 
 84 :           loop = false;
 85 :         }
 86 :       }
 87 : 
 88 :     } catch (Exception e) {
 89 :       e.printStackTrace();
 90 :     }
 91 :   }
 92 : 
 93 : }

*受信したPayloadContainerからServiceContentの取得 [#xdcaa211]

受信したPayloadContainerからは、ServiceContentを取得できます。

 45 :         Container container = exchanger.receiveMessage();

 48 :           PayloadContainer request = (PayloadContainer) container;
 49 :           ServiceContent sc = request.getServiceContent();

*XMLファイルへのServiceContentの出力 [#d705f5ac]

ServiceContent#writeXMLによりWriterにServiceContentのXMLを出力します。したがって、ファイルだけでなく、Writerを実装した任意のリソースにXMLを出力できます。

 78 :           Writer o = new BufferedWriter(new FileWriter(new File(
 79 :               filename)));
 80 :           sc.writeXML(o, false, false);
 81 :           o.flush();
 82 :           o.close();

なお、ServiceContentには、PIPインスタンスID(1つのPIPプロセスにつけられるID)や本番/テストのフラグなどの情報が含まれません。したがって、バックエンドにはServiceContentと別途、これらの情報を必要に応じて通知します。


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

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