ページの先頭行へ戻る
Interstage Business Application Server アプリケーション開発ガイド
FUJITSU Software

9.2.8 クライアントアプリケーションの作成例

クライアントアプリケーションの作成例を以下に示します。

■文字列型を使用した作成例

クライアントアプリケーションで文字列データを扱う場合、“java.lang.String”型を使用してください。
文字列型を使用する場合のクライアントアプリケーションの例を示します。

定義例

サーバアプリケーションがC言語の場合

実行基盤インタフェース生成ツールを使用して、Javaソースを生成する場合のIDLファイルとアプリケーション情報入力ファイルを以下に示します。

IDLファイル

module apfw_mod {
    interface apfw_intf {
        long sampleOp01(in string p1,inout wstring p2,out string p3);
    };
};

アプリケーション情報入力ファイル

<?xml version="1.0" encoding="UTF-8"?>
<apfw-app>
    <server>
        <target name="apl" />
        <library name="libserverapl.so" />
    </server>
    <client>
        <comment>C:\dev\app_def\src_comment\comment.txt</comment>
        <bean>
            <package>samplepkg</package>
        </bean>
    </client>
</apfw-app>
サーバアプリケーションがCOBOLの場合

COBOL開発支援ツールを使用してJavaソースを生成する場合の入力情報を、以下に示します。

クライアントプリケーションの作成例

beanを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import samplepkg.sampleOp01Bean;

class SampleClient1
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のsamplepkg.sampleOp01Beanを生成
            sampleOp01Bean request = new sampleOp01Bean();
            // INパラメタp1を設定
            request.setP1("param1-IN");
            // INOUTパラメタp2を設定
            request.setP2("パラメタ2-インアウト");
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:11111");
            // サーバアプリケーションの呼出し
            sampleOp01Bean response = (sampleOp01Bean)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = response.getApfw_result();
                // INOUTパラメタp2を参照
                String inout = response.getP2();
                // OUTパラメタp3を参照
                String out = response.getP3();
                System.out.println("response-data(RETURN) : "+result);
                if( inout != null )
                {
                    System.out.println("response-data(INOUT) : "+inout);
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out != null )
                {
                    System.out.println("response-data(OUT) : "+out);
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
    }
}
Mapを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import java.util.HashMap;

class SampleClient1
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のjava.util.HashMapを生成
            HashMap<String, Object> request = new HashMap<String, Object>();
            // INパラメタp1を設定
            request.put("p1", "param1-IN");
            // INOUTパラメタp2を設定
            request.put("p2", "パラメタ2-インアウト");
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:11111");
            // サーバアプリケーションの呼出し
            HashMap response = (HashMap)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = (String)response.get("apfw_result");
                // INOUTパラメタp2を参照
                String inout = (String)response.get("p2");
                // OUTパラメタp3を参照
                String out = (String)response.get("p3");
                System.out.println("response-data(RETURN) : "+result);
                if( inout != null )
                {
                    System.out.println("response-data(INOUT) : "+inout);
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out != null )
                {
                    System.out.println("response-data(OUT) : "+out);
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
    }
}

■class型を使用した作成例

classを使用する場合のクライアントアプリケーションの例を示します。

定義例

サーバアプリケーションがC言語の場合

classを扱う場合には、IDLファイルに構造体型を定義します。
実行基盤インタフェース生成ツールを使用して、Javaソースを生成する場合のIDLファイルとアプリケーション情報入力ファイルを以下に示します。

IDLファイル

struct PARAM1STR {
    string mem11;
    wstring mem12;
};

struct PARAM2STR {
    string mem21;
    wstring mem22;
};

struct PARAM3STR {
    string mem31;
    wstring mem32;
};

module apfw_mod {
    interface apfw_intf {
        long sampleOp02(in PARAM1STR P1,inout PARAM2STR P2,out PARAM3STR P3);
    };
};

アプリケーション情報入力ファイル

<?xml version="1.0" encoding="UTF-8"?>
<apfw-app>
    <server>
        <target name="apl" />
        <library name="libserverapl.so" />
    </server>
    <client>
        <comment>C:\dev\app_def\src_comment\comment.txt</comment>
        <bean>
            <package>samplepkg</package>
        </bean>
    </client>
</apfw-app>
サーバアプリケーションがCOBOLの場合

COBOL開発支援ツールを使用してJavaソースを生成する場合の入力情報を、以下に示します。

クライアントプリケーションの作成例

beanを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import samplepkg.sampleOp02Bean;
import samplepkg.PARAM1STR;
import samplepkg.PARAM2STR;
import samplepkg.PARAM3STR;

class SampleClient2
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のsamplepkg.sampleOp02Beanを生成
            sampleOp02Bean request = new sampleOp02Bean();
            PARAM1STR p1str = new PARAM1STR("param1-IN", "パラメタ1-イン");
            PARAM2STR p2str = new PARAM2STR("param2-INOUT", "パラメタ2-インアウト");
            // INパラメタp1を設定
            request.setP1(p1str);
            // INOUTパラメタp2を設定
            request.setP2(p2str);
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:22222");
            // サーバアプリケーションの呼出し
            sampleOp02Bean response = (sampleOp02Bean)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = response.getApfw_result();
                // INOUTパラメタp2を参照
                PARAM2STR inout = response.getP2();
                // OUTパラメタp3を参照
                PARAM3STR out = response.getP3();
                System.out.println("response-data(RETURN): "+result);
                if( inout != null )
                {
                    if( inout.mem21 != null )
                    {
                        System.out.println("response-data(INOUT) : mem21 : "+inout.mem21);
                    }
                    else
                    {
                        System.out.println("response-data(INOUT) : mem21 : null");
                    }
                    if( inout.mem22 != null )
                    {
                        System.out.println("response-data(INOUT) : mem22 : "+inout.mem22);
                    }
                    else
                    {
                        System.out.println("response-data(INOUT) : mem22 : null");
                    }
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out != null )
                {
                    if( out.mem31 != null )
                    {
                        System.out.println("response-data(OUT) : mem31 : "+out.mem31);
                    }
                    else
                    {
                        System.out.println("response-data(OUT) : mem31 : null");
                    }
                    if( out.mem32 != null )
                    {
                        System.out.println("response-data(OUT) : mem32 : "+out.mem32);
                    }
                    else
                    {
                        System.out.println("response-data(OUT) : mem32 : null");
                    }
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
    }
}
Mapを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import java.util.HashMap;
import java.util.Map;

class SampleClient2
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のjava.util.HashMapを生成
            HashMap<String, Object> request = new HashMap<String, Object>();
            HashMap<String, Object> p1str = new HashMap<String, Object>();
            p1str.put("mem11", "param1-IN");
            p1str.put("mem12", "パラメタ1-イン");
            HashMap<String, Object> p2str = new HashMap<String, Object>();
            p2str.put("mem21", "param2-INOUT");
            p2str.put("mem22",  "パラメタ2-インアウト");
            // INパラメタP1を設定
            request.put("P1", p1str);
            // INOUTパラメタP2を設定
            request.put("P2", p2str);

            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:22222");
            // サーバアプリケーションの呼出し
            HashMap response = (HashMap)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = ((Integer)response.get("apfw_result")).intValue();
                // INOUTパラメタp2を参照
                Map inout = (Map)response.get("P2");
                // OUTパラメタp3を参照
                Map out = (Map)response.get("P3");
                System.out.println("response-data(RETURN) : " + result);
                if( inout != null )
                {
                    if( inout.get("mem21") != null )
                    {
                        System.out.println("response-data(INOUT) : mem21 : "+inout.get("mem21"));
                    }
                    else
                    {
                        System.out.println("response-data(INOUT) : mem21 : null");
                    }
                    if( inout.get("mem22") != null )
                    {
                        System.out.println("response-data(INOUT) : mem22 : "+inout.get("mem22"));
                    }
                    else
                    {
                        System.out.println("response-data(INOUT) : mem22 : null");
                    }
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out != null )
                {
                    if( out.get("mem31") != null )
                    {
                        System.out.println("response-data(OUT) : mem31 : "+out.get("mem31"));
                    }
                    else
                    {
                        System.out.println("response-data(OUT) : mem31 : null");
                    }
                    if( out.get("mem32") != null )
                    {
                        System.out.println("response-data(OUT) : mem32 : "+out.get("mem32"));
                    }
                    else
                    {
                        System.out.println("response-data(OUT) : mem32 : null");
                    }
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
    }
}

■配列型を使用した作成例

配列型を使用する場合のクライアントアプリケーションの例を示します。

定義例

サーバアプリケーションがC言語の場合

実行基盤インタフェース生成ツールを使用して、Javaソースを生成する場合のIDLファイルとアプリケーション情報入力ファイルを以下に示します。

IDLファイル

struct P1ARRAY {
    string p1array_val[3];
};
struct P2ARRAY {
    wstring p2array_val[2];
};
struct P3ARRAY {
    string p3array_val[5];
};

module apfw_mod {
    interface apfw_intf {
        long sampleOp03(in P1ARRAY p1array,inout P2ARRAY p2array,out P3ARRAY p3array);
    };
};

アプリケーション情報入力ファイル

<?xml version="1.0" encoding="UTF-8"?>
<apfw-app>
    <server>
        <target name="apl" />
        <library name="libserverapl.so" />
    </server>
    <client>
        <comment>C:\dev\app_def\src_comment\comment.txt</comment>
        <bean>
            <package>samplepkg</package>
        </bean>
    </client>
</apfw-app>
サーバアプリケーションがCOBOLの場合

COBOL開発支援ツールを使用してJavaソースを生成する場合の入力情報を、以下に示します。

クライアントプリケーションの作成例

beanを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import samplepkg.sampleOp03Bean;
import samplepkg.P1ARRAY;
import samplepkg.P2ARRAY;
import samplepkg.P3ARRAY;

class SampleClient3
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のsamplepkg.sampleOp03Beanを生成
            sampleOp03Bean request = new sampleOp03Bean();
            String[] p1array_val = new String[3];
            String[] p2array_val = new String[2];
            for( int i = 0; i < p1array_val.length; i++)
            {
                p1array_val[i] = new String("param1-IN");
            }
            for( int i = 0; i < p2array_val.length; i++)
            {
                p2array_val[i] = new String("パラメタ2-インアウト");
            }
            P1ARRAY p1array = new P1ARRAY( p1array_val );
            P2ARRAY p2array = new P2ARRAY( p2array_val );
            // INパラメタP1ARRAYを設定
            request.setP1array(p1array);
            // INOUTパラメタP2ARRAYを設定
            request.setP2array(p2array);
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:33333");
            // サーバアプリケーションの呼出し
            sampleOp03Bean response = (sampleOp03Bean)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = response.getApfw_result();
                // INOUTパラメタP2ARRAYを参照
                P2ARRAY inout = response.getP2array();
                // OUTパラメタP3ARRAYを参照
                P3ARRAY out = response.getP3array();
                System.out.println("response-data(RETURN) : " + result);

                String[] inout_val = inout.p2array_val;
                String[] out_val = out.p3array_val;

                if( inout_val != null )
                {
                    for( int i = 0; i < inout_val.length; i++)
                    {
                        if( inout_val[i] != null )
                        {
                            System.out.println("response-data(INOUT) : ["+i+"] : "+inout_val[i]);

                        }
                        else
                        {
                            System.out.println("response-data(INOUT) : ["+i+"] : null");
                        }
                    }
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out_val != null )
                {
                    for( int i = 0; i < out_val.length; i++)
                    {
                        if( out_val[i] != null )
                        {
                            System.out.println("response-data(OUT) : ["+i+"] : "+out_val[i]);
                        }
                        else
                        {
                            System.out.println("response-data(OUT) : ["+i+"] : null");
                        }
                    }
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
    }
}

備考.IDLファイルに定義した配列の長さが超過または不足した場合は、例外が発生します。

Mapを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import java.util.HashMap;
import java.util.Map;

class SampleClient3
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のjava.util.HashMapを生成
            HashMap<String, Object> request = new HashMap<String, Object>();
            // パラメタp1array / p2array設定用のjava.util.HashMapを生成
            HashMap<String, Object> in = new HashMap<String, Object>();
            HashMap<String, Object> inout = new HashMap<String, Object>();

            // パラメタp1array / p2arrayに設定する配列を定義する
            String[] inarray = new String[3];
            String[] inoutarray = new String[2];
            for( int i = 0; i < inarray.length; i++)
            {
                inarray[i] = new String("param1-IN");
            }
            for( int i = 0; i < inoutarray.length; i++)
            {
                inoutarray[i] = new String("パラメタ2-インアウト");
            }
            // パラメタp1array / p2arrayに配列データを設定する
            in.put("p1array_val", inarray );
            inout.put("p2array_val", inoutarray );

            // INパラメタp1を設定
            request.put("p1array", in);
            // INOUTパラメタp2を設定
            request.put("p2array", inout);
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:33333");
            // サーバアプリケーションの呼出し
            HashMap<String, Object> response = (HashMap<String, Object>)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = ((Integer)response.get("apfw_result")).intValue();
                // INOUTパラメタp2arrayを参照
                Map inout_ret = (Map)response.get("p2array");
                // OUTパラメタp3arrayを参照
                Map out = (Map)response.get("p3array");

                // p2arrayの配列データを参照
                String[] inoutarray_ret = (String[])inout_ret.get("p2array_val");
                // p3arrayの配列データを参照
                String[] outarray = (String[])out.get("p3array_val");

                System.out.println("response-data(RETURN) : " + result);

                if( inoutarray_ret != null )
                {
                    for( int i = 0; i < inoutarray_ret.length; i++)
                    {
                        if( inoutarray_ret[i] != null )
                        {
                            System.out.println("response-data(INOUT) : ["+i+"] : "+inoutarray_ret[i]);

                        }
                        else
                        {
                            System.out.println("response-data(INOUT) : ["+i+"] : null");
                        }
                    }
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( outarray != null )
                {
                    for( int i = 0; i < outarray.length; i++)
                    {
                        if( outarray[i] != null )
                        {
                            System.out.println("response-data(OUT) : ["+i+"] : "+outarray[i]);
                        }
                        else
                        {
                            System.out.println("response-data(OUT) : ["+i+"] : null");
                        }
                    }
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
    }
}

備考.IDLファイルに定義した配列の長さが超過または不足した場合は、例外が発生します。

■バイナリデータを使用した作成例

バイナリを定義したIDLファイルとアプリケーション情報入力ファイルを使用して、Javaソースを生成した場合のクライアントアプリケーションの例を示します。

定義例

サーバアプリケーションがC言語の場合

実行基盤インタフェース生成ツールを使用して、Javaソースを生成する場合のIDLファイルとアプリケーション情報入力ファイルを以下に示します。

IDLファイル

typedef sequence<octet> PARAM1BIN;
typedef sequence<octet> PARAM2BIN;
typedef sequence<octet> PARAM3BIN;

module apfw_mod {
    interface apfw_intf {
        long sampleOp04 (
            in PARAM1BIN param1bin,
            inout PARAM2BIN param2bin,
            out PARAM3BIN param3bin
        );
    };
};

アプリケーション情報入力ファイル

<?xml version="1.0" encoding="UTF-8"?>
<apfw-app>
    <server>
        <target name="apl" />
        <library name="libserverapl.so" />
    </server>
    <client>
        <comment>C:\dev\app_def\src_comment\comment.txt</comment>
        <bean>
            <package>samplepkg</package>
        </bean>
    </client>
</apfw-app>
サーバアプリケーションがCOBOLの場合

COBOL開発支援ツールを使用してJavaソースを生成する場合の入力情報を、以下に示します。

クライアントプリケーションの作成例

beanを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import samplepkg.sampleOp04Bean;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

class SampleClient4
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のsamplepkg.sampleOp04Beanを生成
            sampleOp04Bean request = new sampleOp04Bean();
            int length = 0;
            File f = new File("sample4-1.txt");
            length = (int)f.length();
            byte[] p1so = new byte[length];
            FileInputStream fis = new FileInputStream(f);
            fis.read(p1so);
            fis.close();
            f = new File("sample4-2.jpg");
            length = (int)f.length();
            byte[] p2so = new byte[length];
            fis = new FileInputStream(f);
            fis.read(p2so);
            fis.close();
            // INパラメタp1を設定
            request.setParam1bin(p1so);
            // INOUTパラメタp2を設定
            request.setParam2bin(p2so);
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:44444");
            // サーバアプリケーションの呼出し
            sampleOp04Bean response = (sampleOp04Bean)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = response.getApfw_result();
                // INOUTパラメタp2を参照
                byte[] inout = response.getParam2bin();
                // OUTパラメタp3を参照
                byte[] out = response.getParam3bin();
                FileOutputStream fos = null;
                System.out.println("response-data(RETURN) : " + result);
                if( inout != null )
                {
                    f = new File("inout.bmp");
                    fos = new FileOutputStream(f);
                    fos.write(result);
                    fos.close();
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out != null )
                {
                    f = new File("outt.jpg");
                    fos = new FileOutputStream(f);
                    fos.write(result);
                    fos.close();
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
        // ファイル操作で発生した例外
        catch(IOException ie)
        {
            ie.printStackTrace();
        }
    }
}
Mapを使用した場合
import com.fujitsu.interstage.apfw.conv.ApfwDataConversionException;
import com.fujitsu.interstage.apfw.msync.ApfwInvokeException;
import java.rmi.RemoteException;
import com.fujitsu.interstage.apfw.scnt.ApfwSystemException;
import com.fujitsu.interstage.apfw.scnt.ApfwUserException;
import com.fujitsu.interstage.apfw.msync.MsyncCall;
import java.util.HashMap;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

class SampleClient4
{
    public static void main(String[] args)
    {
        try
        {
            // パラメタ設定用のjava.util.HashMapを生成
            HashMap<String, Object> request = new HashMap<String, Object>();
            int length = 0;
            File f = new File("sample4-1.txt");
            length = (int)f.length();
            byte[] p1so = new byte[length];
            FileInputStream fis = new FileInputStream(f);
            fis.read(p1so);
            fis.close();
            f = new File("sample4-2.jpg");
            length = (int)f.length();
            byte[] p2so = new byte[length];
            fis = new FileInputStream(f);
            fis.read(p2so);
            fis.close();
            // INパラメタparam1binを設定
            request.put("param1bin", p1so);
            // INOUTパラメタparam2binを設定
            request.put("param2bin", p2so);
            // MsyncCallの作成
            MsyncCall call = new MsyncCall("MyApp");
            // コンテキストIDの設定
            call.setContextId("id:44444");
            // サーバアプリケーションの呼出し
            HashMap<String, Object> response = (HashMap<String, Object>)call.invokeMsync(request,"apl");
            // removeメソッドの呼出し
            call.remove();
            if( response != null )
            {
                // サーバアプリケーションの結果(復帰値)を参照
                int result = ((Integer)response.get("apfw_result")).intValue();
                // INOUTパラメタparam2binを参照
                byte[] inout = (byte[])response.get("param2bin");
                // OUTパラメタparam3binを参照
                byte[] out = (byte[])response.get("param3bin");
                FileOutputStream fos = null;
                System.out.println("response-data(RETURN) : " + result);
                if( inout != null )
                {
                    f = new File("inout.bmp");
                    fos = new FileOutputStream(f);
                    fos.write(result);
                    fos.close();
                }
                else
                {
                    System.out.println("response-data(INOUT) : null");
                }
                if( out != null )
                {
                    f = new File("outt.jpg");
                    fos = new FileOutputStream(f);
                    fos.write(result);
                    fos.close();
                }
                else
                {
                    System.out.println("response-data(OUT) : null");
                }
            }
        }
        // 変換中の例外など
        catch(ApfwDataConversionException adce)
        {
            adce.printStackTrace();
        }
        // API内部の例外
        catch(ApfwInvokeException aie)
        {
            aie.printStackTrace();
        }
        // 通信中の例外
        catch(RemoteException re)
        {
            re.printStackTrace();
        }
        // 同期アプリケーション連携実行基盤で発生した例外
        catch(ApfwSystemException ase)
        {
            ase.printStackTrace();
        }
        // サーバアプリケーションで発生した例外
        catch(ApfwUserException aue)
        {
            aue.printStackTrace();
        }
        // ファイル操作で発生した例外
        catch(IOException ie)
        {
            ie.printStackTrace();
        }
    }
}

■パラメタを省略する場合の作成例

以下のデータ型について、クライアントアプリケーションからサーバアプリケーションへ送信するデータを省略することができます。

beanのインスタンスを作成したときに、これらのデータ型に該当するbeanのプロパティには初期値としてnullが設定されます。クライアントアプリケーションから明示的にnullを指定しなくても、省略データとして扱われます。
サーバアプリケーションから受信したデータで設定されていない場合も同様に、beanのプロパティにnullが設定されます。

以下に判別方法を示します。ここでは、以下の条件で例を記述しています。

    ;
    // サーバアプリケーションの結果(復帰値)を参照
    String result = response.getApfw_result();
    // 第1OUTパラメタp1を参照
    PARAM1STR out1 = response.getP1();
    // 第2OUTパラメタp2を参照
    String[] out2 = response.getP2();
    // 第3OUTパラメタp3を参照
    byte[] out3 = response.getP3();
    // 受信したデータが設定されている
    if( result != null )
    {
        System.out.println("response-data(RETURN) : exists");
        System.out.println("response-data(RETURN) : "+result);
    }
    // 受信したデータが設定されていない
    else
    {
        System.out.println("response-data(RETURN) : null");
    }
    // 受信したデータが設定されている
    if( out1 != null )
    {
        System.out.println("response-data(OUT1) : exists");
        System.out.println("response-data(OUT1) : "+out1);
        // 受信したclass内のデータが設定されている
        if( out1 != null )
        {
            System.out.println("response-data(OUT1:MEM1) : exists");
            System.out.println("response-data(OUT1.MEM1) : "+out1.MEM1);
        }
        // 受信したclass内のデータが設定されていない
        else
        {
            System.out.println("response-data(OUT1:MEM1) : null);
        }
    }
    // 受信したデータが設定されていない
    else
    {
        System.out.println("response-data(OUT1) : null");
    }
    // 受信したデータが設定されている
    if( out2 != null )
    {
        System.out.println("response-data(OUT2) : exists");
        System.out.println("response-data(OUT2) : "+out2);
        for( int i = 0; i < out2.length; i++ )
        {
            // 受信した配列内のデータが設定されている
            if( out2[i] != null )
            {
                System.out.println("response-data(OUT2["+i+"]) : exists");
                System.out.println("response-data(OUT2["+i+"]) : "+out2[i]);
            }
            // 受信した配列内のデータが設定されていない
            else
            {
                System.out.println("response-data(OUT2["+i+"]) : null");
            }
        }
    }
    // 受信したデータが設定されていない
    else
    {
        System.out.println("response-data(OUT2) : null");
    }
    // 受信したデータが設定されている
    if( out3 != null )
    {
        System.out.println("response-data(OUT3) : exists");
        File f = new File("OUT3.txt");
        FileOutputStream fos = new FileOutputStream();
        fos.write(out3);
        fos.close();
    }
    // 受信したデータが設定されていない
    else
    {
        System.out.println("response-data(OUT3) : null");
    }
    ;