3

我有这个错误

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>Message part {http://soap.ws.server.wst.fit.cvut.cz/}createOrders was not recognized.  (Does it exist in service WSDL?)</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

这完全没问题。但问题是 CXF 正在返回内部服务器错误 (HTTP 500)。我希望它返回 400 Bad Request 因为错误的请求导致了这种情况。我该如何改变呢?

细节

产生上述错误的错误请求 - 应该有<soap:createOrder/>而不是<soap:createOrders/>.

POST http://localhost:8080/wst-server-1.0.0/services/soap/order

POST data:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.ws.server.wst.fit.cvut.cz/">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:createOrders/>
   </soapenv:Body>
</soapenv:Envelope>

[no cookies]

Request Headers:
Content-Length: 238
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
4

2 回答 2

1

I found this by Googling for "CXF response code 500". It might help.

http://cxf.547215.n5.nabble.com/CXF-Fault-Response-Code-td566788.html

于 2013-01-03T20:38:44.650 回答
1

我知道答案可能为时已晚,但另一种处理 HTTP 状态代码的方法是使用 CXF 拦截器。

你可以在你的服务器 CXF 配置中添加一个拦截器

 public class ServiceConfigurer implements CxfConfigurer {

    @Override
    public void configureServer(Server server) {
         server.getEndpoint().getOutFaultInterceptors().add(new ChangingStatusCodeInterceptor();
    }
 }  

在你的拦截器中,你可以改变这个

public class SaveInfluxDataInterceptor extends WSS4JOutInterceptor {

    @Override
    public void handleMessage(SoapMessage soapMessage) {
        ((Fault)exchange.get(Exception.class)).setStatusCode(202); // this is because of soap12OutFaultInterceptor look to this fault
        // or you can use this
        // exchange.getOutFaultMessage().put(Message.RESPONSE_CODE, 202);
    }
}  

我将 Camel 与 CXF 一起使用。也许这个解决方案应该改变你的。

于 2021-03-29T11:45:44.790 回答