我已经构建了Spring WS应用程序(基于Spring WS 2.2.3),它公开了一个带有几个Operations的小型Web服务。每个操作接收输入参数以搜索后端数据库并返回响应。一些参数是强制性的(例如街道名称),并且客户端已经请求如果对服务的请求缺少某些强制参数(例如空街道名称),那么我的服务应该返回HTTP状态为400的正确SOAP故障。
我的异常处理工作正常,如果请求消息中缺少某些必需参数,我可以将正确的SOAP Fault返回给客户端,Spring WS通过包装SOAP Fault来处理其余的事务并将其发回对于状态代码为500的客户端,如下所示:
HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: text/xml;charset=utf-8
Content-Length: 503
Date: Thu, 10 Dec 2015 22:28:02 GMT
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">Street Name is required</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
除了我真的希望HTTP状态代码为'400 Bad Request'而不是' 500内部服务器错误'之外,哪个好,我无法想象如何将状态代码从500更改为400并获得类似的响应,如下所示:
HTTP/1.1 400 Bad Request
Server: Apache-Coyote/1.1
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: text/xml;charset=utf-8
Content-Length: 503
Date: Thu, 10 Dec 2015 22:28:02 GMT
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">Street Name is required</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
有什么想法吗?