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.
The target structure has only one field which stores the XML payload.
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.
Export this Java Mapping as a Jar file using NWDS.
Import the Jar file created using the NWDS in to the IR.
In the Interface mapping select the Mapping Program Type as Java Class and choose the java class mapping program.
Payload of the Target Message