xml - 强制 Spring Web 服务将 xsd 命名空间添加到响应中

标签 xml web-services namespaces spring-ws

我使用的是 Spring WS 1.5.8 版。我的回复如下所示:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
   <SOAP-ENV:Header/> 
   <SOAP-ENV:Body> 
      ...
   </SOAP-ENV:Body> 
</SOAP-ENV:Envelope>

但是,我的客户(我与之集成)要求我添加更多 namespace 声明以便解析成功:

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">          
    <soapenv:Body> 
         ... 
    </soapenv:Body> 
</soapenv:Envelope> 

我该怎么做?

最佳答案

您可能不需要我告诉您任何需要某些命名空间声明的 SOAP 客户端,当文档中未使用这些命名空间时,它们就会损坏。所以我不会提这个。

但是,如果您确实想像那样改变响应,您可以使用 EndpointInterceptor,特别是 SoapEndpointInterceptor。您可以连接端点拦截器 as described here .

您的自定义拦截器可以实现 handleResponse 方法,将 messageContext.getResponse() 转换为 SoapMessage 并添加您需要的任何内容:

public class MyInterceptor implements SoapEndpointInterceptor {

    public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
        SoapMessage message = (SoapMessage) messageContext.getResponse();
        message.getEnvelope().addNamespaceDeclaration(....);
        return true;
    }

    // ... other methods here
}

不过,添加此类低级命名空间声明可能会产生副作用,因此请谨慎行事。

关于xml - 强制 Spring Web 服务将 xsd 命名空间添加到响应中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2813320/

相关文章:

css - 覆盖在生产服务器上为 DITA XML 文件定义的样式

amazon-web-services - AWS Dynamo Db on Services 的连接池

wpf - ViewModel 位置到子文件夹(XAML,命名空间)

c# - 在 Unity 中使用命名空间隐藏功能

android - 为什么要在各个android组件中使用字符串资源- "android:text"属性?

android - 如何在 XML 选择器中使用字体图标 (font-awesome)

c# - 将 OpenID 与 Web 服务一起使用 : Best way to authenticate?

javascript - Jquery AJAX 帖子 : 500 (Internal Server Error)?

.net - 我可以从构建配置中排除命名空间(即 Name1.Name2)吗

xml - 在使用XPath的XSLT中