我有类似这样的SOAP响应
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<calculate_response>
<tid>33433</tid>
<status>0</status>
<reason>0</reason>
</calculate_response>
</soapenv:Body>
</soapenv:Envelope>
我需要为它添加名称空间,它应该看起来像这样
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
xmlns:def="http://com.sample.xyz/Messages">
<soapenv:Body>
<def:calculate_response>
<tid>33433</tid>
<status>0</status>
<reason>0</reason>
</def:calculate_response>
</soapenv:Body>
</soapenv:Envelope>
我使用wsimport
创建了存根,我需要在进一步处理之前修改此响应。
实际上,按照我的理解,这是一个两步过程,第一步是将命名空间添加到soap envelop,然后为其添加前缀。 关于前缀部分我找到了this。我不清楚如何做第一步。
注意:我需要在客户端修改响应,我不能在服务器端更改SOAP。
答案 0 :(得分:0)
我在SOAP Message Handlers
我写了handler
来实现SOAPHandler<SOAPMessageContext>
overridden
其handleMessage(SOAPMessageContext context){}
以及后续实施。
//Get soapElement from your soap request.
if (soapElement.getTagName().equalsIgnoreCase("calculate_response")) {
soapElement.setElementQName(
new QName("http://com.sample.xyz/Messages",
"calculate_response",
"def"));