List<String> acoh1ContentList = new ArrayList<String>();
acoh1ContentList.add(acoh1);
acoh1ContentList.add(acoh2);
SOAPHeadersAdapter adapter = (SOAPHeadersAdapter)messageContext.getProperty(Constants.JAXWS_OUTBOUND_SOAP_HEADERS);
adapter.put(ACOH1_HEADER_QNAME, acoh1ContentList);
List<String> headersList = adapter.get(ACOH1_HEADER_QNAME);
headersList.get(0).toString(); // trigger some underlying OM implementation parsing
// use the LogicalMessageImpl to get the message payload
MyLogicalMessageImpl logicalMessageImpl = new MyLogicalMessageImpl(messageContext);
Source payload = logicalMessageImpl.getPayload();
payload.toString();
// get message object and convert to SOAPEnvelope
OMElement omEnvelope = messageContext.getMessage().getAsOMElement();
// confirm headers are there. I can cast here only because I know the implementation. :)
SOAP11HeaderImpl omHeader = (SOAP11HeaderImpl)omEnvelope.getChildElements().next();
Iterator<OMSourcedElementImpl> it = omHeader.getChildElements();
// TODO: not sure if the order of the header additions is or should be preserved.
// in other words, this test may be a little too strict.
OMSourcedElementImpl headerElem1 = it.next();
OMSourcedElementImpl headerElem2 = it.next();
// should only be two header elements, so...
assertFalse(it.hasNext());
assertTrue(headerElem1.toString().equals(acoh1));
assertTrue(headerElem2.toString().equals(acoh2));
// now that we've done a toString() on the header elements, they've been parsed and
// processed by the underlying OM implementation... let's remove one by way of SOAP
// API, then let's make sure we can still get and manipulate the headers via the
// SOAPHeadersAdapter
// TODO: removeChild gives an exception
//soapHeader.removeChild(headerElem1);
headerElem1.detach();
// one is removed, make sure the SOAPHeadersAdapter reflects the change
List<String> contentListAfterSOAPRemoval = adapter.get(ACOH1_HEADER_QNAME);
assertTrue(contentListAfterSOAPRemoval.size() == 1);
// remember we removed headerElem1, so we expect acoh2 to still exist
assertTrue(contentListAfterSOAPRemoval.get(0).equals(acoh2));
}