[WSO2 EI] — Enrich payload inside [CDATA[]]

Hasitha Hiranya Abeykoon
Think Integration
Published in
2 min readFeb 24, 2019

WSO2 Enterprise Integrator is one of popular enterprise integrator software comprised of tools to do data transformations and many more…

Inside ![CDATA[…] you can place any content inside a xml document. Sometimes xml payloads reaching middleware for mediation has such content, and content needs to be modified/enrich during mediation. WSO2 EI has capability to do that using payload factory mediator.

Following proxy service will add a new tag “<MSISDN>xxxx</MSISDN>” inside CDATA payload

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log/>
<script language="js"><![CDATA[var address ='xxxx';var bodyrequestToCreate='<MSISDN>' +address +'</MSISDN>';mc.setProperty('abc', bodyrequestToCreate);]]></script>
<property expression="get-property('bodyrequestToCreate')" name="bodyrequestToCreate" scope="default" type="OM"/>
<payloadFactory media-type="xml">
<format>
<POST xmlns="">
<xmlRequest><![CDATA[<Request>
<Header>
<Service>MAP3</Service>
<OperationType>Operator</OperationType>
</Header>
<Parameters>$1</Parameters>
</Request>]]></xmlRequest>
</POST>
</format>
<args>
<arg evaluator="xml" expression="get-property('abc')"/>
</args>
</payloadFactory>
<log level="full">
<property name="AFTER" value="AFTER"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</target>
</proxy>

The outline of what this proxy does is,

  1. Use script mediator to construct a payload with a dynamic value “xxxx” enclosed by xml tag <MSISDN>.
  2. Set it as a property to message context inside script mediator.
  3. Read the property and set as a new OM type property using property mediator.
  4. Using payloadFactory mediator, set it to payload inside [CDATA[]].

If you invoke the proxy with any SOAP message, you will get a malformed response. The reason for this is WSO2 EI uses STAX parser and by default, the STAX parser is in non coalescing mode. To correct that, you need to do following

1. create a file called XMLInputFactory.properties inside <EI_HOME>
2. add following content into the file
javax.xml.stream.isCoalescing=false

Now after restarting the server, if you invoke the proxy you will receive expected response as follows.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<POST>
<xmlRequest><![CDATA[<Request>
<Header>
<Service>MAP3</Service>
<OperationType>Operator</OperationType>
</Header>
<Parameters><MSISDN>xxxx</MSISDN></Parameters>
</Request>]]>
</xmlRequest>
</POST>
</soapenv:Body>
</soapenv:Envelope>

--

--