Search in sources :

Example 26 with SOAPElement

use of javax.xml.soap.SOAPElement in project jdk8u_jdk by JetBrains.

the class SaajEmptyNamespaceTest method testAddElementToGlobalNsNoDeclarations.

/*
     * Test that adding element with explicitly empty namespace URI shall put
     * the element into global namespace. Namespace declarations are not added
     * explicitly.
     */
@Test
public void testAddElementToGlobalNsNoDeclarations() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.testng.annotations.Test)

Example 27 with SOAPElement

use of javax.xml.soap.SOAPElement in project jdk8u_jdk by JetBrains.

the class SaajEmptyNamespaceTest method testAddElementToNullNs.

/*
     * Test that adding element with explicitly null namespace URI shall put
     * the element into global namespace.
     */
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.testng.annotations.Test)

Example 28 with SOAPElement

use of javax.xml.soap.SOAPElement in project jdk8u_jdk by JetBrains.

the class SaajEmptyNamespaceTest method testAddElementToGlobalNsQName.

/*
     * Test that adding element with explicitly empty namespace URI via QName
     * shall put the element in global namespace.
     */
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.testng.annotations.Test)

Example 29 with SOAPElement

use of javax.xml.soap.SOAPElement in project webservices-axiom by apache.

the class TestSetParentElement method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFactory factory = saajImplementation.newSOAPFactory(protocol);
    SOAPElement parent = factory.createElement(new QName("parent"));
    SOAPElement child1 = parent.addChildElement(new QName("child1"));
    SOAPElement child2 = (SOAPElement) parent.getOwnerDocument().createElementNS(null, "child2");
    child2.setParentElement(parent);
    NodeList children = parent.getChildNodes();
    assertEquals(2, children.getLength());
    assertSame(child1, children.item(0));
    assertSame(child2, children.item(1));
}
Also used : QName(javax.xml.namespace.QName) NodeList(org.w3c.dom.NodeList) SOAPElement(javax.xml.soap.SOAPElement) SOAPFactory(javax.xml.soap.SOAPFactory)

Aggregations

SOAPElement (javax.xml.soap.SOAPElement)29 SOAPMessage (javax.xml.soap.SOAPMessage)20 SOAPBody (javax.xml.soap.SOAPBody)17 SOAPException (javax.xml.soap.SOAPException)14 QName (javax.xml.namespace.QName)12 Test (org.testng.annotations.Test)7 NodeList (org.w3c.dom.NodeList)7 Node (org.w3c.dom.Node)6 IOException (java.io.IOException)5 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)5 Detail (javax.xml.soap.Detail)4 MessageFactory (javax.xml.soap.MessageFactory)4 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)4 SOAPFault (javax.xml.soap.SOAPFault)4 Iterator (java.util.Iterator)3 SOAPFactory (javax.xml.soap.SOAPFactory)3 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)3 SOAPPart (javax.xml.soap.SOAPPart)3 WebServiceException (javax.xml.ws.WebServiceException)3 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)3