Internal Custom Java Sender

A basic internal custom Java sender has the following characteristics:

  • The name of the custom automation package. For example:

    package com.mslv.oms.sample.atm_frame;
    
  • Import statements required for this custom automation plug-in. For example:

      import com.mslv.oms.automation.plugin.*;
      import com.mslv.oms.automation.*;
      import java.rmi.*;
    
  • An arbitrary class name that extends AbstractSendAutomator. For the automation framework to call an internal custom Java sender, the plug-in must extend the AbstractSendAutomator class. This class resides in the com.mslv.automation.plugin package. For example:

      public class MyPlugin extends AbstractSendAutomator {
    
  • The required run method, as dictated by the parent class, AbstractSendAutomator

       protected void run(String inputXML, AutomationContext context)
                       throws com.mslv.oms.automation.AutomationException {
    
  • Cast the AutomationContext object to the TaskContext object. This example assumes that the custom automation plug-in is triggered by an automated task, so the code is expecting the context input an argument to be an instance of the TaskContext object.

            TaskContext taskContext = (TaskContext)context;
    

    Note:

    You can use the TaskContext object to do many things, such as complete the task, suspend it, and so on. For more information about this class, see the OSM Javadocs.

  • Call a method on the TaskContext object to retrieve the task name.

            String taskName = taskContext.getTaskMnemonic();
    
  • Sets the text for the outbound message, which is sent to the external message queue defined by the automation definition. The custom code does not establish a connection to an external system or send the message; the automation framework handles the connection and sends the message upon completion of the makeRequest method.

            outboundMessage.setText("Received task event for task = " + taskName);}
    

    Note:

    OSM provides outboundMessage in the OSM automation framework as a JMS message with text content. If you require other message formats or protocols, do not use outboundMessage. You must implement an internal custom java automator or helper class with the required code.

The following example shows the minimal amount of code required for a custom automation plug-in that sends data to run. This example assumes that it is triggered by an automated task.

  package com.mslv.oms.sample.atm_frame;

  import com.mslv.oms.automation.plugin.*;
  import com.mslv.oms.automation.*;
  import javax.jms.TextMessage;
  import java.rmi.*;
  
  public class MyPlugin extends AbstractSendAutomator {
    protected void makeRequest(String inputXML, AutomationContext context,
                   TextMessage outboundMessage)
                   throws com.mslv.oms.automation.AutomationException {
      try {
        TaskContext taskContext = (TaskContext)context;
        String taskName = taskContext.getTaskMnemonic();

        // optional - You can use this code if you want to define your own correlation ID rather than an autogenerated correlation ID.
        Correlator correlator = getCorrelator(context);
        correlator.add(createCustomCorrelationId(taskContext));

        outboundMessage.setText("Received task event for task = " + taskName);}
      catch(javax.jms.JMSException ex) {
        throw new AutomationException(ex); }
      catch(RemoteException x) {
        throw new AutomationException(x); }
    }

    private String createCustomCorrelationId(TaskContext taskContext) {
     // Create a custom correlation ID using task name and unique order history ID
     // Actual correlation calculation depends on solution logic
        String corrId = taskContext.getTaskMnemonic() 
                        + "-" 
                        + String.valueOf(taskContext.getOrderHistoryId());
        return corrId;
    }

  }