Sample CCI application code

This sample CCI application code demonstrates how to obtain a connection and then an IMSInteraction object to execute an IMS transaction.

In a managed environment, use the CCI API to look up an IMSConnectionFactory instance from the JNDI namespace and then use it to get an IMSConnection instance.

ConnectionFactory cf = null;
if (isManaged) {
   //Use JNDI lookup to get ConnectionFactory instance 
   //Assume the connection factory has a JNDI name of MyIMS
   Context ic = new InitialContext();
   cf = (ConnectionFactory) ic.lookup("MyIMS");
 

If JNDI is not configured, a CCI application can manually configure an IMSManagedConnectionFactory object and use it to obtain a connection factory.

IMSManagedConnectionFactory mcf = new IMSManagedConnectionFactory();
mcf.setDataStoreName("MyDSName");
mcf.setHostName("myHostNm");
mcf.setPortNumber(new Integer(1234));
...
//Create connection factory from ManagedConnectionFactory
cf = (IMSConnectionFactory) mcf.createConnectionFactory();
The following example shows the use of the CCI interfaces to execute a command on an EIS.
  • Use the IMSConnectionFactory object to create an IMSConnection object.
  • Use the IMSConnection object to create an IMSInteraction object.
  • Use the IMSInteraction object to execute transactions on the backend IMS system.
  • Close the IMSInteraction and IMSConnection objects.
public void execute() {
   try {
      ConnectionFactory cf = null;
      if (isManaged) {
         //Use JNDI lookup to get ConnectionFactory instance - assumes 
         //connection factory has JNDI name of MyIMS
         Context ic = new InitialContext();
         cf = (ConnectionFactory) ic.lookup("MyIMS");
      } else {
         //Create and set values for ManagedConnectionFactory
         IMSManagedConnectionFactory mcf = new IMSManagedConnectionFactory();
         mcf.setDataStoreName("MyDSName");
         mcf.setHostName("myHostNm");
         mcf.setPortNumber(new Integer(1234));
         //Create connection factory from ManagedConnectionFactory
         cf = (IMSConnectionFactory) mcf.createConnectionFactory();
      }
      // Create an IMSConnection object
      Connection connection = cf.getConnection();

      //Create an IMSInteraction from the connection to
      //interact with IMS to run the IVTNO transaction (Phonebook)
      IMSInteraction interaction = (IMSInteraction) connection.createInteraction();
      IMSInteractionSpec ixnSpec = new IMSInteractionSpec();
      ixnSpec.setInteractionVerb(IMSInteractionSpec.SYNC_SEND_RECEIVE);

      //Create new input record 
      input = new PhoneBookInputRecordField("cp037");
      input.setIn__ll((short)59);
      input.setIn__zz((short) 0);
      input.setIn__trcd("IVTNO");
      input.setTranCodeLength(10);
      input.setIn__command("DISPLAY");
      input.setIn__name1("LAST3");
      input.setIn__name2("");
      input.setAllFieldsGiven(false);
      PhoneBookOutputRecordField

      //Create new output record 
      output = new PhoneBookOutputRecordField("cp037");

      //Execute interaction by calling the execute() method
      interaction.execute(ixnSpec, input, output);

      //Display output
      System.out.println ("Output is: ");
      System.out.println("\nMessage: "
         + output.getOut__mesg()
         + "\nName:"
         + output.getOut__name1()
         + " "
         + output.getOut__name2()
         + "\nExtension: "
         + output.getOut__extn()
         + "\nZipcode: "
         + output.getOut__zip());

   } catch (Exception e) {
      e.printStackTrace();
      } finally {
      //Close both the interaction and the connection
      interaction.close();
      connection.close();
   }
}