cancel
Showing results for 
Search instead for 
Did you mean: 

JMS Adapter module content conversion

Former Member
0 Kudos

Hi,

I'm developing a module for the jms adapter(sender). My requirement is to parse the XI message(text) using some XML parsing api and do some formatting, logic etc and to make the jms adapter create a xml file with the processed information. Jms File Content Conversion does not suit our requirement and thats the reason we are trying this option.

My understanding is: Access the payload in the "process" method of the local ejb, apply XML parsing using JDOM etc, make a xml which should be the output of the jms adapter. This xml will be the xml with my user defined tag elements after content conversion. Can i form this xml and assign to the inputModuleData? Will the jms adapter use this string to create the xml and send to IS? Are there any other parameters to be set or processes to be done?

Also in which sequence should I put my adapter module in communication channel.

================================================

My code snippet:

public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)

throws ModuleException

{

Object obj = null; // Handler to get Principle data

Message msg = null; // Handler to get Message object

try

{

obj = inputModuleData.getPrincipalData();

msg = (Message)obj;

AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(),AuditDirection.INBOUND);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"sample: Inside sample Module---efore reading payload");

try

{

XMLPayload xmlpayload = msg.getDocument();

String messageStr = xmlpayload.getText();

String inputStr = null;

String tags[] = new String[2];

String values[] = new String[2];

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"sample: Inside sample Module---before content conversion");

String tagvalue1 = messageStr.substring(messageStr.indexOf("BEGIN+"), messageStr.indexOf("'");

String tagvalue2 = messageStr.substring(messageStr.indexOf("'"), messageStr.lastindexOf("ENDING");

tags[0] = "tag1";

tags[1] = "tag2";

values[0] = tagvalue1 ;

values[1] = tagvalue2 ;

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"sample: Inside sample Module---after content conversion");

Document xmldoc = null;

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

DOMImplementation impl = builder.getDOMImplementation();

org.w3c.dom.Element e = null;

Node n = null;

xmldoc = impl.createDocument(null, "MT940", null);

org.w3c.dom.Element root = xmldoc.getDocumentElement();

for(int i = 0; i < tags.length; i++)

{

e = xmldoc.createElementNS(null, tags<i>);

n = xmldoc.createTextNode(values<i>);

e.appendChild(n);

root.appendChild(e);

}

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"sample: Inside sample Module---before dom creation");

DOMSource domSource = new DOMSource(xmldoc);

ByteArrayOutputStream myBytes = new ByteArrayOutputStream();

Result dest = new StreamResult(myBytes);

TransformerFactory tf = TransformerFactory.newInstance();

Transformer serializer = tf.newTransformer();

serializer.setOutputProperty("indent", "yes");

serializer.transform(domSource, dest);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"sample: Inside sample Module---before setting principal data");

byte[] docContent = myBytes.toByteArray();

if (docContent != null) {

xmlpayload.setContent(docContent);

inputModuleData.setPrincipalData(msg);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"sample: Inside sample Module---after setting principal data");

}

}

}

catch(ArrayIndexOutOfBoundsException e)

{

e.printStackTrace();

}

catch(StringIndexOutOfBoundsException e)

{

e.printStackTrace();

}

catch(TransformerException e)

{

e.printStackTrace();

}

catch(Exception e)

{

e.printStackTrace();

}

}

catch(Exception e)

{

ModuleException me = new ModuleException(e);

throw me;

}

return inputModuleData;

}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rachit !

The sequence of your module depends on the input required by your module, and the output you are expecting to throw. Of course it will be before the CallSapAdapter. You can also try to manipulate the data and combine your input or output with the jms adapter modules to simplify your solution. This is for the sender o receiver channel?

Regards,

Matias.

Former Member
0 Kudos

This is for sender channel. The doubt in adapter module is in the process block how will I get the main data being read by the jms adapter from the text file.As I am reading text file from websphere MQ, the content of the text file can be obtained thru xmlpayload.getText() or is there any other way.

obj = inputModuleData.getPrincipalData();

msg = (Message)obj;

XMLPayload xmlpayload = msg.getDocument();

String messageStr = xmlpayload.getText();

At present I am using my adapter module before call sap adapter, but before sap adapter there are two other modules(toBinary and to Xmb), so shld I place it before both or after both the modules.

Thanx in advance

Rachit