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

查看:63
本文介绍了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天全站免登陆