Example usage for javax.xml.soap SOAPEnvelope removeChild

List of usage examples for javax.xml.soap SOAPEnvelope removeChild

Introduction

In this page you can find the example usage for javax.xml.soap SOAPEnvelope removeChild.

Prototype

public Node removeChild(Node oldChild) throws DOMException;

Source Link

Document

Removes the child node indicated by oldChild from the list of children, and returns it.

Usage

From source file:com.googlecode.ddom.saaj.SOAPMessageTest.java

/**
 * Tests the behavior of {@link SOAPMessage#getSOAPHeader()} after removing the header from the
 * message. Note that the SAAJ specification requires the implementation to throw an exception
 * in this case. However, the reference implementation simply returns <code>null</code> (see
 * also <a href="http://java.net/jira/browse/SAAJ-15">SAAJ-15</a>). We stick to the behavior of
 * the reference implementation./*from ww w  . ja v  a 2s  . co  m*/
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetSOAPHeaderWithNoHeader() throws Exception {
    SOAPMessage message = getFactory().createMessage();
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    // Remove the SOAP header (created by default by MessageFactory) using plain DOM methods
    Node child = envelope.getFirstChild();
    while (child != null) {
        if (child instanceof Element && ((Element) child).getLocalName().equals("Header")) {
            envelope.removeChild(child);
            break;
        }
    }
    assertNull(message.getSOAPHeader());
}