CXF 修改默认命名空间值

你总想不到需求会有多操蛋,要求将报文头:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

更改到:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

只是名字不同,虽然两个均合法。
第一种方法,基于Spring配置:

<jaxws:properties>
<entry key="soap.env.ns.map">
<map>
<entry key="SOAP-ENV" value="http://schemas.xmlsoap.org/soap/envelope/"/>
</map>
</entry>
<entry key="disable.outputstream.optimization" value="true"/>
</jaxws:properties>

只测了发布服务器端时加到 endpoint 结点下可用。
第二种方法,代码直接调用:

Client client = ClientProxy.getClient(port);
client.getOutInterceptors();
HashMap<String, String> hmap = new HashMap<String, String>();
hmap.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
client.getRequestContext().put("soap.env.ns.map", hmap);
client.getRequestContext().put("disable.outputstream.optimization", "true");

只测了客户端连接服务器时可用。

参考地址:http://cxf.547215.n5.nabble.com/How-to-customize-namespaces-position-and-prefix-in-CXF-response-td3423069.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值