使用 Liberty 的最佳化本端配接器 API,來呼叫外部位址空間中的服務

使用 WebSphere® 最佳化本端配接器 (WOLA) API,從 Liberty 伺服器,呼叫外部位址空間或子系統上的服務。

開始之前

依照使用最佳化本端配接器,從 Liberty 應用程式連接外部位址空間中的應用程式的說明,將應用程式連接至外部位址空間或子系統。

如果您想傳遞 Rational® Application Developer CICS®/IMS™ Java™ 資料連結精靈所產生的記錄資料,您必須先啟用連線,以使用產生的記錄資料。如需相關資訊,請參閱在 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