Skip to end of metadata
Go to start of metadata

I came across a scenario where the complete input xml payload itself needs to be mapped to a field of the target xml.  Can this be done using the standard Graphical Mapping? The answer is NO. This requires the process of reading the XML payload and convert it to a string. Java mapping can do the job where in the complete XML is always passed to the execute() function. Now the challenge here is to convert the InputStream of the Payload to a String, which I have found out a solution with this code snippet.

S2S ( Steps to Solution):

1. Pass the payload to Java Mapping Program.

2. Read the payload and convert it to a string.

3. Create the target structure in the java Mapping and assign the string payload value to the target field.

With all this idea I will demonstrate this scenario with a simple source structure as shown below.

Source Structure:




Target Structure:

The target structure has only one field which stores the XML payload.



Java Mapping:

This is the Java code that is used to read the inbound xml and convert it to string. Two important things in this code is

1. Conversion of the InputStream to String using the BufferedReader and StringBuffer class.

2. Creation of the target node structure using createElement() and createTextNode() DOM functions.

Export this Java Mapping as a Jar file using NWDS.

Imported Archive:

Import the Jar file created using the NWDS in to the IR.
Interface Mapping:



In the Interface mapping select the Mapping Program Type as Java Class and choose the java class mapping program.
Output:



Source Xml

 


Payload of the Target Message



1 Comment

  1. I think an alternate solution to the above ( passing an entire XML to 1 target field ) is to do a pass through. In this Passthrough process, the IR is bypassed completely, and a dummy namespace and interface is assigned to the sender and receiver interfaces in the Integration Directory.