Sample Java application for retrieving asynchronous callout requests

To prepare a non-MDB Java™ application for inbound requests from an IMS™ application program, specify the appropriate interaction verb, the asynchronous hold queue name, and a timeout value in the Java application.

The following sample code shows an example of a Java application that is configured to receive the callout requests.

// JNDI lookup returns connFactory 
InitialContext initCntx = new InitialContext();
ConnectionFactory connFactory = 
      (ConnectionFactory) initCntx.lookup("java:comp/env/ibm/ims/IMSTarget"); 

IMSConnectionSpec connSpec = new IMSConnectionSpec();
Connection connection = connFactory.getConnection(connSpec);
Interaction interaction = connection.createInteraction(); 
IMSInteractionSpec interactionSpec = new IMSInteractionSpec(); 

//set the commit mode and sync level 
interactionSpec.setCommitMode(0); 
interactionSpec.setSyncLevel(1);

// An eight-character queue name that the asynchronous messages to be retrieved from
String calloutQueueName = new String ("CALLOUTQ");
// Set the asynchronous queue name for the callout message
interactionSpec.setAltClientID(calloutQueueName);
 
// Set interactionVerb to retrieve async output with a timeout
interactionSpec.setInteractionVerb(com.ibm.connector2.ims.ico.
IMSInteractionSpec.SYNC_RECEIVE_CALLOUT);
interactionSpec.setExecutionTimeout(3600000);

for (;;) {
      try {
            // Execute the interaction
            iteraction.execute(interactionSpec, null, calloutMsg); 

            // Further processing on the calloutMsg
            :
      } catch (Exception e) {
            // if the exception is an execution timeout error,
            // you can either do nothing and continue to loop
            // or process the error and then break the loop
            break;
      }
}

iteraction.close(); 
connection.close();

Feedback