在某些情况下,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 Webservice以{"results": []}的形式返回空列表,以防出现空响应?
发布于 2020-04-25 15:15:08
您需要使用XSLT中介将XML处理指令添加到外部元素。
你可以参考这个关于添加处理指令的博客。https://medium.com/@CKoutsoumpos/wso2-esb-handle-empty-or-single-item-arrays-during-json-transformation-with-xslt-c1d5a778a548
https://stackoverflow.com/questions/61408003
复制相似问题