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

No comments:

Post a Comment