从WSO2中的SOAP响应中获取JSON消息

发布于 2025-02-02 00:43:47 字数 661 浏览 3 评论 0原文

...
<property expression="//soap:Envelope/soap:Body/Response/Result" name="result"/>
<log>
  <property expression="get-property('result')" name="result"/>
</log>
...

响应

...
<response>  [  { "_id": "62908b4267c5284f7fa8320e",  "index": 0, "serial": "11006883-fb2b-49ba-a6f7-0ec0daafa1c5", "Active": false, "balance": "$3,723.68", ,"age": 34 }]    </response>

如何获得ID和平衡的响应属性? 当我使用

 <log>
    <property expression="get-property('response')" name="response"/>
 </log>

时,它仅返回JSON数组仅

...
<property expression="//soap:Envelope/soap:Body/Response/Result" name="result"/>
<log>
  <property expression="get-property('result')" name="result"/>
</log>
...

the response

...
<response>  [  { "_id": "62908b4267c5284f7fa8320e",  "index": 0, "serial": "11006883-fb2b-49ba-a6f7-0ec0daafa1c5", "Active": false, "balance": "$3,723.68", ,"age": 34 }]    </response>

How do i get the response property for id and balance?
When i use

 <log>
    <property expression="get-property('response')" name="response"/>
 </log>

it only returns the Json array only only

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微凉 2025-02-09 00:43:47

我们可以假设有效负载看起来像下面。

    <response>
[
    {
        "_id": "62908b4267c5284f7fa8320e",
        "index": 0,
        "serial": "11006883-fb2b-49ba-a6f7-0ec0daafa1c5",
        "Active": false,
        "balance": "$3,723.68",
        "age": 34
    }
]
</response>

我们将将&lt;响应&gt;标记值存储到以下类似的属性中。

<property name="jsonMessageContent" expression="//response/text()"/>

发布该内容,将使用RENRICH调解器将属性值转换为身体。

<enrich>
        <source clone="false" xpath="get-property('jsonMessageContent')"/>
        <target type="body"/>
     </enrich>

最后,我们可以使用xpath来获取_id,ballace从有效负载

<log level="custom">
        <property name="id value***" expression="//jsonArray/jsonElement/_id/text()"/>
        <property name="balance value***" expression="//jsonArray/jsonElement/balance/text()"/>
     </log>

输出:

id value*** = 62908b4267c5284f7fa8320e, balance value*** = $3,723.68

We can assume payload look like below.

    <response>
[
    {
        "_id": "62908b4267c5284f7fa8320e",
        "index": 0,
        "serial": "11006883-fb2b-49ba-a6f7-0ec0daafa1c5",
        "Active": false,
        "balance": "$3,723.68",
        "age": 34
    }
]
</response>

We're going to store <response> tag values into property like below.

<property name="jsonMessageContent" expression="//response/text()"/>

Post that, going to use enrich mediator to convert property value into body.

<enrich>
        <source clone="false" xpath="get-property('jsonMessageContent')"/>
        <target type="body"/>
     </enrich>

Finally we can use xpath to fetch values like _id,balance from payload

<log level="custom">
        <property name="id value***" expression="//jsonArray/jsonElement/_id/text()"/>
        <property name="balance value***" expression="//jsonArray/jsonElement/balance/text()"/>
     </log>

Output:

id value*** = 62908b4267c5284f7fa8320e, balance value*** = $3,723.68
无畏 2025-02-09 00:43:47

假设您在XML响应中有有效的JSON。您可以执行以下操作以获得ID和平衡。在这里,您必须使用脚本中介。

<property expression="//response/text()" name="jsonMessageContent"/>
<script language="nashornJs"><![CDATA[
// Get the Json message portion from the response. You can use property mediator extract only that part      
mc.getProperty('jsonMessageContent')
// Convert into a Json Object
var jsonObj = JSON.parse(mc.getProperty('jsonMessageContent'));
// Specify your jsonpath here and extract
var balance = jsonObj.balance;

// Set to a different property  so you can use it in your integrations
mc.setProperty("balance", balance);
]]></script>

Assuming you have a valid Json within your XML response. You can do the following to get the ID and balance. Here you have to use a script mediator.

<property expression="//response/text()" name="jsonMessageContent"/>
<script language="nashornJs"><![CDATA[
// Get the Json message portion from the response. You can use property mediator extract only that part      
mc.getProperty('jsonMessageContent')
// Convert into a Json Object
var jsonObj = JSON.parse(mc.getProperty('jsonMessageContent'));
// Specify your jsonpath here and extract
var balance = jsonObj.balance;

// Set to a different property  so you can use it in your integrations
mc.setProperty("balance", balance);
]]></script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文