WSO2 AM 1.9 - 将 CDATA 保存在有效负载工厂中 [英] WSO2 AM 1.9 - Keep CDATA in payload factory

查看:23
本文介绍了WSO2 AM 1.9 - 将 CDATA 保存在有效负载工厂中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 WSO2 am 中的有效负载工厂调解器将 Json 转换为 XML.但我的 XML 应该包含 CDATA.

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

当我在 wso2 中使用调解器时,CDATA 是转换:Cdata 标记消失,所有 <我的 CDATA 中的和 > 被转换为 &lt;&gt;

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;

在 wso2 的文档中 1 在stackoverflow上,我发现我应该将 javax.xml.stream.isCoalescing 设置为 false(来自 <APIM_HOME>/XMLInputFactory.属性).但它不起作用:只有 > 被保留,其他的被转换.

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.

我想保留的:

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

以及我实际拥有的:

<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.

非常感谢

推荐答案

我知道这已经有几年了,但是如果有人正在寻找这个答案(就像我一个月前一样 :))你可以做在 API-M 和 ESB 中都低于

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

创建一个注册表资源并将您想要转义的 XML 有效负载发送到该资源.它只会将转义的字符串返回到您的 PayloadFactory

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

示例:注册表资源: SampleFormat.txt

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"/>

如果您在此之后立即打印 $body,您应该会看到正确转义的 SOAPEnvelope.

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

这篇关于WSO2 AM 1.9 - 将 CDATA 保存在有效负载工厂中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆