Utilisation des API des adaptateurs locaux optimisés Liberty pour l'appel des services dans un espace adresse externe

Utilisez les API WebSphere Optimized Local Adapters (WOLA) pour appeler des services dans un espace adresse externe ou un sous-système depuis un serveur Liberty.

Avant de commencer

Connectez l'application à un espace adresse externe ou un sous-système comme décrit dans Utilisation des adaptateurs locaux optimisés pour la connexion à une application dans un espace adresse externe depuis une application Liberty.

Si vous voulez transmettre des données d'enregistrement qui sont générées par l'assistant de liaison de données Java™ CICS/IMS de Rational Application Developer, vous devez d'abord permettre à la connexion d'utiliser les données d'enregistrement générées. Pour plus d'informations, voir Activation des données d'enregistrement générées sur des connexions d'adaptateur local optimisé dans Liberty

Procédure

  1. Dans l'application, créez une interaction depuis l'objet de connexion que vous avez créé. L'exemple suivant crée l'interaction int depuis l'objet de connexion con :
    Interaction int = con.createInteraction();
  2. Create an interaction specification by creating an InteractionSpecImpl object and providing the service name, which is the name of the method that you want to call in the external address space or subsystem. The service name must be the name that you set when you called the Receive Request Any, Receive Request Specific, or Host Service APIs, or, if you are using a Customer Information Control System (CICS) server task, the name of the CICS program. The following example provides the MYSERVICE service name on the isi InteractionSpecImpl object:
    InteractionSpecImpl isi = new InteractionSpecImpl();
    isi.setServiceName("MYSERVICE");
  3. Exécutez l'interaction avec la spécification d'interaction. L'exemple suivant exécute l'interaction int avec la spécification d'interaction isi et n'envoie pas de données :
    int.execute(isi, null);

Exemple

L'exemple suivant explique comment démarrer une interaction avec des données d'entrée et de sortie sous forme de tableau d'octets (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;
		 }

L'exemple suivant explique comment démarrer une interaction avec un objet d'enregistrement de fichier de stockage généré par 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;
		 }

Icône indiquant le type de rubrique Rubrique Tâche

Nom du fichier : twlp_dat_useoutboundconnection.html