【发布时间】:2020-01-07 05:14:39
【问题描述】:
我需要向 Soap 请求添加标头元素,但标头内的子元素没有定义任何前缀。当我尝试在不指定前缀的情况下添加元素时,会引发异常。
private SOAPHeader addSecuritySOAPHeader(SOAPMessageContext context) {
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("S", "http://schemas.xmlsoap.org/soap/envelope/");
envelope.addNamespaceDeclaration("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
SOAPEnvelope header = envelope.getHeader();
// ACTION NODE
SOAPElement action = header.addChildElement("Action");
return header;
}
最后一行产生下一个异常 “com.sun.xml.messaging.saaj.SOAPExceptionImpl:HeaderElements 必须是命名空间限定的”
我需要创建的Heaser:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<Action xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://cgbridge.rategain.com/2011A/ReservationService/HotelResNotif</Action>
</S:Header>
..............
</S:Envelope>
如果我包含任何前缀,例如 S,请求失败,服务器响应“错误请求”
如何添加“干净”的 Action 节点?
我是否在操作中添加了前缀: SOAPElement action = header.addChildElement("Action","S"); 带有“错误请求”消息的服务响应。
<S:Action xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">http://cgbridge.rategain.com/2011A/ReservationService/HotelResNotif</S:Action>
有什么帮助吗?
【问题讨论】: