home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Java / Java.zip / mqaoad21.zip / MQNMRFH2FormatterExt.java < prev    next >
Encoding:
Java Source  |  2003-01-13  |  11.9 KB  |  358 lines

  1. package com.ibm.extricity.adapters.mqseries.mqak;
  2.  
  3. /**
  4.  * MQNMRFH2FormatterExt.java 1.0        10/20/2000
  5.  *
  6.  * The MQNMRFH2FormatterExt is derived from <EM>MQNMRFH2Formatter</EM> class.
  7.  * This class is used to extend the RFH2 Header Formater for use with Extricity
  8.  *
  9.  * OCO Source Materials
  10.  *
  11.  * 5799-RNK
  12.  *
  13.  * (C) Copyright IBM Corp. 2000
  14.  *
  15.  * The source code for this program is not published
  16.  * or otherwise divested of its trade secrets,
  17.  * irrespective of what has been deposited with the
  18.  * U. S. Copyright Office.
  19.  *
  20.  * @author Thomas W. Jaworski
  21. **/
  22. import java.io.*;
  23. import com.ibm.epic.adapters.eak.nativeadapter.*;
  24. import com.ibm.epic.adapters.eak.common.*;
  25. import com.ibm.logging.*;
  26. import com.ibm.mq.*;
  27. import com.ibm.epic.adapters.eak.mcs.*;
  28.  
  29. public class MQNMRFH2FormatterExt extends com.ibm.epic.adapters.eak.nativeadapter.MQNMRFH2Formatter
  30. {
  31.  
  32. /**
  33.  * This makes a MQMessage with the body data contained in an RFH2 header.
  34.  *
  35.  * @param epicMessageExt The input message to generate the MQMessage from
  36.  *
  37.  * @return The MQMessage to send using MQ.
  38.  *
  39.  * @see retrieveMessage
  40.  *
  41.  * @exception AdapterException thrown if the bodyData cannot be set into the message
  42.  */
  43. public MQMessage convertMessage( EpicMessage epicMessageOrg )
  44.    throws AdapterException
  45. {
  46.    // Make sure we have the extended EpicMessage
  47.    if(!(epicMessageOrg instanceof EpicMessageExt))
  48.    {
  49.           return super.convertMessage(epicMessageOrg);
  50.    }
  51.  
  52.    EpicMessageExt epicMessage = (EpicMessageExt)epicMessageOrg;
  53.  
  54.    if (trace)
  55.           traceClient.writeTrace(IRecordType.TYPE_ENTRY, CLASS_NAME,
  56.                                                 "convertMessage(EpicMessage)", "AQM5001",
  57.                                                 AdapterUtil.DEFAULTTRACEMSGFILE,
  58.                                                 new Object[]{"AQM5001"});
  59.    MQMessage mqMessage = null;
  60.    RFH2Header rfh;
  61.  
  62.    /* if trace is on then call the 1 arg constructor, so it will trace also */
  63.    if (trace)
  64.          rfh = new RFH2Header(getApplicationName());
  65.    else
  66.          rfh = new RFH2Header();
  67.  
  68.    String tmp = null;
  69.  
  70.    tmp = epicMessage.getSourceLogicalID();
  71.    if(tmp != null && tmp.length() != 0)
  72.           rfh.addUSRValue("SourceLogicalID", tmp);
  73.  
  74.    tmp = epicMessage.getDestinationLogicalID();
  75.    if(tmp != null && tmp.length() != 0)
  76.           rfh.addUSRValue("DestinationLogicalID", tmp);
  77.  
  78.    tmp = epicMessage.getMsgType();
  79.    if(tmp != null && tmp.length() != 0)
  80.           rfh.addUSRValue("MessageType", tmp);
  81.  
  82.    tmp = epicMessage.getRespondToLogicalID();
  83.    if(tmp != null && tmp.length() != 0)
  84.           rfh.addUSRValue("RespondToLogicalID", tmp);
  85.  
  86.    rfh.addUSRValue("TimeStampCreated",
  87.           Long.toString(epicMessage.getTimeStamp()));
  88.  
  89.    rfh.addUSRValue("TimeStampExpired",
  90.           Long.toString(epicMessage.getExpirationTimeStamp()));
  91.  
  92.    tmp = epicMessage.getTransactionID();
  93.    if(tmp != null && tmp.length() != 0)
  94.           rfh.addUSRValue("TransactionID", tmp);
  95.  
  96.    tmp = epicMessage.getUniqueMsgID();
  97.    if(tmp != null && tmp.length() != 0)
  98.           rfh.addUSRValue("UniqueID", tmp);
  99.  
  100.    tmp = epicMessage.getProcessingCategory();
  101.    if(tmp != null && tmp.length() != 0)
  102.           rfh.addUSRValue("ProcessingCategory", tmp);
  103.  
  104.    tmp = epicMessage.getBodyCategory();
  105.    if(tmp != null && tmp.length() != 0)
  106.           rfh.addUSRValue("BodyCategory", tmp);
  107.  
  108.    tmp = epicMessage.getBodyType();
  109.    if(tmp != null && tmp.length() != 0)
  110.           rfh.addUSRValue("BodyType", tmp);
  111.  
  112.    tmp = epicMessage.getBodySecondaryType();
  113.    if(tmp != null && tmp.length() != 0)
  114.           rfh.addUSRValue("BodySecondaryType", tmp);
  115.  
  116.    tmp = epicMessage.getAckRequested();
  117.    if(tmp != null && tmp.length() != 0)
  118.           rfh.addUSRValue("AckRequested", tmp);
  119.  
  120.    //  Put all fields into the <usr> folder
  121.    tmp = epicMessage.getUserArea();
  122.    if(tmp != null && tmp.length() != 0)
  123.           rfh.addUSRValue("UserArea", tmp);
  124.  
  125.    tmp = epicMessage.getMsgHeaderVersion();
  126.    if(tmp != null && tmp.length() != 0)
  127.           rfh.addUSRValue("MsgHeaderVersion", tmp);
  128.  
  129.    tmp = epicMessage.getCorrelationID();
  130.    if(tmp != null && tmp.length() != 0)
  131.           rfh.addUSRValue("CorrelationID", tmp);
  132.  
  133.    tmp = epicMessage.getGroupStatus();
  134.    if(tmp != null && tmp.length() != 0)
  135.           rfh.addUSRValue("GroupStatus", tmp);
  136.  
  137.    tmp = epicMessage.getQosPolicy();
  138.    if(tmp != null && tmp.length() != 0)
  139.           rfh.addUSRValue("QOSPolicy", tmp);
  140.  
  141.    tmp = epicMessage.getDeliveryCategory();
  142.    if(tmp != null && tmp.length() != 0)
  143.           rfh.addUSRValue("DeliveryCategory", tmp);
  144.  
  145.    tmp = epicMessage.getPublicationTopic();
  146.    if(tmp != null && tmp.length() != 0)
  147.           rfh.addUSRValue("PublicationTopic", tmp);
  148.  
  149.    tmp = epicMessage.getSessionID();
  150.    if(tmp != null && tmp.length() != 0)
  151.           rfh.addUSRValue("SessionID", tmp);
  152.  
  153.    rfh.addUSRValue("EncryptionStatus",
  154.           (new Boolean(epicMessage.getEncryptionStatus()).toString()));
  155.  
  156.    tmp = epicMessage.getBodyData();
  157.    if(tmp != null && tmp.length() != 0)
  158.           rfh.setData(tmp);
  159.  
  160.    boolean xmlflag = MQAOXMLIJ.isXML(epicMessage.getBodyData());
  161.    if(xmlflag)
  162.    {
  163.           rfh.setMcd_msd("XML");
  164.           rfh.setMcd_format("XML");
  165.    }
  166.  
  167.    mqMessage = rfh.formatMQMessage_RFH2Header();
  168.  
  169.    rfh.close(); // @P1C
  170.  
  171.    if(epicMessage.getLMSMessageID() == epicMessage.LMS_MESSAGE_ID_NONE)
  172.    {
  173.           mqMessage.messageId = MQC.MQMI_NONE;
  174.    }
  175.    else
  176.    {
  177.           mqMessage.messageId = epicMessage.getByteArrLMSMessageID();
  178.    }
  179.  
  180.    if(epicMessage.getCorrelationID() == epicMessage.LMS_CORELATION_ID_NONE)
  181.    {
  182.           mqMessage.correlationId = MQC.MQCI_NONE;
  183.    }
  184.    else
  185.    {
  186.           mqMessage.correlationId = epicMessage.getByteArrLMSCorrelationID();
  187.    }
  188.  
  189.    if (trace)
  190.           traceClient.writeTrace(IRecordType.TYPE_EXIT, CLASS_NAME,
  191.                                                 "convertMessage(EpicMessage)", "AQM5002",
  192.                                                 AdapterUtil.DEFAULTTRACEMSGFILE,
  193.                                                 new Object[]{"AQM5002"});
  194.    return mqMessage;
  195. }
  196.  
  197. /**
  198.  * The method takes a received MQMessage and generates an EpicMessage from it.
  199.  * The message must be in the correct format, as generated by <CODE>formatMessage</CODE>.
  200.  *
  201.  * @param mqMessage the raw message received from a remote adapter
  202.  * @param addr This parameter is ignored since all header information is present in the MQMessage.
  203.  *
  204.  * @return The epic message generated from the received message
  205.  *
  206.  * @exception AdapterException thrown if the message data cannot be read or if
  207.  * the message is not String format
  208.  */
  209. public EpicMessage convertMessage( MQMessage mqMessage, MQAOAddress addr )
  210.           throws AdapterException {
  211.    EpicMessageExt em = null;
  212.  
  213.    if (trace)
  214.           traceClient.writeTrace(IRecordType.TYPE_ENTRY, CLASS_NAME,
  215.                                                 "convertMessage(MQMessage)", "AQM5001",
  216.                                                 AdapterUtil.DEFAULTTRACEMSGFILE,
  217.                                                 new Object[]{"AQM5001"});
  218.  
  219.    int msg_length = mqMessage.getTotalMessageLength();
  220.  
  221.    if (trace)
  222.           traceClient.writeTrace(IRecordType.TYPE_INFO, CLASS_NAME,
  223.                                                 "convertMessage(MQMessage)", "AQM5003", AdapterUtil.DEFAULTTRACEMSGFILE,
  224.                                                 new Object[]{"AQM5003","message length", new Integer(msg_length)});
  225.  
  226.    if(msg_length < 1) return em;
  227.  
  228.    if (!mqMessage.format.equals(RFH2Header.MQFMT_RF_HEADER_2))
  229.    {
  230.           AdapterException ae = new AdapterException("AQM0114",
  231.                  new Object[]{"AQM0114",
  232.                                   (CLASS_NAME + "::convertMessage(MQMessage)"),
  233.                                   RFH2Header.MQFMT_RF_HEADER_2,
  234.                                   mqMessage.format,
  235.                                   ""});
  236.  
  237.           if (trace)
  238.                  traceClient.writeTrace(IRecordType.TYPE_ERROR_EXC, CLASS_NAME,
  239.                                                 "convertMessage(MQMessage)", "AQM5011",
  240.                                                 AdapterUtil.DEFAULTTRACEMSGFILE,
  241.                                                 new Object[]{ "AQM5011",ae.getClass().getName(),
  242.                                                                   ae.getMessage(),""});
  243.  
  244.           throw ae;
  245.    }
  246.  
  247.    RFH2Header rfh;
  248.  
  249.    /* if trace is on then call the 1 arg constructor, so it will trace also */
  250.    if (trace)
  251.          rfh = new RFH2Header(getApplicationName());
  252.    else
  253.          rfh = new RFH2Header();
  254.  
  255.    rfh.parseRFH2(mqMessage);
  256.  
  257.  
  258.    if (trace)
  259.           traceClient.writeTrace(IRecordType.TYPE_INFO, CLASS_NAME,
  260.                                                 "convertMessage(MQMessage)", "AQM5003", AdapterUtil.DEFAULTTRACEMSGFILE,
  261.                                                 new Object[]{"AQM5003","RFH2Header", rfh});
  262.  
  263.    String srcid = (String)rfh.getUSRValue("SourceLogicalID");
  264.    String tmp = (String)rfh.getUSRValue("MessageType");
  265.  
  266.    em = new EpicMessageExt(srcid, tmp);
  267.  
  268.    if(mqMessage.messageId == MQC.MQMI_NONE)
  269.    {
  270.           em.setLMSMessageID(em.LMS_MESSAGE_ID_NONE);
  271.           ((ENAService)addr).setLastLMSMessageID(em.LMS_MESSAGE_ID_NONE);
  272.    }
  273.    else
  274.    {
  275.           em.setLMSMessageID(mqMessage.messageId);
  276.           ((ENAService)addr).setLastLMSMessageID(em.getLMSMessageID());
  277.    }
  278.  
  279.    if(mqMessage.correlationId == MQC.MQCI_NONE)
  280.    {
  281.           em.setLMSCorrelationID(em.LMS_CORELATION_ID_NONE);
  282.           ((ENAService)addr).setLastLMSCorrelationID(em.LMS_CORELATION_ID_NONE);
  283.    }
  284.    else
  285.    {
  286.           em.setLMSCorrelationID(mqMessage.correlationId);
  287.           ((ENAService)addr).setLastLMSCorrelationID(em.getLMSCorrelationID());
  288.    }
  289.  
  290.    em.setRespondToLogicalID((String)rfh.getUSRValue("RespondToLogicalID"));
  291.  
  292.    em.setDestinationLogicalID((String)rfh.getUSRValue("DestinationLogicalID"));
  293.  
  294.    try
  295.    {
  296.            Long ts = new Long((String)rfh.getUSRValue("TimeStampCreated"));
  297.            em.setTimeStamp(ts.longValue());
  298.    }
  299.    catch(Exception e)
  300.    {
  301.    }
  302.  
  303.    try
  304.    {
  305.            Long ets = new Long((String)rfh.getUSRValue("TimeStampExpired"));
  306.            em.setExpirationTimeStamp(ets.longValue());
  307.    }
  308.    catch(Exception e)
  309.    {
  310.    }
  311.  
  312.    em.setTransactionID((String)rfh.getUSRValue("TransactionID"));
  313.  
  314.    em.setUniqueMsgID((String)rfh.getUSRValue("UniqueID"));
  315.  
  316.    em.setProcessingCategory((String)rfh.getUSRValue("ProcessingCategory"));
  317.  
  318.    em.setBodyCategory((String)rfh.getUSRValue("BodyCategory"));
  319.  
  320.    em.setBodyType((String)rfh.getUSRValue("BodyType"));
  321.  
  322.    em.setBodySecondaryType((String)rfh.getUSRValue("BodySecondaryType"));
  323.  
  324.    em.setAckRequested((String)rfh.getUSRValue("AckRequested"));
  325.  
  326.    em.setUserArea((String)rfh.getUSRValue("UserArea"));
  327.  
  328.    em.setMsgHeaderVersion((String)rfh.getUSRValue("MsgHeaderVersion"));
  329.  
  330.    em.setCorrelationID((String)rfh.getUSRValue("CorrelationID"));
  331.  
  332.    em.setGroupStatus((String)rfh.getUSRValue("GroupStatus"));
  333.  
  334.    em.setQosPolicy((String)rfh.getUSRValue("QOSPolicy"));
  335.  
  336.    em.setDeliveryCategory((String)rfh.getUSRValue("DeliveryCategory"));
  337.  
  338.    em.setPublicationTopic((String)rfh.getUSRValue("PublicationTopic"));
  339.  
  340.    em.setSessionID((String)rfh.getUSRValue("SessionID"));
  341.  
  342.    Boolean encStat = new Boolean((String)rfh.getUSRValue("EncryptionStatus"));
  343.    em.setEncryptionStatus(encStat.booleanValue());
  344.  
  345.    em.setBodyData(rfh.getData());
  346.  
  347.    rfh.close(); // @P1C
  348.  
  349.    if (trace)
  350.           traceClient.writeTrace(IRecordType.TYPE_EXIT, CLASS_NAME,
  351.                                                 "convertMessage(MQMessage)", "AQM5002",
  352.                                                 AdapterUtil.DEFAULTTRACEMSGFILE,
  353.                                                 new Object[]{"AQM5002"});
  354.  
  355.    return em;
  356. }
  357. }
  358.