ページの先頭行へ戻る
Interstage Service Integrator V9.5.0 アプリケーション開発ガイド
FUJITSU Software

D.8.1 ESIAPISendTest.java(送信処理)

共通APIを使用した送信処理のサービス利用側アプリケーションのサンプルプログラムです。

        :
        :
public class ESIAPISendTest {

        public static void main(String[] args) throws ESIAPIException {
                // (1) サービスエンドポイント名の指定
                String strEndpoint = "inboundtest";
                if (args.length >= 1) {
                        strEndpoint = args[0];
                }
                try {
                        System.out.println("java.home=" + System.getProperty("java.home"));

                        // (2) Serviceクラスの生成
                        ESIService es = ESIServiceFactory.getService(strEndpoint);

                        // (3) 共通メッセージの生成
                        ESIMessage msg = new ESIMessage();

                        // (4) ペイロードの設定
                        msg.getPayload().getBytePayload().setObject("<name>test-payload</name>".getBytes());

                        // (5) ヘッダの設定
                        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
                        msg.getHeader().getParameter().put("user.createdate", sdf1.format(new Date()));
                        // (6) 送信APIの呼出し
                        ESIMessage retMessage = es.send(msg);

                        // (7) ペイロードの取り出し
                        byte[] bytePayload = retMessage.getPayload().getBytePayload().getObject();
                        if (bytePayload != null) {
                                String byteString = new String(bytePayload);
                                System.out.println("objectPayload=[" + byteString + "]");
                        }

                        // (8) ヘッダの取り出し
                        System.out.println("Status=" + retMessage.getHeader().getParameter().get("com.fujitsu.esi.status"));
                        System.out.println("Errorcode=" + retMessage.getHeader().getParameter().get("com.fujitsu.esi.error.code"));
                        System.out.println("stepname=" + retMessage.getHeader().getParameter().get("com.fujitsu.esi.error.stepname"));
                        System.out.println("methodtype=" + retMessage.getHeader().getParameter().get("com.fujitsu.esi.error.methodtype"));
                        System.out.println("user.result=" + retMessage.getHeader().getParameter().get("result"));
                        :
                        :
                } catch (ESIAPIException e) {
                        e.printStackTrace();
                }
        }
        :
        :
}
  1. サービスエンドポイント名の設定
    サービスエンドポイント名“inboundtest”を設定します。
    サービスエンドポイント定義で指定するサービスエンドポイント名と一致させます。

    サービスエンドポイント定義:<INSDIR>\sample\App\def\endpoint.xml

    サービスエンドポイント定義/opt/FJSVesi/sample/App/def/endpoint.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <EndpointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="esi-endpoint.xsd">
        <Endpoint name="inboundtest" sync="true"> ………サービスエンドポイント名
            <Description>Sync Send Endpoint</Description>
            <SequenceName>calctest</SequenceName>
        </Endpoint>
            :

    ポイント

    サービスエンドポイント定義の設定により、同期処理で送信するか、非同期処理で送信するかが決まります。

  2. Serviceクラスの作成
    サービスエンドポイント名をもとに、送信のServiceクラスを作成します。

  3. 共通メッセージの作成
    共通メッセージを作成します。共通メッセージ操作APIを使用します。

  4. ペイロードの設定
    ペイロードに作業用のデータとして“<name>test-payload</name>”を設定します。

  5. ヘッダの設定
    共通メッセージのヘッダに作業用のデータとしてキー:“user.createdate”、値:“<現在日時>”を設定します。

  6. 送信APIの呼出し
    共通メッセージを設定して、メッセージ送受信API“ESIService#send()”を呼び出します。

  7. ペイロードの取出し
    共通メッセージの中から、ペイロードを取り出します。

  8. ヘッダの取出し
    共通メッセージの中から、ヘッダパラメタキー名と値を取り出します。
    サンプルプログラムは、共通メッセージのヘッダのすべてのパラメタキー名と値を取り出すように作成されています。