Liberty の最適化されたローカル・アダプター API を使用した外部アドレス・スペースのサービスの呼び出し

WebSphere® Optimized Local Adapters (WOLA) API を使用して、Liberty サーバーから外部アドレス・スペースまたはサブシステムのサービスを呼び出します。

始める前に

最適化されたローカル・アダプターを使用した Liberty アプリケーションから外部アドレス・スペースのアプリケーションへの接続の説明に従って、アプリケーションを外部アドレス・スペースまたはサブシステムに接続します。

Rational® Application Developer CICS®/IMS™ Java™ Data Binding ウィザードで生成されたレコード・データを渡す場合は、まず、生成されたレコード・データを接続で使用できるようにする必要があります。詳細については、『Liberty での最適化されたローカル・アダプターのアウトバウンド接続における生成レコード・データの使用可能化』を参照してください。

手順

  1. アプリケーションで、作成した Connection オブジェクトから対話を作成します。 以下の例では、con Connection オブジェクトから対話 int を作成します。
    Interaction int = con.createInteraction();
  2. InteractionSpecImpl オブジェクトを作成して、サービス名 (外部アドレス・スペースまたはサブシステムで呼び出すメソッドの名前) を指定し、対話仕様を作成します。 サービス名は、任意要求受信、特定要求受信、またはホスト・サービス API の呼び出し時に設定した名前、あるいは顧客情報管理システム (CICS) プログラムの名前 (CICS サーバー・タスクを使用している場合) でなければなりません。 以下の例では、isi InteractionSpecImpl オブジェクトでサービス名 MYSERVICE を指定しています。
    InteractionSpecImpl isi = new InteractionSpecImpl();
    isi.setServiceName("MYSERVICE");
  3. 対話仕様を指定して対話を実行します。 以下の例では、isi 対話仕様を指定して int 対話を実行しています。データは送信していません。
    int.execute(isi, null);

以下の例では、入出力データをバイト配列 (byte[]) として指定して対話を開始する方法を示しています。
public byte[] driveInteraction(javax.resource.cci.ConnectionFactory cf,
javax.resource.cci.Connection con,byte[] inputDataBytes),throws javax.resource.ResourceException
	{
	// Create an interaction using the optimized local adapter connection
		 javax.resource.cci.Interaction i = con.createInteraction();
	// The InteractionSpec describes the service we want to call
		 com.ibm.websphere.ola.InteractionSpecImpl isi = new com.ibm.websphere.ola.InteractionSpecImpl();
		 isi.setServiceName("MYSERVICE");
	// The input data is specified using an IndexedRecord.  The first
	// slot in the indexed record contains the input data bytes.
		 javax.resource.cci.RecordFactory rf = cf.getRecordFactory();
		 javax.resource.cci.IndexedRecord ir = rf.createIndexedRecord(null);
		 ir.add(inputDataBytes);
		 		 
	// The interaction returns another IndexedRecord, whose first
	// slot contains the output data bytes.
		 javax.resource.cci.Record or = i.execute(isi, ir);
		 byte[] outputDataBytes = null;
		 		 
		 if (or != null)
		 {
		 		 outputDataBytes = (byte[])((javax.resource.cci.IndexedRecord)or).get(0);
		 }
		 		 
	// Return the output data to the caller
			return outputDataBytes;
		 }

以下の例では、Rational Application Developer によって生成されたコピーブック Record オブジェクトを使用して対話を開始する方法を示しています。

 /**
  * An example of driving an optimized local adapter interaction, using a Rational 
  * Application Developer copybook mapping class as input (inputRecord) and receiving
  * a Rational Application Developer copybook mapping as output.
	*/		 
			public javax.resource.cci.Record driveInteraction(
		 	javax.resource.cci.Connection con,
		 	javax.resource.cci.Record inputRecord)
		 	throws javax.resource.ResourceException
	  {
	// Create an interaction using the OLA connection
		 	javax.resource.cci.Interaction i = con.createInteraction();
	// The InteractionSpec describes the service we want to call com.ibm.websphere.ola.InteractionSpecImpl isi = 
		 new com.ibm.websphere.ola.InteractionSpecImpl();
		 isi.setServiceName("MYSERVICE");
	// The Rational Application Developer generated copybook implements 
	// javax.resource.cci.Record and can be passed directly to the interaction.
	// The interaction returns an IndexedRecord, whose first slot contains 
  // the output data bytes.
		 	javax.resource.cci.Record or = i.execute(isi, inputRecord);
		 	javax.resource.cci.Record outputRecord = null;
		 	if (or != null)
		 {
	// In this example, RADGeneratedOutputType is the name of the Rational Application Developer
  // generated copybook mapping class.
		 	outputRecord = new RADGeneratedOutputType();
 // The output bytes are stored in the output record returned on the
 // interaction, which is an IndexedRecord.
		 byte[] outputDataBytes = 
     (byte[])((javax.resource.cci.IndexedRecord)or).get(0);
		 		 		 
 // To convert the output bytes to another Rational Application Developer generated copybook, 
 // call the setBytes(byte[]) method of that class.  The class will 
 // implement the  com.ibm.etools.marshall.RecordBytes interface.
		 ((com.ibm.etools.marshall.RecordBytes)outputRecord)
        .setBytes(outputDataBytes);
		 }
		 		 
// Return the output data to the caller
		 		 return outputRecord;
		 }

トピックのタイプを示すアイコン タスク・トピック

ファイル名: twlp_dat_useoutboundconnection.html