Sample non-MDB Java application for retrieving and processing synchronous callout requests

To prepare a Java™ application for inbound requests from an IMS™ application program, specify the appropriate interaction verb, the tpipe name, and the timeout value in the Java application.

// 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(IMSInteractionSpec.COMMIT_THEN_SEND); 
interactionSpec.setSyncLevel(IMSInteractionSpec.SYNC_LEVEL_CONFIRM);

// An 8-character name of the OTMA asynchronous hold queue that the 
// messages are to be retrieved from
String calloutQueueName = new String (“CALLOUTQ”);
// Set the queue name for the callout message
interactionSpec.setAltClientID(calloutQueueName);
 
// Set InteractionVerb for retrieving callout request with a timeout value
interactionSpec.setInteractionVerb(IMSInteractionSpec.SYNC_RECEIVE_CALLOUT);
// Specify to retrieve only synchronous callout request messages
interactionSpec.setCalloutRequestType(IMSInteractionSpec.CALLOUT_REQUEST_SYNC); 
interactionSpec.setExecutionTimeout(5000);


// Execute the interaction
iteraction.execute(interactionSpec, null, calloutRequestMsg); 

// Get correlation token
byte[] corrToken = interactionSpec.getSyncCalloutCorrelationToken();

// Further processing on the request (calloutRequestMsg)
:

// Send back the response (calloutRespondMsg) by using the SYNC_SEND interaction
interactionSpec.setInteractionVerb(com.ibm.connector2.ims.ico.IMSInteractionSpec.SYNC_SEND);
// SYNC_SEND does not support alternate client ID
interactionSpec.setAltClientID(null);  
interactionSpec.setSyncCalloutCorrelationToken(corrToken);

// Execute the interaction
iteraction.execute(interactionSpec, calloutRespondMsg, null); 

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

For a complete code sample, right-click here and select Save Link As (in FireFox) or Save Target As (in Microsoft Internet Explorer) to download the Java sample file.