cancel
Showing results for 
Search instead for 
Did you mean: 

Module Adapter - String Change in XML

Former Member
0 Kudos

Module Adapter

I have been reading "How to Create Modules for the J2EE Adapter Engine" and am trying to implement an adapter module to change a few strings in the message.

I understand I can grab the XI message using the getPrincipalData such as:

// get the XI message from the environment

Message msg = (Message) inputModuleData.getPrincipalData();

and return the message using:

// provide the XI message for returning

inputModuleData.setPrincipalData(msg);

What is the proper method of searching for strings inside this message and changing a value. We have tried the approach of using XSLT and Java maps to change values but the items we need to change need to occur at the adapter level. Any sample code around changing payload information in an adapter module would be appreciated.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks for all the info.

Does anyone have example code of using SAX in an adapter module? In addition is it possible to test the adapter module before publishing with SDM?

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

Just do a Google on how SAX parser works. You will find many documents on the same. Build the logic over this in your Adapter Module.

Testing your module codewould be simple. Just create a Main() method in your java class and callthe corresponding methods of the class.

Regards,

Bhavesh

former_member91687
Active Contributor
0 Kudos

Hi,

The methods which you use with SAX parser are:

1) Start of the document(startDocument)

2) start of the element(startElement)

3) end of the element(endElement)

4) end of the document(endDocument)

5) chars()

Build your logic using these. These blogs should help you in the process:

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii

You could write the java code in the process method of your bean or you could call the class from the process method.

What exactly do you mead by testng the adapter module? You could test your the java code i.e the SAX parser as you would test any standalone java code. You would be using the same in your bean.

Regards,

Chandra

0 Kudos

Hi,

I just published a blog titled <a href="/people/thorsten.nordholmsbirk/blog/2006/08/10/using-jaxp-to-both-parse-and-emit-xml-in-xi-java-mapping-programs">Using JAXP to both parse and emit XML in XI Java mapping programs</a>, detailing the use of JAXP in mapping programs. The techniques are fully applicable to adapter modules as well.

Regards,

Thorsten

Answers (1)

Answers (1)

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

If your Source to the Adapter Module is an XML , then you can use the following piece of code to change the same into an InputStream.

If you want to manipulate on the Source XML, then you can Parse this input stream using DOM / SAX to do whatever validation you want.

obj = imd.getPrincipalData();
msg = (Message) obj;
XMLPayload xp = msg.getDocument();
InputStream in=xp.getInputStream(),

Regards,

Bhavesh

former_member91687
Active Contributor
0 Kudos

Hi,

Create an object for the XMLPayload and use this to get the payload input as a stream, use this as a parameter and do the manipulations you want to do on the payload and get the output as an outputstream and send it back to Payload by setContent method.

Regards,

Chandra

Former Member
0 Kudos

Hi,

Please take this eg. good description of adapter module:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3bdc14e1-0901-0010-b5a9-a01...

Regards

Vijaya

Message was edited by: vijaya kumari