【问题标题】:How to change the status code of soap fault如何更改soap故障的状态码
【发布时间】:2021-10-28 08:13:19
【问题描述】:

如何更改spring中soap故障的状态码?我们尝试迁移的网络服务总是响应 http 200,即使它有带有错误详细信息的 soapfault .. 我复制这种行为,因为它是一个迁移,但我似乎找不到解决方法:(

示例响应:

Http 200
<?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" xmlns:ds="http://www.ilog.com/rules">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>Error when executing the ruleset</faultstring>
            <faultactor>http://www.ilog.com/rules</faultactor>
            <detail>
                <ds:DecisionServiceException>
                    <ds:exception>Error when executing</ds:exception>
                </ds:DecisionServiceException>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

    标签: java spring soap soapfault


    【解决方案1】:

    您可以使用 CFX 拦截器来做到这一点。

    您可以在您的服务器 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);
        }
    }  
    

    也许这个解决方案应该改变你的。

    【讨论】:

      猜你喜欢
      • 2013-06-01
      • 1970-01-01
      • 2012-01-28
      • 2014-06-27
      • 1970-01-01
      • 2012-02-01
      • 2014-09-22
      • 1970-01-01
      • 2013-10-03
      相关资源
      最近更新 更多