Integrating CDATA based Web Service with SAP PI – A Generic Approach
Integration with CDATA based web services, which have an embedded request and response structure using SAP PI, has been a tough problem to crack. In this blog, I would try to explain a generic way to integrate and map to such Web Services.
Let us start with understanding what CDATA actually means.
The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages like XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure. In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup. A CDATA section is merely an alternative syntax for expressing character data; there is no semantic difference between character data that manifests as a CDATA section and character data that manifests as in the usual syntax in which “<” and “&” would be represented by “<” and “&”, respectively.
This is how an example mark-up looks like:
<Blog>SCN Blog</blog>, this can be interpreted as <blog>SCN Blog</blog>
Typical problem is PI, is to map a source structure into a target XML structure, where CDATA information needs to be embedded into one node. This can be an imported XSD or WSDL document.
In the screen shot above, the CDATA string needs to be imbedded onto the RequestXML element.
The transformed XML is expected as follows
The source structure on the other hand can be a hierarchical structure.
The First Step to achieve the above target would be to generate an intermediate structure from the hierarchical structure, with all relevant target fields being clubbed into one records set.
The next step and by-far the important step is to embed the above structure into the CDATA and finally into the request XML node.
There can be multiple ways to achieve this, one is to write a complicated UDF and build the XML (using string concatenation functions between the data components and tag identifiers like < , & gt). This can become cumbersome and have hit on performance.
A simpler way is to write a JAVA map to do it. I would explain a generic JAVA map next, which can be used in any such situations.
The First step is to create the root element for the target and define the expected target namespace.
The next step is to generate String data out of the Intermediate structure
This can simply be achieved by using the Famous Transformer Factory class. The important method here is SetOutputProperty, with the attribute OutputKeys.OMIT_XML_DECLARATION. This property is required to be set for converting XML to String.
The next step is to embed this string into the CDATA element of the target node. This can be achieved as follows
The createCDATASection () method takes care of the embedding, and the trick is done !
The above JAVA map can them be used for any such CDATA conversion requirements.
The point to be noted though is, that you would need a sequential ( graphical + JAVA ) Operational mapping .