1

I'm trying to use payload factory mediator in WSO2 am to transform Json to XML. But my XML should contain CDATA.

When I use the mediator in wso2, the CDATA is transform : the Cdata tags disappear and all the < and > in my CDATA are transformed to &lt; and &gt;

In the documentation of wso2 1 and on stackoverflow, I find that I should put the javax.xml.stream.isCoalescing to false (from <APIM_HOME>/XMLInputFactory.properties). But it doesn't work : just the > are conserved, the others are transformed.

what I want to keep :

<soapenv:Body>
<![CDATA[
    <?xml version="1.0" encoding="UTF-8"?>
    <Data>
        <body>
            <MSISDN>111111111</MSISDN>
        </body>
    </Data>
]]></soapenv:Body>

and what I have actually :

<soapenv:Body>
&lt;?xml version="1.0" encoding="UTF-8"?>
    &lt;Data>
        &lt;body>
            &lt;MSISDN>111111111&lt;/MSISDN>
        &lt;/body>
    &lt;/Data></soapenv:Body>

Someone can help me ? because I don't understand why the doc's instructions don't work.

Thanks a lot

Community
  • 1
  • 1
  • Maybe this question can help you: http://stackoverflow.com/questions/223652/is-there-a-way-to-escape-a-cdata-end-token-in-xml – Philippe Sevestre Sep 16 '15 at 01:17
  • I don't know anything about WSO2 AM but in WSO2 ESB, you can't use payloadfactory if you want CDATA section to be preserved, see http://stackoverflow.com/questions/32089603/wso2-esb-invoking-webservices-with-xml-data-within-a-tag-of-the-payload – Jean-Michel Sep 16 '15 at 06:36
  • Thank you. The last link help me to build an alternative. It's not really clean so I keep the request open if someone find the answer or if it's a bug to fixe. A clean solution will be better but for the moment it's ok for me – Rémy BEULE-DAUZAT Sep 16 '15 at 12:20

2 Answers2

2

I know it's been couple of years for this, but if someone is looking for this answer(just like I was a month ago :) ) you can do the below both in API-M and ESB

Create a registry resource and send the XML payload you want to escape to the resource. It will simply return the escaped string to your PayloadFactory

Example: Registry Resource: SampleFormat.txt

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
   <text xmlns="http://ws.apache.org/commons/ns/payload"><![CDATA[$1]]></text>
</soapenv:Body>
</soapenv:Envelope>

PayloadFactory

 <payloadFactory description="Send Escaped XML" media-type="xml">
    <format key="conf:/SampleFormat.txt" />
    <!--Custom format will be loaded form Registry containing an XML with escaped characters -->
    <args>
        <arg evaluator="text" expression="get-property('XMLToBeEscaped')" literal="true" />
    </args>
</payloadFactory>
<property name="messageType" scope="axis2" type="STRING" value="text/xml"/>
<property name="ContentType" scope="axis2" type="STRING" value="text/xml"/>

And if you print your $body right after this, you should see the properly escaped SOAPEnvelope.

aadi
  • 98
  • 1
  • 1
  • 9
0

I know this is API-M but if some looking for answer in WSO2 ESB 4.9.0 answer is,

create a file name XMLInputFactory.properties and put below contents and restart.

javax.xml.stream.isCoalescing=false
com.ctc.wstx.minTextSegment=2147483647
Roshan Wijesena
  • 3,106
  • 8
  • 38
  • 57