Reputation: 327
I'm trying to construct a simple header element (i.e. contextID) with org.apache.cxf.headers.Header
The XML representation should be like:
<soapenv:Header>
<contextID>someString</contextID>
</soapenv:Header>
I was trying like this in an interceptor:
String contextID = "someString";
List<Header> headers = message.getHeaders();
//this could be possibly wrong
Header contextIdHeader = new Header(new QName(CORE_NAMESPACE, "contextID"), contextID);
headers.add(contextIdHeader);
message.put(Header.HEADER_LIST, headers);
But I'm getting an exception:
java.lang.ClassCastException: java.lang.String cannot be cast to org.w3c.dom.Element
I suppose, the construction of the Header element is wrong. What would be the correct way to do it?
Thank you!
Upvotes: 2
Views: 917
Reputation: 327
Found the solution:
the Header element has to be created like this
Header contextIdHeader = new Header(new QName(CORE_NAMESPACE, "contextID"), contextID, new JAXBDataBinding(String.class));
Upvotes: 2