【发布时间】:2022-09-30 12:15:26
【问题描述】:
有这个遗留系统发送带有空命名空间属性的 SOAP 请求,导致字段值为空,当从 SOAP UI 测试时删除命名空间属性时,它工作正常。
这就是有问题的 SOAP 请求的样子
<?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\">
<soapenv:Body>
<ADD xmlns=\"http://www.cc.com/ws\">
<ID xmlns=\"\">dummy</ID>
<PWD xmlns=\"\">password</PWD>
</ADD>
</soapenv:Body>
</soapenv:Envelope>
我尝试使用WsConfigurerAdapter 的addInterceptors 方法添加拦截器,其代码粘贴在下面,但它不起作用
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
SOAPMessage soapMessage = ((SaajSoapMessage) messageContext.getRequest()).getSaajMessage();
SOAPBody body = soapMessage.getSOAPBody();
Iterator<SOAPBodyElement> it = body.getChildElements();
while (it.hasNext()) {
Object node = it.next();
if (!isTextNode(node)) {
com.sun.xml.internal.messaging.saaj.soap.ver1_1.BodyElement1_1Impl e =
(com.sun.xml.internal.messaging.saaj.soap.ver1_1.BodyElement1_1Impl) node;
Iterator<SOAPBodyElement> subItr = e.getChildElements();
while(subItr.hasNext()) {
Object subNode = subItr.next();
if(subNode instanceof com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl) {
SOAPElement el = (SOAPElement) subNode;
el.removeAttribute(\"xmlns\");
}
}
}
}
soapMessage.writeTo(System.out);
return true;
}
标签: java spring-boot soap