spring boot cxf soap ws-modify 命名空间

问题描述

我正在使用 CXF 使用合约最后方法开发 spring boot soap-ws 项目。我有来自客户端的 xml 请求,如下所示。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <teen xmlns="some url">
         <!--Optional:-->
         <arg0>
         //DATA
          </arg0>
      </teen>
   </soapenv:Body>
</soapenv:Envelope>

服务不接受上述请求。我想将 xml 请求更改为下面(服务接受以下消息)。 arg0 应该有一个添加的空命名空间。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:se>
   <soapenv:Header/>
   <soapenv:Body>
       <teen xmlns="some url">
         <!--Optional:-->
         <arg0 xmlns="">
         //DATA
          </arg0>
      </teen>
   </soapenv:Body>
</soapenv:Envelope>

有人可以帮助我了解如何实现这一目标吗?

解决方法

我做了一些研究,这就是答案。我创建了一个下面的类并实现了扩展类的handlemethod。 handlemethod 做所有的 xml 修改。

public class InvalidCharInterceptor extends AbstractPhaseInterceptor<Message> {
    
    public InvalidCharInterceptor() {
        super(Phase.RECEIVE); // This is important which determines at what point are we modifying the xml.
    }
public void handleMessage(Message message) throws Fault {

}
}

然后,我在 webserviceconfig 类中添加了新的拦截器类。

EndpointImpl endpoint = new EndpointImpl(bus,"service-class-name");
endpoint.getInInterceptors().add(new InvalidCharInterceptor());

仅供参考..Apache cxf 有关于拦截器的详细解释。 https://cxf.apache.org/docs/interceptors.html