Examples of Handling Responses from External Systems
In Message Property Correlation, the following steps describe how responses from external systems are handled.
-
The plug-in populates the message content.
-
The plug-in sets a property on the outbound JMS message, with name of the value set for correlationproperty in the automationMap.xml file, and a value decided by the business logic. For example, you could use this to correlate on a reference number.
-
If the value of the correlationproperty in the automationMap.xml file is set to the value JMSCorrelationID, the plug-in is not required to set the property on the outbound message (as described in Step 2). The automation framework does this automatically.
-
The automation framework saves the message properties set for each message with the event information.
-
The automation framework sets the replyTo property on the JMS message.
-
The external system copies the properties on the request message to the response message.
-
The external system sends the message to the reply queue specified in the automationMap.xml file.
-
The automation framework uses the configuration in the automationMap.xml file to map messages from external systems to plug-ins. The plug-ins are automators written by system integrators. Configuration of an automator for receiving messages from an external system are defined within Design Studio and saved to the automationMap.xml file.
-
The automation framework uses the message properties of the response, plus the correlation information saved in step four above, to reload a Context for the response message.
-
The run method of the external system automator is called and is passed the Context created in step 9.
-
The automator performs business logic, such as completing the task.
The following example shows a custom automation plug-in that handles and processes response messages from an external system.
package com.mslv.oms.sample.atm_frame; import com.mslv.oms.automation.plugin.*; import com.mslv.oms.automation.*; import java.rmi.*; public class UIMResponseHandler extends AbstractAutomator { public void run( String inputXML, AutomationContext task) throws AutomationException { try { TaskContext tctx = (TaskContext)task; tctx.completeTaskOnExit( "success" ); } catch(RemoteException ex){ throw new AutomationException( ex ); } catch(AutomationException x ) { throw x; } } }
This automation plug-in does not need to send JMS messages to any system, so it extends AbstractAutomator and is intended to process Task automation responses, so it casts the Context to a TaskContext then completes the task.
The following example shows what the external system is expected to do for the message property correlation to work.
public void sendMessage(Message originalMessage) { try { // // Set up the JMS connections // QueueConnectionFactory connectionFactory = (QueueConnectionFactory)jndiCtx.lookup(connectionFactoryName); QueueConnection queueConnection = connectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue replyQueue = (Queue)originalMessage.getJMSReplyTo(); QueueSender queueSender = queueSession.createSender(replyQueue); // // Create the message // TextMessage textMessage = queueSession.createTextMessage(((TextMessage)originalMessage).getText()); textMessage.setStringProperty("MESSAGE_NAME","ActivationResponse"); textMessage.setJMSCorrelationID(originalMessage.getJMSCorrelationID()); // // Send the message // queueSender.send(textMessage, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, 1800000); } catch(javax.jms.JMSException ex){ ex.printStackTrace(); } catch(javax.naming.NamingException ex){ ex.printStackTrace(); } }
The following code snippets from this example show:
-
how the external system chooses which JMS destination to send the reply to.
Queue replyQueue = (Queue)originalMessage.getJMSReplyTo(); QueueSender queueSender = queueSession.createSender(replyQueue);
-
the external system setting a property that identifies the nature of the JMS message. This implies that the automation was defined with a message property selector select statement that matches these parameters.
textMessage.setStringProperty("MESSAGE_NAME","ActivationResponse");
-
the external system echoing the correlation information onto the reply message. This implies that the automation was defined to correlate based on JMSCorrelationID.
textMessage.setJMSCorrelationID(originalMessage.getJMSCorrelationID());