home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Java / Java.zip / mqaoad21.zip / MQAOAdapterHelper.java < prev    next >
Text File  |  2003-01-13  |  64KB  |  1,644 lines

  1. package com.ibm.extricity.adapters.mqseries.mqak;
  2.  
  3. /**
  4.  * MQAOAdapterHelper.java 1.0   10/6/2000
  5.  *
  6.  * This class is used to perform the Extricity MQAK Adapter functions
  7.  *
  8.  * OCO Source Materials
  9.  *
  10.  * 5799-RNK
  11.  *
  12.  * (C) Copyright IBM Corp. 2000
  13.  *
  14.  * The source code for this program is not published
  15.  * or otherwise divested of its trade secrets,
  16.  * irrespective of what has been deposited with the
  17.  * U. S. Copyright Office.
  18.  *
  19.  * @author Thomas W. Jaworski
  20. **/
  21.  
  22. import java.util.*;
  23.  
  24. import com.extricity.adapter.api.*;
  25. import com.extricity.document.api.*;
  26.  
  27. import com.extricity.engine.mgr.runtime.priv.PrivateProcessID;
  28. import CRStation.defs.machine.ProcessID;
  29.  
  30. import com.ibm.epic.adapters.eak.mcs.*;
  31. import com.ibm.epic.adapters.eak.nativeadapter.*;
  32. import com.ibm.epic.adapters.eak.common.AdapterException;
  33.  
  34. import com.ibm.epic.LogTrace.*;
  35.  
  36. import javax.mail.internet.*;import javax.mail.*;import com.ibm.misc.*;import javax.naming.directory.*;import javax.naming.*;import com.ibm.dk.NTF.psg.PSGCCEncryption;public class MQAOAdapterHelper
  37.         extends com.extricity.ibm.process.ProcessCompletionNotification
  38.         implements MQAOAdapterHelperInt, Runnable {
  39.         private String gatewayComp = "GATEWAY";
  40.         private String destComp = "BFM";
  41.         private String protAndVer = "UNKNOWN";
  42.         private String msgBodyCategory = "DEFAULT";
  43.  
  44.         protected static boolean _DEBUG = true;
  45.  
  46.         protected boolean expCommit = true;
  47.  
  48.         // State connection
  49.         //private EpicNativeAdapter stateENA = null;
  50.  
  51.         // Connection pool
  52.         private Vector poolENA = new Vector();
  53.  
  54.         // Process locked connections
  55.         private Hashtable lockedENA = new Hashtable();
  56.  
  57.         private boolean isFirst = true;
  58.  
  59.         // Event list
  60.         private Vector termEvents = new Vector();
  61.  
  62. /**
  63.  * MQAOAdapterHelper constructor.
  64.  */
  65. public MQAOAdapterHelper()
  66. {
  67.    super();
  68. }
  69.  
  70. /**
  71.  * Insert the method's description here.
  72.  * Creation date: (11/20/00 6:10:43 PM)
  73.  * @param processID CRStation.defs.machine.ProcessID
  74.  */
  75. public void addEvent(String processID)
  76. {
  77.    try
  78.    {
  79.           ProcessData pd = (ProcessData)executeGetProcessData(processID);
  80.           if(pd.getBOCorrelationID() != null)
  81.           {
  82.                  synchronized(termEvents)
  83.                  {
  84.                         termEvents.add(processID);
  85.                  }
  86.                  if(_DEBUG)
  87.                  {
  88.                         System.out.println("  addEvent Completion Event Added ProcessID="+processID+
  89.                                                  " ProcessData="+pd.toString());
  90.                  }
  91.           }
  92.           else if(_DEBUG)
  93.           {
  94.                  System.out.println("  addEvent Process Not Found ProcessID="+processID);
  95.           }
  96.    }
  97.    catch(ISException e)
  98.    {
  99.           System.out.println("  addEvent received exception: "+e.toString());
  100.    }
  101. }
  102.  
  103. /**
  104.  * Check for process start message.
  105.  * Creation date: (10/6/00 3:11:27 PM)
  106.  * @param context com.extricity.adapter.api.EventContext
  107.  * @exception com.extricity.adapter.api.ISException The exception description.
  108.  */
  109. public void checkForEvents(EventContext context)
  110.    throws com.extricity.adapter.api.ISException
  111. {
  112.    if(_DEBUG)
  113.    {
  114.           System.out.println("checkForEvents");
  115.    }
  116.    // Make sure that processes get to re-start first before we start checking for new process start messages
  117.    if(isFirst)
  118.    {
  119.           isFirst = false;
  120.           if(_DEBUG)
  121.           {
  122.                  System.out.println("  checkForEvents SKIPPED");
  123.           }
  124.           return;
  125.    }
  126.  
  127.    EpicNativeAdapter theENA = getEpicNativeAdapter("ProcessID=DSIPATCHER");
  128.    ENAService theENAServ = new ENAService();
  129.    theENAServ.setApplicationName(gatewayComp);
  130.    theENAServ.setBodyCategory(msgBodyCategory);
  131.    theENAServ.setBodyType("DEFAULT");
  132.    EpicMessageExt theEM;
  133.  
  134.    // Peek a message for a specific process
  135.    theENAServ.setPeekOnly(true);
  136.    theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.NO_EXTRICITYPROCESSID);
  137.    //theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,"Wed Oct 25 10:41:51 EDT ");
  138.    theENAServ.setTimout(0);
  139.    try
  140.    {
  141.           theENA.begin();
  142.           theEM = (EpicMessageExt)theENA.receiveMsg(theENAServ);
  143.    }
  144.    catch(AdapterException e)
  145.    {
  146.           // Return the ENA to pool
  147.           retEpicNativeAdapter(theENA);
  148.  
  149.           logException("ProcessID=DSIPATCHER","Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  150.           throw new ISException(e.toString());
  151.    }
  152.    if(theEM != null)
  153.    {
  154.           if(_DEBUG)
  155.           {
  156.                  System.out.println("  checkForEvents: theEM(MsgID="+theEM.getLMSMessageID()+"): " + theEM.toString());
  157.           }
  158.           context.addVariantEvent(MQAOAdapterImp.EVENT_PIP_START, theEM.getLMSMessageID(), "IBM Extricity MQAK Adapter");
  159.    }
  160.    else if(_DEBUG)
  161.    {
  162.           System.out.println("  checkForEvents: NO-EVENT-MESSAGE");
  163.    }
  164.    synchronized(termEvents)
  165.    {
  166.           while(!termEvents.isEmpty())
  167.           {
  168.                  String eventProcessId = (String)termEvents.remove(0);
  169.                  context.addVariantEvent(MQAOAdapterImp.EVENT_PROCESS_END, eventProcessId, "IBM Extricity MQAK Adapter");
  170.                  if(_DEBUG)
  171.                  {
  172.                         System.out.println("  checkForEvents: Process Complete Event ProcessId="+eventProcessId);
  173.                  }
  174.           }
  175.    }
  176.    // Return the ENA to pool
  177.    retEpicNativeAdapter(theENA);
  178. }
  179.  
  180.  
  181.  
  182. /**
  183.  * Insert the method's description here.
  184.  * Creation date: (10/16/00 4:38:19 PM)
  185.  * @param processID String - Extricity public process id
  186.  * @param i_commitcontext com.extricity.document.api.Element
  187.  * @param o_opstatus com.extricity.document.api.Element
  188.  * @exception com.extricity.adapter.api.ISException The exception description.
  189.  */
  190. public void executeCommit(String processID, String i_commitcontext, Element o_opstatus)
  191.    throws com.extricity.adapter.api.ISException
  192. {
  193.    EpicNativeAdapter theENA = null;
  194.  
  195.    if(_DEBUG)
  196.    {
  197.           System.out.println("executeCommit:\n  processID="+processID+"\n  i_commitcontext="+i_commitcontext+"");
  198.    }
  199.    // Check if it is a send
  200.    if(i_commitcontext.startsWith("_COMMIT_"))
  201.    {
  202.           // Get a native adapter
  203.           theENA = getEpicNativeAdapter(processID);
  204.           // Find the message on the _STATE_ queue based on the commit context and remove it
  205.           ENAService theENAServ = new ENAService();
  206.           theENAServ.setApplicationName(internalAppId);
  207.           theENAServ.setBodyCategory("_STATE_");
  208.           theENAServ.setBodyType("_STATE_");
  209.           // Receive a message for a specific Correlation ID
  210.           theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.encodeLMSCorrelationID(i_commitcontext));
  211.           theENAServ.setTimout(0);
  212.           // Do the receive
  213.           try
  214.           {
  215.                  theENA.begin();
  216.                  if(theENA.receiveMsg(theENAServ) == null)
  217.                  {
  218.                         if(_DEBUG)
  219.                         {
  220.                            System.out.println("  executeCommit (SEND) NO-MESSAGE-MEETING-CRITERIA");
  221.                         }
  222.                  }
  223.           }
  224.           catch(AdapterException e)
  225.           {
  226.                  // Return the ENA to pool
  227.                  retEpicNativeAdapter(theENA);
  228.  
  229.                  logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  230.                  throw new ISException(e.toString());
  231.           }
  232.    }
  233.    // It's a receive
  234.    else
  235.    {
  236.           // Detect re-start
  237.           theENA = restEpicNativeAdapter(processID);
  238.           if(theENA == null)
  239.           {
  240.                  // Get an ENA to work with
  241.                  theENA = getEpicNativeAdapter(processID);
  242.                  // Find the message on the queue based on the commit context and remove it
  243.                  ENAService theENAServ = new ENAService(gatewayComp,msgBodyCategory,"DEFAULT");
  244.                  // Receive a message for a specific LMS Message ID
  245.                  theENAServ.addFilter(theENAServ.FILTERNAME_LMS_MESSAGE_ID,i_commitcontext);
  246.                  theENAServ.setTimout(0);
  247.                  // Do the receive
  248.                  try
  249.                  {
  250.                         theENA.begin();
  251.                         if(theENA.receiveMsg(theENAServ) != null)
  252.                         {
  253.                            if(_DEBUG)
  254.                            {
  255.                                   System.out.println("  executeCommit (RECV) DUPLICATE-MESSAGE-DELETED");
  256.                            }
  257.                         }
  258.                  }
  259.                  catch(AdapterException e)
  260.                  {
  261.                         // Return the ENA to pool
  262.                         retEpicNativeAdapter(theENA);
  263.  
  264.                         logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  265.                         throw new ISException(e.toString());
  266.                  }
  267.           }
  268.    }
  269.    // Do the commit
  270.    commit(processID,theENA);
  271.  
  272.    // Return the ENA to pool
  273.    retEpicNativeAdapter(theENA);
  274. }
  275.  
  276. /**
  277.  * Insert the method's description here.
  278.  * Creation date: (11/6/00 2:12:19 PM)
  279.  * @return com.ibm.extricity.adapters.mqseries.mqak.ProcessData
  280.  * @param processID java.lang.String
  281.  */
  282. public void executeDelProcessData(String processID)
  283.    throws com.extricity.adapter.api.ISException
  284. {
  285.    EpicNativeAdapter theENA = getEpicNativeAdapter(processID);
  286.    ENAService theENAServ = new ENAService();
  287.    theENAServ.setApplicationName(internalAppId);
  288.    theENAServ.setBodyCategory("_STATE_");
  289.    theENAServ.setBodyType("_STATE_");
  290.    EpicMessageExt theEM;
  291.  
  292.    if(_DEBUG)
  293.    {
  294.           System.out.println("executeDelProcessData:\n  processID="+processID);
  295.    }
  296.    // Receive a message for a specific process
  297.    theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.encodeLMSCorrelationID(processID));
  298.    theENAServ.setTimout(0);
  299.    // Do the remove
  300.    try
  301.    {
  302.           theENA.begin();
  303.           theEM = (EpicMessageExt)theENA.receiveMsg(theENAServ);
  304.           theENA.commit();
  305.           if(_DEBUG && (theEM == null))
  306.           {
  307.                  System.out.println("  executeDelProcessData NO-MESSAGE-MEETING-CRITERIA");
  308.           }
  309.    }
  310.    catch(AdapterException e)
  311.    {
  312.           // Return the ENA to pool
  313.           retEpicNativeAdapter(theENA);
  314.  
  315.           logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  316.           throw new ISException(e.toString());
  317.    }
  318.    // Return the ENA to pool
  319.    retEpicNativeAdapter(theENA);
  320. }
  321.  
  322. /**
  323.  * Insert the method's description here.
  324.  * Creation date: (11/6/00 2:12:19 PM)
  325.  * @return com.ibm.extricity.adapters.mqseries.mqak.ProcessData
  326.  * @param processID java.lang.String
  327.  */
  328. public ProcessDataInt executeGetProcessData(String processID)
  329.    throws com.extricity.adapter.api.ISException
  330. {
  331.    EpicNativeAdapter theENA = getEpicNativeAdapter(processID);
  332.    ENAService theENAServ = new ENAService();
  333.    theENAServ.setApplicationName(internalAppId);
  334.    theENAServ.setBodyCategory("_STATE_");
  335.    theENAServ.setBodyType("_STATE_");
  336.    EpicMessageExt theEM;
  337.    ProcessData pd = new ProcessData();
  338.  
  339.    if(_DEBUG)
  340.    {
  341.           System.out.println("executeGetProcessData:\n  processID="+processID);
  342.    }
  343.    // Peek a message for a specific process
  344.    theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.encodeLMSCorrelationID(processID));
  345.    theENAServ.setPeekOnly(true);
  346.    theENAServ.setTimout(0);
  347.    // Do the peek
  348.    try
  349.    {
  350.           theEM = (EpicMessageExt)theENA.receiveMsg(theENAServ);
  351.           if(theEM == null)
  352.           {
  353.                  if(_DEBUG)
  354.                  {
  355.                         System.out.println("  executeDelProcessData NO-MESSAGE-MEETING-CRITERIA");
  356.                  }
  357.           }
  358.           else
  359.           {
  360.                  pd.setBOCorrelationID(theEM.getBOCorrelationID());
  361.                  pd.setTradingPartner(theEM.getDstTradingPartnerID());
  362.                  if(_DEBUG)
  363.                  {
  364.                         System.out.println("  executeGetProcessData ProcessData="+pd.toString());
  365.                  }
  366.           }
  367.    }
  368.    catch(AdapterException e)
  369.    {
  370.           // Return the ENA to pool
  371.           retEpicNativeAdapter(theENA);
  372.  
  373.           logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  374.           throw new ISException(e.toString());
  375.    }
  376.  
  377.    // Return the ENA to pool
  378.    retEpicNativeAdapter(theENA);
  379.  
  380.    return pd;
  381. }
  382.  
  383. /**
  384.  * Insert the method's description here.
  385.  * Creation date: (10/25/00 9:51:13 AM)
  386.  * @return java.lang.String
  387.  * @param prvProcID java.lang.String
  388.  */
  389. public String executeGetPublicProcessID(String prvProcIDStr, Element o_opstatus)
  390.    throws com.extricity.adapter.api.ISException
  391. {
  392.    PrivateProcessID prvProcID = new PrivateProcessID();
  393.    try
  394.    {
  395.           prvProcID.fromString(prvProcIDStr);
  396.    }
  397.    catch(Throwable e)
  398.    {
  399.           logException("ProcessID=UNKONWN","Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  400.           throw new ISException(e.toString());
  401.    }
  402.    if(_DEBUG)
  403.    {
  404.           System.out.println("executeGetPublicProcessID:  PubProcessId="+prvProcID.getPublicProcessID().toString());
  405.    }
  406.    //System.out.println("prvProcID.getPublicProcessID().getID()="+prvProcID.getPublicProcessID().getID()+
  407.    //           "\nprvProcID.getPublicProcessID().getProcessDefID()="+prvProcID.getPublicProcessID().getProcessDefID()+
  408.    //           "\nprvProcID.getPublicProcessID().getDisplayName()="+prvProcID.getPublicProcessID().getDisplayName());
  409.    return prvProcID.getPublicProcessID().getDisplayName();
  410. }
  411.  
  412. /**
  413.  * Insert the method's description here.
  414.  * Creation date: (10/16/00 4:40:24 PM)
  415.  * @return java.lang.String
  416.  * @param processID String - Extricity public process id
  417.  * @param i_msgid String - LMS Message ID
  418.  * @param i_msgfilter com.extricity.document.api.Element
  419.  * @param o_msghdr com.extricity.document.api.Element
  420.  * @param o_commitcontext com.extricity.document.api.Element
  421.  * @param o_opstatus com.extricity.document.api.Element
  422.  * @exception com.extricity.adapter.api.ISException The exception description.
  423.  */
  424. public ProcessDataInt executeRecvMsg(String processID, String i_msgid,boolean peekonly, Element i_msgfilter, Element o_msghdr, Element o_opstatus)
  425.    throws com.extricity.adapter.api.ISException
  426. {
  427.    EpicNativeAdapter theENA = getEpicNativeAdapter(processID);
  428.    ENAService theENAServ = new ENAService();
  429.    theENAServ.setApplicationName(gatewayComp);
  430.    theENAServ.setBodyCategory(msgBodyCategory);
  431.    theENAServ.setBodyType("DEFAULT");
  432.    EpicMessageExt theEM;
  433.    ProcessData pd = new ProcessData();
  434.  
  435.    if(_DEBUG)
  436.    {
  437.           System.out.println("executeRecvMsg:\n  processID="+processID+"\n  MsgID="+i_msgid);
  438.    }
  439.    // Are we requesting a specific message
  440.    if(i_msgid == null)
  441.    {
  442.           if(_DEBUG)
  443.           {
  444.                  System.out.println("  executeRecvMsg CorID="+processID);
  445.           }
  446.           // Receive a message for a specific process
  447.           theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.encodeLMSCorrelationID(processID));
  448.    }
  449.    else
  450.    {
  451.           if(_DEBUG)
  452.           {
  453.                  System.out.println("  executeRecvMsg MsgID="+i_msgid);
  454.           }
  455.           // Receive a message for a specific LMS Message ID
  456.           theENAServ.addFilter(theENAServ.FILTERNAME_LMS_MESSAGE_ID,i_msgid);
  457.    }
  458.    theENAServ.setPeekOnly(peekonly);
  459.    if(recvPollRate > 0)
  460.    {
  461.           // Check for 1 second
  462.           theENAServ.setTimout(1000);
  463.    }
  464.    // Do the receive
  465.    try
  466.    {
  467.           theENA.begin();
  468.           do
  469.           {
  470.                  theEM = (EpicMessageExt)theENA.receiveMsg(theENAServ);
  471.                  if(_DEBUG && (theEM == null))
  472.                  {
  473.                         System.out.println("  executeRecvMsg NO-MESSAGE-MEETING-CRITERIA");
  474.                  }
  475.           } while((theEM == null) && (i_msgid == null) && (recvPollRate == 0));
  476.    }
  477.    catch(AdapterException e)
  478.    {
  479.           // Return the ENA to pool
  480.           retEpicNativeAdapter(theENA);
  481.  
  482.           logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  483.           throw new ISException(e.toString());
  484.    }
  485.  
  486.    if(theEM == null)
  487.    {
  488.           if(i_msgid != null)
  489.           {
  490.              throw new ISException("NO-MESSAGE-MEETING-CRITERIA("+i_msgid+")");
  491.           }
  492.           pd.setMsgXML(null);
  493.    }
  494.    else
  495.    {
  496.           if(_DEBUG)
  497.           {
  498.              System.out.println("  executeRecvMsg theEM: " + theEM.toString());
  499.           }
  500.  
  501.           // Fill the header BO
  502.           o_msghdr.setData("MessageType",theEM.getMsgType());
  503.           o_msghdr.setData("AckRequested",theEM.getAckRequested());
  504.           o_msghdr.setData("DestinationComponent",theEM.getDestinationComponent());
  505.           o_msghdr.setData("SrcTradingPartnerID",theEM.getSrcTradingPartnerID());
  506.           o_msghdr.setData("DstTradingPartnerID",theEM.getDstTradingPartnerID());
  507.           o_msghdr.setData("BOCorrelationID",theEM.getBOCorrelationID());
  508.           o_msghdr.setData("ExtricityProcessID",theEM.getExtricityProcessID());
  509.           o_msghdr.setData("ProtocolAndVersion",theEM.getProtocolAndVersion());
  510.           o_msghdr.setData("ProcessTransactionID",theEM.getProcessTransactionID());
  511.           o_msghdr.setData("UniqueMsgID",theEM.getUniqueMsgID());
  512.           // Get the XML body
  513.           pd.setMsgXML(theEM.getBodyData());
  514.  
  515.           if(_DEBUG)
  516.           {
  517.              System.out.println("  executeRecvMsg MsgHdr=" + o_msghdr.toString(true)+
  518.                                             "\n   XML="+pd.getMsgXML());
  519.           }
  520.  
  521.           // Do we have a commit context
  522.           if(expCommit)
  523.           {
  524.              // Fill in the commit context
  525.              pd.setCommitContext(theEM.getLMSMessageID());
  526.              if(_DEBUG)
  527.              {
  528.                     System.out.println("  executeRecvMsg GenCommitContext="+pd.getCommitContext());
  529.              }
  530.              // Save the ENA for this process
  531.              saveEpicNativeAdapter(processID,theENA);
  532.           }
  533.           else
  534.           {
  535.              if(_DEBUG)
  536.              {
  537.                     System.out.println("  executeRecvMsg IMPLICIT-COMMIT");
  538.              }
  539.              // Commit the operation in-line
  540.              commit(processID,theENA);
  541.              // Return the ENA to pool
  542.              retEpicNativeAdapter(theENA);
  543.           }
  544.    }
  545.    return pd;
  546. }
  547.  
  548. /**
  549.  * Insert the method's description here.
  550.  * Creation date: (10/16/00 4:41:19 PM)
  551.  * @param processID String - Extricity public process id
  552.  * @param i_msghdr com.extricity.document.api.Element
  553.  * @param i_msgxml java.lang.String
  554.  * @param o_commitcontext com.extricity.document.api.Element
  555.  * @param o_opstatus com.extricity.document.api.Element
  556.  * @exception com.extricity.adapter.api.ISException The exception description.
  557.  */
  558. public String executeSendMsg(String processID, Element i_msghdr, String i_msgxml, Element o_opstatus, String uniqueID)
  559.    throws com.extricity.adapter.api.ISException
  560. {
  561.    EpicNativeAdapter theENA = getEpicNativeAdapter(processID);
  562.    EpicMessageExt theEM;
  563.    String CommitContext = null;
  564.  
  565.    if(_DEBUG)
  566.    {
  567.           System.out.println("executeSendMsg\n  processID="+processID+"\n  msgHdr="+i_msghdr.toString(true)+"\n  msgXML="+i_msgxml);
  568.    }
  569.    // Check if message already sent
  570.    if(expCommit)
  571.    {
  572.           // Find the message on the _STATE_ queue based on the commit context and remove it
  573.           ENAService theENAServ = new ENAService();
  574.           theENAServ.setApplicationName(internalAppId);
  575.           theENAServ.setBodyCategory("_STATE_");
  576.           theENAServ.setBodyType("_STATE_");
  577.           // Receive a message for a specific Correlation ID
  578.           theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.encodeLMSCorrelationID("_COMMIT_"+processID));
  579.           theENAServ.setPeekOnly(true);
  580.           theENAServ.setTimout(0);
  581.           // Do the receive
  582.           try
  583.           {
  584.                  if(theENA.receiveMsg(theENAServ) != null)
  585.                  {
  586.                         // Message already sent - Just return the commit context
  587.                         if(_DEBUG)
  588.                         {
  589.                            System.out.println("  executeSendMsg MESSAGE-ALREADY-SENT");
  590.                         }
  591.                         return "_COMMIT_"+processID;
  592.                  }
  593.           }
  594.           catch(AdapterException e)
  595.           {
  596.              // Return the ENA to pool
  597.              retEpicNativeAdapter(theENA);
  598.  
  599.                  logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  600.                  throw new ISException(e.toString());
  601.           }
  602.    }
  603.    // Send the message
  604.    theEM = sendMsg(theENA,processID,i_msghdr,i_msgxml,uniqueID);
  605.  
  606.    if(expCommit)
  607.    {
  608.           try
  609.           {
  610.                  theEM.setDestinationComponent(internalAppId);
  611.                  theEM.setBodyCategory("_STATE_");
  612.                  theEM.setBodyType("_STATE_");
  613.                  theEM.setLMSMessageID(theEM.LMS_MESSAGE_ID_NONE);
  614.                  theEM.setExtricityProcessID("_COMMIT_"+processID);
  615.                  // Remove the message data to save queue size
  616.                  theEM.setBodyData(null);
  617.                  if(_DEBUG)
  618.                  {
  619.                         System.out.println("  executeSendMsg theEM: " + theEM.toString());
  620.                  }
  621.                  // Save the state message
  622.                  theENA.sendMsg(theEM);
  623.           }
  624.           catch(AdapterException e)
  625.           {
  626.              // Return the ENA to pool
  627.              retEpicNativeAdapter(theENA);
  628.  
  629.                  logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  630.                  throw new ISException(e.toString());
  631.           }
  632.           // Fill in the commit context
  633.           CommitContext = "_COMMIT_"+processID;
  634.    }
  635.    else
  636.    {
  637.           if(_DEBUG)
  638.           {
  639.                  System.out.println("  executeSendMsg IMPLICIT-COMMIT");
  640.           }
  641.    }
  642.    // Commit the operation in-line
  643.    commit(processID,theENA);
  644.    // Return the ENA to pool
  645.    retEpicNativeAdapter(theENA);
  646.    // Return the commit context
  647.    return CommitContext;
  648. }
  649.  
  650. /**
  651.  * Insert the method's description here.
  652.  * Creation date: (11/6/00 2:14:16 PM)
  653.  * @param processID java.lang.String
  654.  * @param pd com.ibm.extricity.adapters.mqseries.mqak.ProcessData
  655.  */
  656. public void executeSetProcessData(String processID, ProcessDataInt pd)
  657.    throws com.extricity.adapter.api.ISException
  658. {
  659.    EpicNativeAdapter theENA = getEpicNativeAdapter(processID);
  660.    ENAService theENAServ = new ENAService();
  661.    theENAServ.setApplicationName(internalAppId);
  662.    theENAServ.setBodyCategory("_STATE_");
  663.    theENAServ.setBodyType("_STATE_");
  664.  
  665.    if(_DEBUG)
  666.    {
  667.           System.out.println("executeSetProcessData:\n  processID="+processID+"\n  ProcessData="+pd.toString());
  668.    }
  669.    // Delete any previous copy
  670.    executeDelProcessData(processID);
  671.    try
  672.    {
  673.           // Fill the relevent fields
  674.           EpicMessageExt theEM = new EpicMessageExt(internalAppId,"StateMessage");
  675.           theEM.setAckRequested("False");
  676.           theEM.setDestinationComponent(internalAppId);
  677.           theEM.setDstTradingPartnerID(pd.getTradingPartner());
  678.           theEM.setBOCorrelationID(pd.getBOCorrelationID());
  679.           theEM.setExtricityProcessID(processID);
  680.           theEM.setBodyCategory("_STATE_");
  681.           theEM.setBodyType("_STATE_");
  682.           if(_DEBUG)
  683.           {
  684.                  System.out.println("  executeSetProcessData theEM: " + theEM.toString());
  685.           }
  686.           // Send the message
  687.           theENA.begin();
  688.           theENA.sendMsg(theEM);
  689.           // Commit the operation in-line
  690.           theENA.commit();
  691.    }
  692.    catch(AdapterException e)
  693.    {
  694.           // Return the ENA to pool
  695.           retEpicNativeAdapter(theENA);
  696.  
  697.           logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  698.           throw new ISException(e.toString());
  699.    }
  700.  
  701.    // Return the ENA to pool
  702.    retEpicNativeAdapter(theENA);
  703. }
  704.  
  705.  
  706.  
  707. /**
  708.  * Insert the method's description here.
  709.  * Creation date: (10/23/00 3:07:55 PM)
  710.  * @param args java.lang.String[]
  711.  */
  712. public static void main(String[] args)
  713. {
  714.    MQAOAdapterHelper ad = new MQAOAdapterHelper();
  715.    Element msghdr = new TestElement();
  716.    Element opstat = new TestElement();
  717.    String comCtx = null;
  718.    TestEventContext ec = new TestEventContext();
  719.    // Create
  720.    String theXML = "<Pip3A4PurchaseOrderRequest><PurchaseOrder><ProductLineItem><shipFrom><GlobalLocationIdentifier>Home</GlobalLocationIdentifier></shipFrom><ProductQuantity>10</ProductQuantity><LineNumber>001</LineNumber><productUnit><ProductPackageDescription><ProductDescription><GlobalProductIdentifier>Junk</GlobalProductIdentifier></ProductDescription></ProductPackageDescription></productUnit><requestedShipDate><DateStamp>11/30/2000</DateStamp></requestedShipDate><GlobalProductUnitOfMeasureCode>Piece</GlobalProductUnitOfMeasureCode><SpecialHandlingInstruction><SpecialHandlingText><FreeFormText>None</FreeFormText></SpecialHandlingText></SpecialHandlingInstruction><requestedPrice><FinancialAmount><GlobalCurrencyCode>USD</GlobalCurrencyCode><MonetaryAmount>1000.00</MonetaryAmount></FinancialAmount></requestedPrice></ProductLineItem><GlobalShipmentTermsCode>FOB</GlobalShipmentTermsCode><RevisionNumber>0</RevisionNumber><GlobalFinanceTermsCode>NET30</GlobalFinanceTermsCode><PartnerDescription><GlobalPartnerClassificationCode>Provider</GlobalPartnerClassificationCode></PartnerDescription><GlobalPurchaseOrderTypeCode>RN</GlobalPurchaseOrderTypeCode></PurchaseOrder><fromRole><PartnerRoleDescription><GlobalPartnerRoleClassificationCode>Buyer</GlobalPartnerRoleClassificationCode></PartnerRoleDescription></fromRole><toRole><PartnerRoleDescription><GlobalPartnerRoleClassificationCode>Seler</GlobalPartnerRoleClassificationCode></PartnerRoleDescription></toRole><thisDocumentGenerationDateTime><DateTimeStamp>11/2/2000 09:17:00</DateTimeStamp></thisDocumentGenerationDateTime><thisDocumentIdentifier><ProprietaryDocumentIdentifier>PO98798</ProprietaryDocumentIdentifier></thisDocumentIdentifier><GlobalDocumentFunctionCode>PO</GlobalDocumentFunctionCode></Pip3A4PurchaseOrderRequest>";
  721.    // Accept
  722.    //String theXML = "<Pip3A4PurchaseOrderAcceptance><PurchaseOrder><GlobalPurchaseOrderStatusCode>Accept</GlobalPurchaseOrderStatusCode><GlobalShipmentTermsCode>FOB</GlobalShipmentTermsCode><RevisionNumber>0</RevisionNumber><purchaseOrderDate><DateStamp>11/30/2000</DateStamp></purchaseOrderDate><purchaseOrderNumber><ProprietaryDocumentIdentifier>PO98798</ProprietaryDocumentIdentifier></purchaseOrderNumber></PurchaseOrder><fromRole><PartnerRoleDescription><GlobalPartnerRoleClassificationCode>Seler</GlobalPartnerRoleClassificationCode><PartnerDescription><GlobalPartnerClassificationCode>Seler</GlobalPartnerClassificationCode><BusinessDescription><GlobalBusinessIdentifier>Manufacturer</GlobalBusinessIdentifier><GlobalSupplyChainCode>Manufacturer</GlobalSupplyChainCode></BusinessDescription></PartnerDescription></PartnerRoleDescription></fromRole><toRole><PartnerRoleDescription><GlobalPartnerRoleClassificationCode>Buyer</GlobalPartnerRoleClassificationCode><PartnerDescription><GlobalPartnerClassificationCode>Buyer</GlobalPartnerClassificationCode><BusinessDescription><GlobalBusinessIdentifier>Shopper</GlobalBusinessIdentifier><GlobalSupplyChainCode>Shopper</GlobalSupplyChainCode></BusinessDescription></PartnerDescription></PartnerRoleDescription></toRole><thisDocumentGenerationDateTime><DateTimeStamp>11/2/2000 09:17:00</DateTimeStamp></thisDocumentGenerationDateTime><thisDocumentIdentifier><ProprietaryDocumentIdentifier>PO98798</ProprietaryDocumentIdentifier></thisDocumentIdentifier><requestingDocumentIdentifier><ProprietaryDocumentIdentifier>PO98798</ProprietaryDocumentIdentifier></requestingDocumentIdentifier><GlobalDocumentFunctionCode>PO</GlobalDocumentFunctionCode><requestingDocumentDateTime><DateTimeStamp>11/2/2000 09:17:00</DateTimeStamp></requestingDocumentDateTime></Pip3A4PurchaseOrderAcceptance>";
  723.    String theCorID = new String("4.ijcxbwsq");//(new Date()).toString();
  724.    //String theCorID = new String("16.ij12cmjo");//(new Date()).toString();
  725.    //String theCorID = new String("14.ij12cmjo");//(new Date()).toString();
  726.    String theMsgID = null;
  727.    String pID = "4.iiclkt4n.im4d42.000000e2970e17104.ihxblcrg.im4d42..DICAM.847409406.ORG-3A4-1_1-Create Purchase Order.1.0.1";
  728.  
  729.    _DEBUG = true;
  730.  
  731.    try
  732.    {
  733.           ProcessDataInt pd = new ProcessData(theCorID,"847409406");
  734.           /*ad.executeSetProcessData(pID,pd);
  735.           pd = ad.executeGetProcessData(pID);
  736.           System.out.println("PROCESSDATA: " + pd.toString());
  737.           ad.executeDelProcessData(pID);*/
  738.  
  739.           if((new Random((new Date()).getTime())).nextFloat() < 1.0)
  740.           {
  741.                  theCorID = EpicMessageExt.NO_EXTRICITYPROCESSID;
  742.           }
  743.           ad.startup("BFM","BFM","GATEWAY","RosettaNet-1_1","DEFAULT",null,true,true,false,30);
  744.           msghdr.setData("SrcTradingPartnerID","847409406");
  745.           msghdr.setData("DstTradingPartnerID","103");
  746.           msghdr.setData("BOCorrelationID",theCorID);
  747.           msghdr.setData("ProcessTransactionID","3A4-1_1-CreatePurchaseOrder");
  748.           System.out.println("SEND msghdr: " + msghdr.toString());
  749.           System.out.println("   XML: " + theXML);
  750.           comCtx = ad.executeSendMsg(theCorID,msghdr,theXML,opstat,"TestUniqueID");
  751.           //comCtx = ad.executeSendMsg(theCorID,msghdr,theXML,opstat,"TestUniqueID");
  752.           ad.executeCommit(theCorID,comCtx,opstat);
  753.  
  754.           //ad.poolENA.clear();
  755.           ad.startup("GATEWAY","BFM","BFM","RosettaNet-1_1","DEFAULT",null,true,true,false,30);
  756.           if(theCorID.compareTo(EpicMessageExt.NO_EXTRICITYPROCESSID) == 0)
  757.           {
  758.                  do
  759.                  {
  760.                         //theXML = ad.executeRecvMsg(theCorID,theMsgID,null,msghdr,comctx,opstat);
  761.                         ad.checkForEvents(ec);
  762.                         theMsgID = ec.getVariantEvent();
  763.                  } while(theMsgID == null);
  764.                  System.out.println("\n\n======================\nEVENT msgid: " + theMsgID + "\n================\n");
  765.           }
  766.           //theCorID = "Wed Oct 25 10:41:51 EDT ";
  767.           msghdr.clearAll();
  768.           ProcessDataInt pdXML = ad.executeRecvMsg(pID,theMsgID,false,null,msghdr,opstat);
  769.           System.out.println("RECEIVE msghdr: " + msghdr.toString());
  770.           System.out.println("   XML: " + pdXML.getMsgXML());
  771.           ad.executeCommit(pID,pdXML.getCommitContext(),opstat);
  772.           theCorID = msghdr.getData("BOCorrelationID");
  773.  
  774.           //ProcessData pd = new ProcessData(pID,"847409406");
  775.           ad.executeSetProcessData(theCorID,pd);
  776.           pd = ad.executeGetProcessData(theCorID);
  777.           System.out.println("PROCESSDATA: " + pd.toString());
  778.           ad.executeDelProcessData(theCorID);
  779.    }
  780.    catch(ISException e)
  781.    {
  782.           System.out.println("executeRecvMsg->ISException: " + e.toString());
  783.    }
  784. }
  785.  
  786. /**
  787.  * onProcessCompletion method comment.
  788.  */
  789. public void onProcessCompletion(CRStation.defs.machine.ProcessID process_id)
  790. {
  791.    if(_DEBUG)
  792.    {
  793.           System.out.println("onProcessCompletion\n  process_id="+process_id.getDisplayName());
  794.    }
  795.    addEvent(process_id.getDisplayName());
  796. }
  797.  
  798. /**
  799.  * Insert the method's description here.
  800.  * Creation date: (10/18/00 3:06:30 PM)
  801.  * @return com.ibm.epic.adapters.eak.nativeadapter.EpicNativeAdapter
  802.  * @param ProcessID java.lang.String
  803.  */
  804. private synchronized EpicNativeAdapter restEpicNativeAdapter(String ProcessID)
  805. {
  806.    return (EpicNativeAdapter)lockedENA.remove(ProcessID);
  807. }
  808.  
  809. /**
  810.  * Insert the method's description here.
  811.  * Creation date: (10/18/00 3:02:55 PM)
  812.  * @param theENA com.ibm.epic.adapters.eak.nativeadapter.EpicNativeAdapter
  813.  */
  814. private synchronized void retEpicNativeAdapter(EpicNativeAdapter theENA)
  815. {
  816.    poolENA.add(theENA);
  817. }
  818.  
  819. /**
  820.  * Insert the method's description here.
  821.  * Creation date: (10/18/00 3:04:23 PM)
  822.  * @param ProcessID java.lang.String
  823.  * @param theENA com.ibm.epic.adapters.eak.nativeadapter.EpicNativeAdapter
  824.  */
  825. private synchronized void saveEpicNativeAdapter(String ProcessID, EpicNativeAdapter theENA)
  826. {
  827.    lockedENA.put(ProcessID,theENA);
  828. }
  829.  
  830. /**
  831.  * Insert the method's description here.
  832.  * Creation date: (10/19/00 3:18:45 PM)
  833.  * @param theENA com.ibm.epic.adapters.eak.nativeadapter.EpicNativeAdapter
  834.  * @param processID java.lang.String
  835.  * @param i_msghdr com.extricity.document.api.Element
  836.  * @param i_msgxml java.lang.String
  837.  */
  838. private EpicMessageExt sendMsg(EpicNativeAdapter theENA, String processID, Element i_msghdr, String i_msgxml, String uniqueID)
  839.    throws com.extricity.adapter.api.ISException
  840. {
  841.    EpicMessageExt theEM = null;
  842.  
  843.    try
  844.    {
  845.           // Create the message
  846.           if(i_msghdr.getData("MessageType") == null)
  847.           {
  848.                  theEM = new EpicMessageExt(gatewayComp,"GatewayMessage");
  849.           }
  850.           else
  851.           {
  852.                  if(i_msghdr.getData("MessageType").compareTo("GatewayMessage") == 0)
  853.                  {
  854.                         theEM = new EpicMessageExt(gatewayComp,"GatewayMessage");
  855.                  }
  856.                  else if(i_msghdr.getData("MessageType").compareTo("GatewayCommand") == 0)
  857.                  {
  858.                         theEM = new EpicMessageExt(gatewayComp,"GatewayCommand");
  859.                  }
  860.                  else
  861.                  {
  862.                         theEM = new EpicMessageExt(gatewayComp,"GatewayMessage");
  863.                  }
  864.           }
  865.           // Fill the message header
  866.           theEM.setAckRequested("0");
  867.           if(i_msghdr.getData("DestinationComponent") == null)
  868.           {
  869.                  theEM.setDestinationComponent(destComp);
  870.           }
  871.           else
  872.           {
  873.                  theEM.setDestinationComponent(i_msghdr.getData("DestinationComponent"));
  874.           }
  875.           theEM.setSrcTradingPartnerID(i_msghdr.getData("SrcTradingPartnerID"));
  876.           theEM.setDstTradingPartnerID(i_msghdr.getData("DstTradingPartnerID"));
  877.           if(i_msghdr.getData("BOCorrelationID") != null)
  878.           {
  879.                  theEM.setBOCorrelationID(i_msghdr.getData("BOCorrelationID"),true);
  880.           }
  881.           else
  882.           {
  883.                  // Look-up BO Correlation ID for ExtricityProcessID
  884.                  ProcessDataInt pd = executeGetProcessData(processID);
  885.                  if(pd.getBOCorrelationID() == null)
  886.                  {
  887.                         // Default
  888.                         theEM.setBOCorrelationID(theEM.NO_BOCORRELATIONID,true);
  889.                  }
  890.                  else
  891.                  {
  892.                         theEM.setBOCorrelationID(pd.getBOCorrelationID(),true);
  893.                  }
  894.           }
  895.           theEM.setExtricityProcessID(processID,false);
  896.           if(i_msghdr.getData("ProtocolAndVersion") == null)
  897.           {
  898.                  theEM.setProtocolAndVersion(protAndVer);
  899.           }
  900.           else
  901.           {
  902.                  theEM.setProtocolAndVersion(i_msghdr.getData("ProtocolAndVersion"));
  903.           }
  904.           theEM.setProcessTransactionID(i_msghdr.getData("ProcessTransactionID"));
  905.           if(i_msghdr.getData("UniqueMsgID") == null)
  906.           {
  907.              theEM.setUniqueMsgID(uniqueID);
  908.           }
  909.           else
  910.           {
  911.              theEM.setUniqueMsgID(i_msghdr.getData("UniqueMsgID"));
  912.           }
  913.  
  914.  
  915.           // Fill the message data
  916.           theEM.setBodyData(i_msgxml);
  917.           if(_DEBUG)
  918.           {
  919.                  System.out.println("  sendMsg theEM: " + theEM.toString());
  920.           }
  921.           // Send the message
  922.           theENA.begin();
  923.           theENA.sendMsg(theEM);
  924.    }
  925.    catch(AdapterException e)
  926.    {
  927.           // Return the ENA to pool
  928.           retEpicNativeAdapter(theENA);
  929.  
  930.           logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  931.           throw new ISException(e.toString());
  932.    }
  933.    return theEM;
  934. }
  935.  
  936. /**
  937.  * Insert the method's description here.
  938.  * Creation date: (10/6/00 2:44:50 PM)
  939.  */
  940. public void shutdown() throws com.extricity.adapter.api.ISException
  941. {
  942.    // Close the process monitor functionality
  943.    close();
  944.  
  945.    // Close the queue monitor
  946.    stopMonitor = true;
  947.    monitor.interrupt();
  948.  
  949.    // Release resources
  950.    poolENA.clear();
  951.    lockedENA.clear();
  952.    termEvents.clear();
  953. }
  954.  
  955.  
  956.  
  957.         protected Thread monitor = null;
  958.         protected boolean stopMonitor = false;
  959.  
  960. /**
  961.  * Insert the method's description here.
  962.  * Creation date: (10/18/00 3:23:39 PM)
  963.  * @param theENA com.ibm.epic.adapters.eak.nativeadapter.EpicNativeAdapter
  964.  */
  965. private void commit(String processID,EpicNativeAdapter theENA)
  966.    throws com.extricity.adapter.api.ISException
  967. {
  968.    try
  969.    {
  970.           theENA.commit();
  971.    }
  972.    catch(AdapterException e)
  973.    {
  974.           logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  975.           throw new ISException(e.toString());
  976.    }
  977. }
  978.  
  979.  
  980.  
  981. /**
  982.  * Insert the method's description here.
  983.  * Creation date: (10/6/00 3:47:01 PM)
  984.  * @return com.ibm.epic.adapters.eak.nativeadapter.EpicNativeAdapter
  985.  * @exception com.ibm.epic.adapters.eak.common.AdapterException The exception description.
  986.  */
  987. private synchronized EpicNativeAdapter getEpicNativeAdapter(String processID)
  988.         throws com.extricity.adapter.api.ISException
  989. {
  990.    EpicNativeAdapter theENA;
  991.  
  992.    if(poolENA.isEmpty())
  993.    {
  994.           try
  995.           {
  996.                  return new EpicNativeAdapter(gatewayComp,"IBM Extricity MQAK Adapter");
  997.           }
  998.           catch(AdapterException e)
  999.           {
  1000.                  logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  1001.                  throw new ISException(e.toString());
  1002.           }
  1003.    }
  1004.    else
  1005.    {
  1006.           return (EpicNativeAdapter)poolENA.remove(0);
  1007.    }
  1008. }
  1009.  
  1010.  
  1011.  
  1012. /**
  1013.  * Insert the method's description here.
  1014.  * Creation date: (5/23/00 4:45:32 PM)
  1015.  */
  1016. public void run()
  1017. {
  1018.         EpicNativeAdapter theENA;
  1019.         ENAService theENAServ = new ENAService();
  1020.         theENAServ.setApplicationName(gatewayComp);
  1021.         theENAServ.setBodyCategory(msgBodyCategory);
  1022.         theENAServ.setBodyType("DEFAULT");
  1023.         EpicMessageExt theEM;
  1024.  
  1025.         // Receive a message for a specific process
  1026.         theENAServ.addFilter(theENAServ.FILTERNAME_LMS_CORRELATION_ID,EpicMessageExt.encodeLMSCorrelationID(""));
  1027.         theENAServ.setPeekOnly(true);
  1028.         theENAServ.setTimout(30000);
  1029.  
  1030.         byte[] nocorl = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  1031.  
  1032.         try
  1033.         {
  1034.                 theENA = getEpicNativeAdapter("ProcessID=MQAK_1.0.1_TRANSLATOR");
  1035.         }
  1036.         catch(ISException e)
  1037.         {
  1038.                 return;
  1039.         }
  1040.  
  1041.         while(true)
  1042.         {
  1043.                 try
  1044.                 {
  1045.                         // Exit the que monitor
  1046.                         if(stopMonitor)
  1047.                         {
  1048.                                 // Return the ENA to pool
  1049.                                 retEpicNativeAdapter(theENA);
  1050.  
  1051.                                 return;
  1052.                         }
  1053.                         theEM = (EpicMessageExt)theENA.receiveMsg(theENAServ);
  1054.                         if(theEM == null)
  1055.                         {
  1056.                                 if(_DEBUG)
  1057.                                 {
  1058.                                         System.out.println("  run NO-MESSAGE-MEETING-CRITERIA");
  1059.                                 }
  1060.                         }
  1061.                         else if( (theEM.getLMSCorrelationID().compareTo(new String(nocorl)) != 0) &&
  1062.                                      (theEM.getLMSCorrelationID().substring(0,6).compareTo("GWNONE") != 0) )
  1063.                         {
  1064.                                 System.out.println(
  1065.                                         "Skipping Message with COrrelationID='" + theEM.getLMSCorrelationID() + "'"+theEM.getLMSCorrelationID().length());
  1066.                                 theEM = null;
  1067.                                 Thread.sleep(5000);
  1068.                         }
  1069.                         else
  1070.                         {
  1071.                                 theENAServ.addFilter(theENAServ.FILTERNAME_LMS_MESSAGE_ID,theEM.getLMSMessageID());
  1072.                                 theENAServ.setPeekOnly(false);
  1073.                                 theENA.begin();
  1074.                                 theEM = (EpicMessageExt) theENA.receiveMsg(theENAServ);
  1075.                                 theENAServ.delFilter(theENAServ.FILTERNAME_LMS_MESSAGE_ID);
  1076.                                 theENAServ.setPeekOnly(true);
  1077.                                 theEM.setLMSCorrelationID(theEM.encodeLMSCorrelationID("NONE"));
  1078.                                 if(_DEBUG)
  1079.                                 {
  1080.                                         System.out.println("  run theEM: " + theEM.toString());
  1081.                                 }
  1082.                                 // Save the state message
  1083.                                 theENA.sendMsg(theEM);
  1084.                                 theENA.commit();
  1085.                         }
  1086.                 }
  1087.                 catch(AdapterException e)
  1088.                 {
  1089.                         try
  1090.                         {
  1091.                                 theENA.rollback();
  1092.                         }
  1093.                         catch(AdapterException x)
  1094.                         {
  1095.                         }
  1096.                         if(_DEBUG)
  1097.                         {
  1098.                                 System.out.println("  run MQAK-EXCEPTION-RECEIVING-MESSAGE: " + e.toString());
  1099.                         }
  1100.                 }
  1101.                 catch(Exception e)
  1102.                 {
  1103.                         try
  1104.                         {
  1105.                                 theENA.rollback();
  1106.                         }
  1107.                         catch(AdapterException x)
  1108.                         {
  1109.                         }
  1110.                         if(_DEBUG)
  1111.                         {
  1112.                                 System.out.println(
  1113.                                         "  run GENERAL-EXCEPTION-RECEIVING-MESSAGE: " + e.toString());
  1114.                         }
  1115.                         return;
  1116.                 }
  1117.         }
  1118. }
  1119.  
  1120.         private String internalAppId = "GATEWAY";
  1121.  
  1122.  
  1123.         private static String ADAPTER_EXCEPTION = "EXCEPTION0402";
  1124.         private static String GENERAL_EXCEPTION = "EXCEPTION0402";
  1125.         private MQAOExceptionLogExt logExt = null;
  1126.  
  1127. /**
  1128.  * Insert the method's description here.
  1129.  * Creation date: (10/25/00 9:51:13 AM)
  1130.  * @return java.lang.String
  1131.  * @param prvProcID java.lang.String
  1132.  */
  1133. public void executeLogException(String processID, String subComponent,String logMessage,String exceptionId,String processName,String extData,Element opStatus)
  1134.         throws com.extricity.adapter.api.ISException
  1135. {
  1136.         if((exceptionId == null) || (exceptionId.compareTo("") == 0))
  1137.         {
  1138.                 exceptionId = GENERAL_EXCEPTION;
  1139.         }
  1140.         if((processName == null) || (processName.compareTo("") == 0))
  1141.         {
  1142.                 processName = "UNKNOWN";
  1143.         }
  1144.         try
  1145.         {
  1146.                 logExceptionInt(processID,subComponent,logMessage,exceptionId,processName,extData);
  1147.         }
  1148.         catch(Exception e)
  1149.         {
  1150.                 opStatus.setData("result","failure");
  1151.                 opStatus.setData("reason",e.toString());
  1152.         }
  1153. }
  1154.  
  1155. /**
  1156.  * Insert the method's description here.
  1157.  * Creation date: (3/2/01 4:55:26 PM)
  1158.  * @param processID java.lang.String
  1159.  * @param subComponent java.lang.String
  1160.  * @param errMessage java.lang.String
  1161.  */
  1162. public void logException(String processID,String subComponent,String logMessage,String exceptionId,String processName)
  1163. {
  1164.         logException(processID,subComponent,logMessage,exceptionId,processName,null);
  1165. }
  1166.  
  1167. /**
  1168.  * Insert the method's description here.
  1169.  * Creation date: (3/2/01 4:55:26 PM)
  1170.  * @param processID java.lang.String
  1171.  * @param subComponent java.lang.String
  1172.  * @param errMessage java.lang.String
  1173.  */
  1174. public void logException(String processID,String subComponent,String logMessage,String exceptionId,String processName,String extData)
  1175. {
  1176.         try
  1177.         {
  1178.                 logExceptionInt(processID,subComponent,logMessage,exceptionId,processName,extData);
  1179.         }
  1180.         catch(Exception e)
  1181.         {
  1182.                  System.out.println("  logException: Error while exception logging: "+e.toString());
  1183.                  System.out.println("                Log=!"+exceptionId+"!: "+subComponent+" "+processName+" "+processID+" "+logMessage);
  1184.         }
  1185. }
  1186.  
  1187. /**
  1188.  * Insert the method's description here.
  1189.  * Creation date: (3/2/01 4:55:26 PM)
  1190.  * @param processID java.lang.String
  1191.  * @param subComponent java.lang.String
  1192.  * @param errMessage java.lang.String
  1193.  */
  1194. private void logExceptionInt(String processID,String subComponent,String logMessage,String exceptionId,String processName,String extData)
  1195.         throws Exception
  1196. {
  1197.         if(exceptionId == null)
  1198.         {
  1199.                 exceptionId = GENERAL_EXCEPTION;
  1200.         }
  1201.         else if(exceptionId.compareTo("") == 0)
  1202.         {
  1203.                 exceptionId = GENERAL_EXCEPTION;
  1204.         }
  1205.         if(processName == null)
  1206.         {
  1207.                 processName = "UNKNOWN";
  1208.         }
  1209.         if(logExt == null)
  1210.         {
  1211.                 EpicLog epicLog = new EpicLog(gatewayComp,"GATEWAY");
  1212.                 String stringMsg;
  1213.                 try
  1214.                 {
  1215.                         stringMsg = new EpicLogTraceException(exceptionId,
  1216.                                                                                                   new Object[]{subComponent,processName,processID}).toString();
  1217.                 }
  1218.                 catch(Exception e)
  1219.                 {
  1220.                         stringMsg = null;
  1221.                 }
  1222.                 if((stringMsg == null) || (stringMsg.compareTo("") == 0))
  1223.                 {
  1224.                         stringMsg = "!"+exceptionId+"!: "+subComponent+" "+processName+" "+processID;
  1225.                 }
  1226.                 epicLog.writeExceptionLog(gatewayComp,stringMsg + " " + logMessage,1);
  1227.         }
  1228.         else
  1229.         {
  1230.                 logExt.logFromMsgFile(exceptionId,subComponent,processName,processID,logMessage,extData);
  1231.         }
  1232. //      System.out.println("===>logException:\n  processId="+processID+"\n  subComponent="+subComponent+
  1233. //                             "\n  logMessage="+logMessage+"\n  processName="+processName+"\n  extData="+extData);
  1234. }
  1235.  
  1236.  
  1237.  
  1238.         private int recvPollRate = 30;
  1239.  
  1240. /**
  1241.  * Insert the method's description here.
  1242.  * Creation date: (10/6/00 4:05:34 PM)
  1243.  * @param gatewayApplication java.lang.String
  1244.  * @param gatewayComponent java.lang.String
  1245.  * @param destinationComponent java.lang.String
  1246.  * @param protocolAndVersion java.lang.String
  1247.  */
  1248. public void startup(String gatewaycomp, String internalappid, String destcomp, String protandver, String msgbodycat, String exceptionlogext, boolean debug, boolean expcommit, boolean adaptmessages, int recvpollrate)
  1249.         throws com.extricity.adapter.api.ISException
  1250. {
  1251.    gatewayComp = gatewaycomp;
  1252.    internalAppId = internalappid;
  1253.    destComp = destcomp;
  1254.    protAndVer = protandver;
  1255.    msgBodyCategory = msgbodycat;
  1256.    _DEBUG = debug;
  1257.    expCommit = expcommit;
  1258.    recvPollRate = recvpollrate;
  1259.  
  1260.    // Initialize the monitor functionality
  1261.    init();
  1262.  
  1263.    if(adaptmessages)
  1264.    {
  1265.            if(monitor == null)
  1266.            {
  1267.                   monitor = new Thread(this);
  1268.                   monitor.start();
  1269.            }
  1270.    }
  1271.  
  1272.    if(exceptionlogext != null)
  1273.    {
  1274.            if(exceptionlogext.compareTo("") != 0)
  1275.            {
  1276.                    try
  1277.                    {
  1278.                            Class logExtClass = Class.forName(exceptionlogext,true,getClass().getClassLoader());
  1279.                            logExt = (MQAOExceptionLogExt)logExtClass.newInstance();
  1280.                            //logExt = (MQAOExceptionLogExt)getClass().getClassLoader().loadClass(exceptionlogext).newInstance();
  1281.                    }
  1282.                    catch(Exception e)
  1283.                    {
  1284.                            System.out.println("Unable to load Exception Logging Extension Class:"+exceptionlogext+" Exception:"+e.toString());
  1285.                    }
  1286.            }
  1287.    }
  1288. }
  1289.         private static String PAMResponse_base = "PAMResponse";
  1290. public void executeAuditLog(String content, Element o_opstatus)
  1291.         throws com.extricity.adapter.api.ISException {
  1292.  
  1293.         String errorCode = "";
  1294.         // write audit logging information
  1295.  
  1296.         try {
  1297.                 if (_DEBUG) {
  1298.                         System.out.print("executeAuditLog:: start to write to the audit log");
  1299.  
  1300.                 }
  1301.  
  1302.                 com.ibm.epic.LogTrace.EpicLog auditLog =
  1303.                         new com.ibm.epic.LogTrace.EpicLog("GATEWAY", "GATEWAY");
  1304.  
  1305.                 /* @param applicationName The application name creating and sending the message
  1306.                 * @param msgType The type of message being created (e.g. Application), may be null to use default
  1307.                 * @param bodyType The type of body for the message (e.g.sync_salesorder)
  1308.                 * @param bodyCategory The category of body for the message (e.g. OAG)
  1309.                 * @param bodyData The body data. This is the data that will be transmitted. It can be in any format
  1310.                 * but is usually expected to be XML usr data.*/
  1311.                 com.ibm.epic.adapters.eak.mcs.EpicMessage msg =
  1312.                         new com.ibm.epic.adapters.eak.mcs.EpicMessage(
  1313.                                 "GATEWAY",
  1314.                                 null,
  1315.                                 "DEFAULT",
  1316.                                 "DEFAULT",
  1317.                                 content);
  1318.  
  1319.                 auditLog.writeAudit(msg);
  1320.                 errorCode = "success";
  1321.         } catch (Exception e) {
  1322.                 if (_DEBUG)
  1323.                         System.out.println("error connect to solution manager" + e.getMessage());
  1324.  
  1325.                 errorCode = "failed";
  1326.         }
  1327.  
  1328.         o_opstatus.setData("result", errorCode);
  1329.  
  1330. }   /**
  1331.  * Insert the method's description here.
  1332.  * Creation date: (10/25/00 9:51:13 AM)
  1333.  * @return void
  1334.  */
  1335. public void executeBuyerAuthentication(String base, String filter, Element o_opstatus)
  1336.         throws com.extricity.adapter.api.ISException {
  1337.  
  1338.         /*
  1339.          * 1. set up ldap connection
  1340.          * 2. instantiate EpicDirectory
  1341.          * 3. authenticate
  1342.          * errorCode: ""(default value); setUpError(set up error); found(set up successful and found the entry);
  1343.          *   notFound(set up successful, entry not found)
  1344.          */
  1345.  
  1346.         String errorCode = "";
  1347.         com.ibm.epic.directory.EpicDirectory directory = null;
  1348.         try {
  1349.                 directory = new com.ibm.epic.directory.EpicDirectory();
  1350.         } catch (Exception e) {
  1351.                 if (_DEBUG)
  1352.                         System.out.println("executeBuyerAuthentication: LDAP set up error");
  1353.                 errorCode = "setUpError";
  1354.         }
  1355.         if (errorCode != null && errorCode.length() == 0) {
  1356.  
  1357.                 try {
  1358.                         NamingEnumeration searchResults =
  1359.                                 directory.search(
  1360.                                         base,
  1361.                                         filter,
  1362.                                         javax.naming.directory.SearchControls.SUBTREE_SCOPE);
  1363.                         if (_DEBUG)
  1364.                                 System.out.println("executeBuyerAuthentication:: found the entry" + filter+base);
  1365.                         errorCode = "found";
  1366.  
  1367.                 } catch (Exception e) {
  1368.                         if (_DEBUG)
  1369.                                 System.out.println("executeBuyerAuthentication: " + filter+base + " not found");
  1370.                         errorCode = "notFound";
  1371.                         if (_DEBUG)
  1372.                                 System.out.println("executeBuyerAuthentication::" + e.getMessage());
  1373.                 } finally {
  1374.                         try {
  1375.                                 directory.close();
  1376.                         } catch (Exception e) {
  1377.                                 //ignore if cannot close the directory context
  1378.                         }
  1379.                 }
  1380.         }
  1381.  
  1382.  
  1383.         o_opstatus.setData("result", errorCode);
  1384.  
  1385.  
  1386. }   /**
  1387.  * Insert the method's description here.
  1388.  * Creation date: (3/7/2002 11:25:59 AM)
  1389.  * @return boolean
  1390.  * @param cardnumber java.lang.String
  1391.  * @exception com.extricity.adapter.api.ISException The exception description.
  1392.  */
  1393. public boolean executeCardCheck(String cardnumber)
  1394.         throws com.extricity.adapter.api.ISException {
  1395.         int weight = 2, sum = 0;
  1396.         boolean allzeros = true;
  1397.  
  1398.         if (cardnumber.length() == 0)
  1399.                 return false;
  1400.  
  1401.         for (int i = 0; i < cardnumber.length(); i++) {
  1402.                 if (cardnumber.charAt(i) != '0') {
  1403.                         allzeros = false;
  1404.                         break;
  1405.                 }
  1406.         }
  1407.         if (allzeros)
  1408.                 return false;
  1409.  
  1410.         // go through the number starting at the 'tens' place and perform the mod 10 weighting
  1411.         for (int pos = cardnumber.length() - 2; pos >= 0; pos--) {
  1412.                 // weight current digit. Note: convert ascii code to the digit it represents
  1413.                 int digit = weight * Character.digit(cardnumber.charAt(pos), 10);
  1414.                 if (digit < 0)
  1415.                         return false; // digit is not valid
  1416.  
  1417.                 // add the digit if less than 10 to the sum, otherwise add the sum of the digits if greater than or equal to 10
  1418.                 sum = sum + (digit / 10) + (digit % 10);
  1419.  
  1420.                 // alternately weight digits by a factors of 2 and 1
  1421.                 weight = (weight == 2) ? 1 : 2;
  1422.  
  1423.         }
  1424.         // compute the numerical value of the last digit
  1425.         int last_digit =
  1426.                 Character.digit(cardnumber.charAt(cardnumber.length() - 1), 10);
  1427.  
  1428.         // is the last digit the same as the computed check?
  1429.         if (last_digit == ((10 - (sum % 10)) % 10))
  1430.                 return true; // yes! valid card number
  1431.  
  1432.         return false;
  1433. }/**
  1434.  * Insert the method's description here.
  1435.  * Creation date: (10/25/00 9:51:13 AM)
  1436.  * @return java.lang.String
  1437.  * @param prvProcID java.lang.String
  1438.  */
  1439. public String executeEncryptPCard(String pCard, Element o_opstatus)
  1440.         throws com.extricity.adapter.api.ISException {
  1441.  
  1442.         if (_DEBUG) {
  1443.                 System.out.println("executeEncryptPCard:  PCard= " + pCard);
  1444.         }
  1445.         String status = null;
  1446.         String encodeResult = null;
  1447.         try {
  1448.                 byte[] result = PSGCCEncryption.doEncrypt(pCard);
  1449.                 if (_DEBUG)
  1450.                         System.out.println(
  1451.                                 "executeEncryptPCard: after encryptioin,the PCard= " + new String(result));
  1452.  
  1453.                 // encoding...
  1454.                 BASE64Encoder encoder = new BASE64Encoder();
  1455.                 encodeResult = encoder.encode(result);
  1456.  
  1457.                 if (_DEBUG)
  1458.                         System.out.println(
  1459.                                 "executeEncryptPCard: after encoding,the PCard= " + encodeResult);
  1460.                 status = "success";
  1461.  
  1462.         } catch (Throwable e) {
  1463.                 status = "failed";
  1464.                 if (_DEBUG)
  1465.                         System.out.println("executeEncryptPCard: error " + e.toString());
  1466.         }
  1467.  
  1468.         o_opstatus.setData("result", status);
  1469.  
  1470.         return encodeResult;
  1471. }
  1472. public String executeGetAdminUserEmailAddr(
  1473.         String dn,
  1474.         String inAttrId,
  1475.         Element o_opstatus)
  1476.         throws com.extricity.adapter.api.ISException {
  1477.  
  1478.         String output_email_addr = null;
  1479.         String errorCode = "";
  1480.         com.ibm.epic.directory.EpicDirectory directory = null;
  1481.         try {
  1482.                 directory = new com.ibm.epic.directory.EpicDirectory();
  1483.         } catch (Exception e) {
  1484.                 output_email_addr = "";
  1485.                 errorCode = "setUpError";
  1486.                 if (_DEBUG) {
  1487.                         System.out.println("executeGetAdminUserEmailAddr: LDAP set up error occurred ");
  1488.  
  1489.                 }
  1490.  
  1491.         }
  1492.  
  1493.         // no LDAP set up error
  1494.         if (errorCode != null && errorCode.length() == 0) {
  1495.  
  1496.                 try {
  1497.                         String[] retAttrs = {inAttrId};
  1498.                         Attributes attributes = null;
  1499.                         // finding all the admin user entries
  1500.  
  1501.                         StringBuffer mailAddr = new StringBuffer();
  1502.  
  1503.                         attributes = directory.read(dn, retAttrs);
  1504.  
  1505.                         if (_DEBUG) {
  1506.                                 System.out.println(
  1507.                                         "executeGetAdminUserEmailAddr:: attributes list " + attributes.toString());
  1508.                         }
  1509.                         NamingEnumeration attrlist = directory.getAttributeList(attributes);
  1510.                         while (attrlist.hasMore()) {
  1511.                                 Attribute tempAttr = (Attribute) attrlist.nextElement();
  1512.                                 Enumeration attrValueList = directory.getAttributeValueList(tempAttr);
  1513.                                 // only retrieve the value of the mail attribute
  1514.                                 while (attrValueList.hasMoreElements()) {
  1515.                                         String attrValue = (String) attrValueList.nextElement();
  1516.  
  1517.                                         mailAddr.append(attrValue);
  1518.                                         mailAddr.append(",");
  1519.                                 }
  1520.  
  1521.                         }
  1522.  
  1523.                         errorCode = "found";
  1524.                         output_email_addr = mailAddr.substring(0, mailAddr.length() - 1);
  1525.                         if (_DEBUG) {
  1526.                                 System.out.println(
  1527.                                         "executeGetAdminUserEmailAddr:: found the email address " + output_email_addr);
  1528.                         }
  1529.  
  1530.                 } catch (Exception e) {
  1531.                         errorCode = "notFound";
  1532.                         output_email_addr = "";
  1533.                         if (_DEBUG) {
  1534.                                 System.out.println(
  1535.                                         "executeGetAdminUserEmailAddr:: not found any email address " + e.getMessage());
  1536.                         }
  1537.                 } finally {
  1538.                         try {
  1539.                                 directory.close();
  1540.                         } catch (Exception e) {
  1541.                                 //ignore if cannot close the directory context
  1542.                         }
  1543.                 }
  1544.         }
  1545.         o_opstatus.setData("result", errorCode);
  1546.  
  1547.         return output_email_addr;
  1548. }public Vector executeReadResponseProperties(String processID, String baseFileName, String language, String cntryCode, String status)
  1549.  throws com.extricity.adapter.api.ISException{
  1550. Vector resp = new Vector();
  1551. try{
  1552.         System.out.println("Input values are : ");
  1553.         System.out.println("\t ProcessID - " + processID);
  1554.         System.out.println("\t basefile name - " + baseFileName);
  1555.         System.out.println("\t language - " + language);
  1556.         System.out.println("\t cntry code - " + cntryCode);
  1557.         System.out.println("\t status - " + status);
  1558.  
  1559.  
  1560.         java.util.ResourceBundle bundle = ResourceBundle.getBundle(PAMResponse_base, new java.util.Locale(language.trim(), cntryCode.trim()));
  1561.         //java.util.ResourceBundle bundle = ResourceBundle.getBundle("PAMResponse", new java.util.Locale("de", "de"));
  1562.  
  1563.  
  1564.  
  1565.         String code = bundle.getString(status);
  1566.         String text = bundle.getString(code);
  1567.         String data = bundle.getString(code+"Data");
  1568.  
  1569.         resp.addElement(code);
  1570.         resp.addElement(text);
  1571.         resp.addElement(data);
  1572.  
  1573.         System.out.println("Results read are : " + resp.toString());
  1574.         return resp;
  1575. } catch(Exception e)
  1576.  
  1577. {
  1578.         // Exception occured and unable to retrieve the information from properties file
  1579.         System.out.println("Unable to retrieve response information from property file. Details :");
  1580.         System.out.println(e.toString());
  1581.         // logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  1582.         return resp;
  1583. }
  1584. }public boolean executeSendMail(
  1585.         String processID,
  1586.         String mailserver,
  1587.         String recipient,
  1588.         String sender,
  1589.         String subject,
  1590.         String msgtext)
  1591.         throws com.extricity.adapter.api.ISException {
  1592.         boolean debug = false;
  1593.         boolean rtnValue = false;
  1594.  
  1595.         //Set the host smtp address
  1596.         try {
  1597.                 Properties props = System.getProperties();
  1598.                 System.out.println("Contents of props : " + props.toString());
  1599.                 props.put("mail.smtp.host", mailserver);
  1600.  
  1601.                 // create some properties and get the default Session
  1602.                 Session session = Session.getDefaultInstance(props, null);
  1603.                 session.setDebug(debug);
  1604.                 System.out.println("session passed");
  1605.  
  1606.                 // create a message
  1607.                 Message msg = new MimeMessage(session);
  1608.  
  1609.                 // set the from and to address
  1610.                 InternetAddress addressFrom =
  1611.                         new InternetAddress(sender);
  1612.                 msg.setFrom(addressFrom);
  1613.  
  1614.                 StringTokenizer st = new StringTokenizer(recipient, ",");
  1615.                 InternetAddress[] addressTo;
  1616.  
  1617.                 addressTo = new InternetAddress[st.countTokens()];
  1618.                 for (int i = 0; i <= st.countTokens(); i++) {
  1619.                         String currString = (String) st.nextElement();
  1620.                         addressTo[i] = new InternetAddress(currString);
  1621.                 }
  1622.  
  1623.                 msg.setRecipients(Message.RecipientType.TO, addressTo);
  1624.  
  1625.                 // Setting the Subject and Content Type
  1626.                 msg.setSubject(subject);
  1627.                 msg.setContent(msgtext, "text/plain");
  1628.  
  1629.                 msg.saveChanges(); // implicit with send()
  1630.                 Transport transport = session.getTransport("smtp");
  1631.                 transport.connect(mailserver, "", "");
  1632.                 transport.sendMessage(msg, msg.getAllRecipients());
  1633.                 transport.close();
  1634.  
  1635.                 rtnValue = true;
  1636.         } catch (Exception e) {
  1637.                 rtnValue = false;
  1638.                 System.out.println("Unable to send mail. Details :");
  1639.                 System.out.println(e.toString());
  1640.                 // logException(processID,"Adapter",e.toString(),ADAPTER_EXCEPTION,"NONE");
  1641.         }
  1642.         return rtnValue;
  1643. }}
  1644.