Example usage for javax.xml.soap SOAPEnvelope getFirstChild

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

Introduction

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

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

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  va 2s .  c  o  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());
}