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);
// get message object and convert to SOAPEnvelope
SOAPEnvelope soapEnvelope = messageContext.getMessage().getAsSOAPEnvelope();
// confirm headers are there
SOAPHeader soapHeader = soapEnvelope.getHeader();
Iterator<SOAPHeaderElement> it = soapHeader.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.
SOAPHeaderElement headerElem1 = it.next();
SOAPHeaderElement 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.detachNode();
// 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));
}