我尝试在Apache CXF文档之后添加标题
List<Header> headers = new ArrayList<Header>();
Header dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "decapitated",
new JAXBDataBinding(String.class));
headers.add(dummyHeader);
//server side:
context.getMessageContext().put(Header.HEADER_LIST, headers);
//client side:
((BindingProvider)proxy).getRequestContext().put(Header.HEADER_LIST, headers);
这会以
格式生成标题<SoapHeader>
<dummy xmlns="uri:org.apache.cxf.dummy>decapitated</dummy>
</SoapHeader>
我想要实现的是
<SoapHeader>
<dummy xmlns="uri:org.apache.cxf.dummy>
<value>decapitated</value>
</dummy>
答案 0 :(得分:1)
一个选项是创建一个SOAPElement并将其添加到标题中,如下所示:
SOAPFactory sf = SOAPFactory.newInstance();
SOAPElement seqElement = sf.createElement(new QName("uri:org.apache.cxf","dummy"));
SOAPElement textElement = sf.createElement(new QName("uri:org.apache.cxf","value"));
textElement.addTextNode("decapitated");
seqElement.addChildElement(textElement);
SoapHeader dummyHeader = new SoapHeader(new QName("uri:org.apache.cxf","dummy"), seqElement);