Reputation: 59
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 <
and >
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>
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<body>
<MSISDN>111111111</MSISDN>
</body>
</Data></soapenv:Body>
Someone can help me ? because I don't understand why the doc's instructions don't work.
Thanks a lot
Upvotes: 1
Views: 1388
Reputation: 128
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.
Upvotes: 3
Reputation: 3136
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
Upvotes: 0