In one of our project assignments, we had a kind of strange, or a rather tricky requirement. This is was supposed to be a normal XML file to a web service scenario, but the situation was that, the source system gives an XML file, which contains customer’s complaints / acknowledgments. The file naming scheme for both complaints and acknowledgements was the same, and we had to process only those XML files that had complaints in them. There was no way to identify the type of data the files had, as both the complaints and acknowledgements had same file name, but different root tags.
After a lot of research, the only solution we came up with is to have two different outbound interfaces, one for complaints, and the other for acknowledgements. Firstly, pick the file, convert it into a string using a java mapping, then use the graphical mapping to split it into complaints / acknowledgements.
Below are the steps:
First, we have to create a dummy data type with just one element in it, as shown in the below screenshot.
Then create the Message Type and Message Interface for this data type and set the direction of the message interface as Outbound.
This interface is going to be used as the Sender Message Interface.
Then import the XSD / create the data type & message types for the complaint and acknowledgments. Create their message interfaces accordingly with direction as inbound.
In the next step, we have written a simple java mapping program to convert the given XML input into String and import it into the “Imported Archives”. The output of this java mapping is passed to a graphical mapping, which creates the XML message for complaint / acknowledgement based on the input.
Java Mapping:
The graphical mapping is a one-to-many mapping, with the one outbound interface, and two inbound interfaces, with the occurrence of the inbound interfaces defined as “0..1”. The inbound interface is our dummy inbound message interface, and the inbound interfaces would be the Complaints and Acknowledgments interfaces.
The graphical mapping takes the XML input in String format, uses a substring UDF fetch the values.
The UDF “getString” in the above screenshot takes the XML string, the index of the beginning and ending tags of the element “messagetype” as input and returns the actual value of this element called “messagetype”. If this value is “Complaint” then, the target structure “ichicr”, which is for complaint is created, else, the other structure “ichicsrack”, which is an acknowledgment.
Code for getString():
The same logic is used to retrieve the values of other elements, and are populated into the target element as shown in the below screenshot.
Then, create the operations mapping as shown below:
This mapping output returns either of Complaint / Acknowledgement messages at a time and the other message would be empty. Create the configuration scenario in the Integration Directory, with one sender and two receivers.
Result of Operations Mapping:
1. For Complaints:
2. For Acknowledgments:
Hope this blog is helpful.