交换对象包含soap消息的主体(不是soap标头)。在exchange.getIn.getHeader()中,我们仅获取传递的HTTP标头,而不是SOAP标头。
如何从Camel中的交换对象中检索SOAP标头?
以下是传递的soap标头:
<soapenv:Header>
<ns1:info xmlns:ns1="http://www.w3schools.com/transaction/">
<ns1:TransactionID>01</ns1:TransactionID>
<ns1:AppUserID>52</ns1:AppUserID>
<ns1:AppPass>ab</ns1:AppPass>
</ns1:info>
</soapenv:Header>
我们尝试使用,
exchange.getIn()。getHeader(“ TransactionID”);
但是它无法提取已发送的SOAP标头。
答案 0 :(得分:0)
如果cxf端点配置为在DataFormat.PAYLOAD中工作,则:
.process(exchange -> {
CxfPayload body = exchange.getIn().getBody(CxfPayload.class);
for (Object header : body.getHeaders()) {
SoapHeader soapHeader = (SoapHeader) header;
org.w3c.dom.Element element = (Element) soapHeader.getObject();
//parse elements
}
});
如果处于原始模式,只需读取输入流并使用xpath将数据解析为xml
答案 1 :(得分:0)
那是我的解决办法:
List<SoapHeader> soapHeaders = (List)exchange.getIn().getHeader("org.apache.cxf.headers.Header.list");
Element header = ((Element)soapHeaders.get(0).getObject());
String eventType = (String)header.getElementsByTagName("TransactionID").item(0).getTextContent();
exchange.getIn().setHeader("TYPE_EVENT",eventType);