在WSO ESB中处理一个空的xml后端响应

问题描述 投票:0回答:1

WSO2-ESB服务在某些情况下从端点接收到“空” XML响应。

通常,响应看起来像这样。它包含几个result

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:results xmlns:ns2="http://the-endpoint.com/">
            <result>some result</result>
            <result>some other result</result>
            <result>some very different result</result>
        </ns2:results>
    </S:Body>
</S:Envelope>

然后将其转换为result的数组并由客户端使用。

{"results": ["some result", ...]}

但是在极少数情况下,端点响应只是一个空结果列表,JAX-WS显然将其转换为空<ns2:results/>标记。

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:results xmlns:ns2="http://the-endpoint.com/"/>
    </S:Body>
</S:Envelope>

[WSO2-ESB然后将其转换为null对象,这会引起麻烦。

{"results": null}

现在,如果响应为空,如何使WSO2-ESB Web服务将空列表返回为{"results": []}

xml web-services wso2 jax-ws wso2esb
1个回答
0
投票

您需要使用XSLT介体将XML处理指令添加到外部元素。

您可以在添加处理说明上参考此博客。 https://medium.com/@CKoutsoumpos/wso2-esb-handle-empty-or-single-item-arrays-during-json-transformation-with-xslt-c1d5a778a548

© www.soinside.com 2019 - 2024. All rights reserved.