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

RIGHT:[[目次>Hestia Hacks]]|[[前>2アクションPIPの回答側処理]]|[[次>ServiceContentのXMLファイルを入力して送信]]
 
 目次
 
 #contents
 
 *概要 [#g9d276f6]
 
 JMSによるEISとHestiaの接続について解説します。
 
 サンプルプログラム全体を以下に示します。
 
 【PIPSenderJMS.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.JMSMessageExchanger;
  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 PIPSenderJMS {
  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 RECEIVE_QUEUE = prop.getProperty("RECEIVE_QUEUE");
  31 :       String SEND_QUEUE = prop.getProperty("SEND_QUEUE");
  32 :       String FACTORY = prop.getProperty("FACTORY");
  33 :       String SENDER = prop.getProperty("SENDER");
  34 :       String RECEIVER = prop.getProperty("RECEIVER");
  35 :       String HANDLER_ID = prop.getProperty("HANDLER_ID");
  36 : 
  37 :       Connection connection = new Connection(HOST, USER, PASS,
  38 :           Connection.EXCHANGE_MODE_JMS, RECEIVE_QUEUE, SEND_QUEUE,
  39 :           FACTORY, HANDLER_ID);
  40 :       JMSMessageExchanger exchanger = new JMSMessageExchanger(connection,
  41 :           Configuration.getInstance());
  42 : 
  43 :       RootElement re = Repository.getDefault().getResolver()
  44 :           .resolveByVersion("0C1",
  45 :               "Pip0C1AsynchronousTestNotification", "R01.02.00");
  46 :       RootElementGenerator reg = new RootElementGenerator(re);
  47 :       reg.process();
  48 :       ServiceContent sc = new ServiceContent("0C1", re);
  49 :       sc.setGlobalDocumentFunctionCode("Request");
  50 :       sc.setDocumentGenerationDateTime(new DateTimeStamp());
  51 :       sc.setDocumentIdentifier((new UID()).toString());
  52 :       sc.setElementValue(
  53 :           "fromRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier",
  54 :               SENDER);
  55 :       sc.setElementValue(
  56 :           "toRole/PartnerRoleDescription/PartnerDescription/BusinessDescription/GlobalBusinessIdentifier",
  57 :               RECEIVER);
  58 : 
  59 :       Session session = new InitiationSession(new PayloadContainer(
  60 :           new Date(), SENDER, RECEIVER, (new UID()).toString(), sc,
  61 :           null));
  62 :       SampleUtils.printSessionState("created", session);
  63 :       PayloadContainer request = session.getMessageToSend();
  64 :       SampleUtils.printSessionState("got", session);
  65 :       SampleUtils.printContainerInformation(request);
  66 :       SampleUtils.printServiceContent(request.getServiceContent());
  67 :       new Validator(request.getServiceContent().getElement()).validate();
  68 :       exchanger.sendMessage(request);
  69 :       SampleUtils.printSessionState("sent", session);
  70 : 
  71 :       int time = 0;
  72 :       boolean loop = true;
  73 :       while (loop) {
  74 :         Thread.sleep(5000);
  75 :         exchanger.hit();
  76 :         SampleUtils.printSessionState("loop=" + time++, session);
  77 : 
  78 :         Container container = exchanger.receiveMessage();
  79 :         if (container != null) {
  80 :           SampleUtils.printContainerInformation(container);
  81 :           session.pushStatus((StatusContainer) container);
  82 :           SampleUtils.printSessionState("pushed", session);
  83 :           loop = false;
  84 :         }
  85 :       }
  86 : 
  87 :     } catch (Exception e) {
  88 :       e.printStackTrace();
  89 :     }
  90 :   }
  91 : 
  92 : }
 
 *JMSMessageExchangerの使用 [#lda1768c]
 
 JMSによる接続にはJMSMessageExchangerクラスを使用します。JMSを使用するため、 ConnectionコンストラクタにEXCHANGE_MODE_JMS を指定する必要があります。また、同コンストラクタにはハンドラIDを指定します(ここでは「EIS」)。このハンドラIDはbridgehandlers.xmlに登録されているものを指定する必要があります。
 JMSMessageExchangerはJMSによる接続を行うクラスです。また、 Connectionコンストラクタには、JMSでの接続を意味するEXCHANGE_MODE_JMSを指定します。
 
  37 :       Connection connection = new Connection(HOST, USER, PASS,
  38 :           Connection.EXCHANGE_MODE_JMS, RECEIVE_QUEUE, SEND_QUEUE,
  39 :           FACTORY, HANDLER_ID);
  40 :       JMSMessageExchanger exchanger = new JMSMessageExchanger(connection,
  41 :           Configuration.getInstance());
 
 一般的な処理の記述方法は、DirectMessageExchangerと同じです。JMSMessageExchangerとDirectMessageExchangerは共通の上位クラスMessageExchangerを持ちます。
 
 |関連クラス|機能|h
 |com.ados.hestia.sdk.Connection|Hestiaのネットワークアドレス等のプロパティのラッピング。|
 |com.ados.hestia.sdk.message.JMSMessageExchanger|HestiaとJMS接続を行う。|
 |com.ados.hestia.sdk.message.MessageExchanger|JMSMessageExchangerとDirectMessageExchangerの上位クラス。|
 
 *Hestia側ハンドラの設定 [#f5429164]
 
 Hestia側に、JMSで接続するためのハンドラを設定する必要があります。下記のように設定します。
 
 【{HestiaHOME}/server/default/data/bridgehandlers.xml】
  <handlers>
 	<handler>
 		Handler.ID=EIS
 		Handler.Priority=0
 		Communicator.Type=JMS
 		JMS.Queue.Receive=queue/hestiaIncomingQueue
 		JMS.Queue.Send=queue/hestiaOutcomingQueue
 		JMS.Factory=UIL2ConnectionFactory
 		Filter.Partner.Local=Any
 		Filter.Partner.Remote=Any
 		Filter.Pip=Any
 	</handler>
 	<handler>
 		・・・
 	</handler>
  </handlers>
 

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

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