使用 Liberty 优化本地适配器 API 在外部地址空间中调用服务

使用 WebSphere® 优化本地适配器 (WOLA) API 从 Liberty 服务器在外部地址空间或者子系统中调用服务。

开始之前

使用优化本地适配器从 Liberty 应用程序连接至外部地址空间中的应用程序中所述,将应用程序连接到外部地址空间或子系统。

如果您想要传递由“Rational® Application Developer CICS®/IMS™ Java™ 数据绑定”向导所生成的记录数据,那么您必须首先启用连接以使用所生成的记录数据。有关更多信息,请参阅在 Liberty 中的出站优化本地适配器连接中启用所生成的记录数据

过程

  1. 在应用程序中,创建来自您所创建的连接对象的交互。 以下示例将创建来自 con 连接对象的 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 生成的副本记录对象启动交互。

 /**
  	* 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