Monday, 3 October 2016

Backup Of Input Message

Step1:
Create a Message flow like below
MQInputNode---->JavaComputeNode----->MQOutputNode


Step2:
Write the below code in JCN

//Make a modifiable MbMessage based on the input message passed in on the inAssembly.

MbMessage InMessage = new MbMessage(inAssembly.getMessage());

//Now partially parse the input message one record at a time.
MbElement inputRootElement = InMessage.getRootElement();//root
MbElement inputPropertiesElement = inputRootElement.getFirstElementByPath("Properties");//properties
MbElement inputMQMDElement = inputRootElement.getFirstElementByPath("MQMD");//mqmd
MbElement inputXMLNSCElement = inputRootElement.getFirstElementByPath("XMLNSC");//xmlnsc

MbElement inputXMLNSCRootTagElement = inputXMLNSCElement.getFirstChild(); 
//Child(Root tag of Input

 // Create a new output message for the record that we are going to be propagate.
 MbMessage outputMessage = new MbMessage();
outAssembly = new MbMessageAssembly(inAssembly, outputMessage);

//Create new parsers folders in the output message.
 MbElement outputRootElement = outputMessage.getRootElement();//root
 MbElement outputPropertiesElement = outputRootElement.createElementAsLastChild(inputPropertiesElement.getParserClassName());//properties
MbElement outputMQMDElement = outputRootElement.createElementAsLastChild(inputMQMDElement.getParserClassName());//mqmd
MbElement outputXMLNSCElement = outputRootElement.createElementAsLastChild(inputXMLNSCElement.getParserClassName());   //xmlnsc
MbElement BACKUP=outputMessage.getRootElement().createElementAsLastChild(MbElement.TYPE_NAME, "BackUp", null);//New tag in xmlnsc
 
//Create the root tag in the output XMLNSC folder that will be used for this output record.
//  MbElement outputXMLNSCRootTag = inputXMLNSCRootTagElement.createElementAsLastChild(MbElement.TYPE_NAME, "BackUp", null);

//MbElement Payload = outputMessage.getRootElement().getLastChild();
// outputXMLNSCRootTag.addAsFirstChild(outputXMLNSCElement.copy());
 
//Copy the Properties Folder, MQMD header, and the current record.
 outputPropertiesElement.copyElementTree(inputPropertiesElement);//Properties
 
outputMQMDElement.copyElementTree(inputMQMDElement);//mqmd
 
 outputXMLNSCElement.copyElementTree(inputXMLNSCElement); //xmlnsc
 
 BACKUP.copyElementTree(inputXMLNSCElement);//backup
//  MbElement Payload = outputMessage.getRootElement().getLastChild();
// outputRootElement.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BackUp",Payload.copy().getValue());  
 
//Propagate this message, requesting that the output message assembly be cleared after propagation.
out.propagate(outAssembly);

Step3:-
Place the below test Message
<Details><Summary><Name>Bhanu</Name><Designation>Technical Lead</Designation><Domain>EAI</Domain><Location>Vishakapatnam</Location></Summary></Details>

Observe the Obtained Output as below

Monday, 26 September 2016

Exception_Email_Notification

Flow:-

MQInput Node Properties:-


Email Ouput Node Properties 



ParseExceptionMessage:-

CREATE COMPUTE MODULE ExceptionHandling_Compute
    CREATE FUNCTION Main() RETURNS BOOLEAN
    BEGIN
         CALL CopyMessageHeaders();
        -- CALL CopyEntireMessage();
       
       
        DECLARE ptrException REFERENCE TO InputExceptionList.*[1];
             DECLARE messageNumber,eText,description,Loc,flowname CHARACTER;
       
         WHILE LASTMOVE(ptrException) DO
            -- store the current values for the error number and text
            IF ptrException.Number IS NOT NULL THEN
                 SET messageNumber = ptrException.Number;
               
                 IF ptrException.Text <> '' THEN
                     IF description<> '' THEN
                        SET description = description || ',' || ' '||ptrException.Text;
                    ELSE
                         SET description = ptrException.Text;
                    END IF;
                END IF;
               
              IF LENGTH(ptrException.Label)>0 THEN
                      SET Loc=ptrException.Label;   
              END IF;
              END IF;
              -- now move to the last child which should be the next exceptionlist
            MOVE ptrException LASTCHILD;
        END WHILE;
       
        SET description = description ||': ' ||ptrException;
        set eText = ptrException;
        if CONTAINS(description,'Failed to open Queue') then
            set eText = 'Failed to open Output queue';
            END if;
        If CONTAINS(description,'WTX exception') then
            DECLARE CRLF CHARACTER CAST(X'0D0A09' AS CHAR CCSID 1208);
            set eText = REPLACE(eText, CRLF, '');
        END IF;   
       
          SET  flowname=SUBSTRING(Loc  FROM  0  FOR  POSITION('.'  IN Loc REPEAT-1));
         

        SET OutputRoot.XMLNSC = NULL;
       
       
        SET OutputRoot.XMLNSC.ERRORLOG.TimeStamp = CURRENT_TIMESTAMP;
        SET OutputRoot.XMLNSC.ERRORLOG.FlowName = flowname;
        SET OutputRoot.XMLNSC.ERRORLOG.ErrorCode = messageNumber;
        SET OutputRoot.XMLNSC.ERRORLOG.ErrorText = eText;
        SET OutputRoot.XMLNSC.ERRORLOG.ErrorDescription = description;
       
        --Uncomment the below code to Override Email Configuration
       
        -- Add recipient information to the EmailOutputHeader
        --SET OutputRoot.EmailOutputHeader.To = 'bhanu7miralce@gmail.com';
        --SET OutputRoot.EmailOutputHeader.Cc = 'kota.bhanumurty@gmail.com';
        --SET OutputRoot.EmailOutputHeader.Bcc = '<recipient email address>';

        -- Add sender information to EmailOutputHeader
        --SET OutputRoot.EmailOutputHeader.From = '
kota.bhanumurty@gmail.com';
        --SET OutputRoot.EmailOutputHeader."Reply-To" = '<reply email address>';

        -- Add subject to EmailOutputHeader
        --SET OutputRoot.EmailOutputHeader.Subject = 'Replaced by ESQL compute node.';

        -- Add SMTP server information to the LocalEnvironment
        --SET OutputLocalEnvironment.Destination.Email.SMTPServer ='';

        -- Create a new message body, which will be sent as the main text of the email.
        --SET OutputRoot.BLOB.BLOB = CAST('This is the new text for the body of the email.' AS BLOB CCSID 1208);
       
        RETURN TRUE;
    END;

    CREATE PROCEDURE CopyMessageHeaders() BEGIN
        DECLARE I INTEGER 1;
        DECLARE J INTEGER;
        SET J = CARDINALITY(InputRoot.*[]);
        WHILE I < J DO
            SET OutputRoot.*[I] = InputRoot.*[I];
            SET I = I + 1;
        END WHILE;
    END;

    CREATE PROCEDURE CopyEntireMessage() BEGIN
        SET OutputRoot = InputRoot;
    END;
END MODULE;


Exception from Try that will be caught in Catch:-

 After ParseExceptionMessage:-



 Make Below Configurations at

C:\Program Files\IBM\MQSI\9.0.0.0>mqsicreateconfigurableservice IB9NODE -c SMTP
-o MYEMAILSERVER

BIP8071I: Successful command completion.

C:\Program Files\IBM\MQSI\9.0.0.0>mqsichangeproperties IB9NODE -c SMTP -o MYEMAI
LSERVER -n serverName -v <<serverName>>
BIP8071I: Successful command completion.

C:\Program Files\IBM\MQSI\9.0.0.0>mqsisetdbparms IB9NODE -n smtp::EmailIdentity
-u <<EmailId>> -p <<Password>>
BIP8071I: Successful command completion.

C:\Program Files\IBM\MQSI\9.0.0.0>mqsichangeproperties IB9NODE -c SMTP -o MYEMAI
LSERVER -n securityIdentity -v EmailIdentity
BIP8071I: Successful command completion.