所以,我正在为一个已经存在的应用程序编写一个 Spring Web 服务来与之通信。我让服务工作到接收请求并响应请求的位置,但问题是,应用程序希望响应采用普通旧 XML (POX) 格式。我的响应当前附加了 SOAP header ,如下所示:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<Person>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Person>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我需要它返回的是:
<Person>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
</Person>
根据我的发现,Spring 非常有能力做到这一点,我认为它与 DomPoxMessageFactory
有关,但我发现的所有示例都是旧版本的 Spring WS 类似 v1.5。甚至 Spring 发行版中的 POX 样本也是 3 年前编写的。感谢您的帮助!
编辑:我也在使用 spring-ws v2.1.2。到目前为止,我的代码非常类似于您在这里找到的代码:http://static.springsource.org/spring-ws/sites/2.0/reference/html/tutorial.html
最佳答案
您可以实现 EndpointInterceptorAdapter并更改覆盖handleResponse的响应。:
@Override
public boolean handleResponse(MessageContext messageContext_, Object endpoint_)
throws IOException {
WebServiceMessage _webServiceMessage = messageContext_.getResponse();
SoapMessage _soapMessage = (SoapMessage) _webServiceMessage;
// modify the content
但是我不确定您可以在多大程度上修改响应。
关于java - 使用普通旧式 XML (POX) 创建 Spring Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15486140/