2010-05-11 43 views
4

我正在使用Spring WS 1.5.8版。我的回答是這樣的:強制Spring Web服務將xsd命名空間添加到響應中

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

然而,我的客戶(其中我與整合)要求,我會爲了增加更多的命名空間declerations的解析成功:

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

您可能不需要我告訴您,當文檔中未使用這些名稱空間時,任何需要某些名稱空間聲明的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 
} 

添加這種低級別的命名空間聲明可能帶來的副作用,雖然如此謹慎行事。

+0

謝謝快速反應的skaffman – 2010-05-11 19:46:17