4

我正在使用 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>

但是,我的客户(我与之集成)要求我添加更多命名空间声明以使解析成功:

<?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> 

我该怎么做?

4

1 回答 1

5

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

但是,如果您确实想像那样改变响应,您可以使用 a EndpointInterceptor,特别是 a SoapEndpointInterceptor您可以按照此处所述连接端点拦截器。

您的自定义拦截器可以实现该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
}

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

于 2010-05-11T18:43:59.960 回答