Java Code Examples for javax.xml.soap.SOAPElement#addNamespaceDeclaration()

The following examples show how to use javax.xml.soap.SOAPElement#addNamespaceDeclaration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SaajEmptyNamespaceTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNs() 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", "", "");
    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);
}
 
Example 3
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNsQName() 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(null, "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);
}
 
Example 4
Source File: SaajEmptyNamespaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example 5
Source File: SaajEmptyNamespaceTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example 6
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example 7
Source File: SaajEmptyNamespaceTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNs() 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", "", "");
    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);
}
 
Example 8
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 9
Source File: SaajEmptyNamespaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example 10
Source File: SaajEmptyNamespaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNs() 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", "", "");
    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);
}
 
Example 11
Source File: SaajEmptyNamespaceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@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());
}
 
Example 12
Source File: SaajEmptyNamespaceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNs() 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", "", "");
    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);
}
 
Example 13
Source File: SaajEmptyNamespaceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNsQName() 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(null, "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);
}
 
Example 14
Source File: SaajEmptyNamespaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNsQName() 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(null, "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);
}
 
Example 15
Source File: SaajEmptyNamespaceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNsQName() 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(null, "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);
}
 
Example 16
Source File: SAAJInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void applyEvents(List<XMLEvent> events, SOAPElement el) throws SOAPException {
    if (events != null) {
        for (XMLEvent ev : events) {
            if (ev.isNamespace()) {
                el.addNamespaceDeclaration(((Namespace)ev).getPrefix(), ((Namespace)ev).getNamespaceURI());
            } else if (ev.isAttribute()) {
                el.addAttribute(((Attribute)ev).getName(), ((Attribute)ev).getValue());
            }
        }
    }
}
 
Example 17
Source File: MUTube.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example 18
Source File: AbstractTypeTestClient3.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAny() throws Exception {
    if (!shouldRunTest("StructWithAny")) {
        return;
    }
    StructWithAny swa = new StructWithAny();
    swa.setName("Name");
    swa.setAddress("Some Address");

    StructWithAny yOrig = new StructWithAny();
    yOrig.setName("Name2");
    yOrig.setAddress("Some Other Address");

    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement x = factory.createElement("hello", "foo", "http://some.url.com");
    x.addNamespaceDeclaration("foo", "http://some.url.com");
    x.addTextNode("This is the text of the node");

    SOAPElement x2 = factory.createElement("hello2", "foo", "http://some.url.com");
    x2.addNamespaceDeclaration("foo", "http://some.url.com");
    x2.addTextNode("This is the text of the node for the second struct");

    swa.setAny(x);
    yOrig.setAny(x2);

    Holder<StructWithAny> y = new Holder<>(yOrig);
    Holder<StructWithAny> z = new Holder<>();

    StructWithAny ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAny(swa, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAny(swa, y, z);
    } else {
        ret = rpcClient.testStructWithAny(swa, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAny(swa, y.value);
        assertEqualsStructWithAny(yOrig, z.value);
        assertEqualsStructWithAny(swa, ret);
    }
}
 
Example 19
Source File: AbstractTypeTestClient5.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyArrayLax() throws Exception {
    if (!shouldRunTest("StructWithAnyArrayLax")) {
        return;
    }
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement elem = factory.createElement("StringElementQualified",
        "x1", "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    elem.addTextNode("This is the text of the node");

    StructWithAnyArrayLax x = new StructWithAnyArrayLax();
    x.setName("Name x");
    x.setAddress("Some Address x");
    x.getAny().add(elem);

    elem = factory.createElement("StringElementQualified", "x1",
        "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    elem.addTextNode("This is the text of the node for the second struct");

    StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax();
    yOrig.setName("Name y");
    yOrig.setAddress("Some Other Address y");
    yOrig.getAny().add(elem);

    Holder<StructWithAnyArrayLax> y = new Holder<>(yOrig);
    Holder<StructWithAnyArrayLax> z = new Holder<>();
    StructWithAnyArrayLax ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAnyArrayLax(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAnyArrayLax(x, y, z);
    } else {
        ret = rpcClient.testStructWithAnyArrayLax(x, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAnyArrayLax(x, y.value);
        assertEqualsStructWithAnyArrayLax(yOrig, z.value);
        assertEqualsStructWithAnyArrayLax(x, ret);
    }
}
 
Example 20
Source File: AbstractTypeTestClient5.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testStructWithAnyArrayLaxComplex() throws Exception {
    if (!shouldRunTest("StructWithAnyArrayLaxComplex")) {
        return;
    }
    SOAPFactory factory = SOAPFactory.newInstance();
    SOAPElement elem = factory.createElement("AnonTypeElementQualified", "x1",
        "http://apache.org/type_test/types1");
    elem.addNamespaceDeclaration("x1", "http://apache.org/type_test/types1");
    SOAPElement floatElem = factory.createElement("varFloat", "x1",
        "http://apache.org/type_test/types1");
    floatElem.addTextNode("12.76");
    elem.addChildElement(floatElem);
    SOAPElement intElem = factory.createElement("varInt", "x1",
        "http://apache.org/type_test/types1");
    intElem.addTextNode("56");
    elem.addChildElement(intElem);
    SOAPElement stringElem = factory.createElement("varString", "x1",
        "http://apache.org/type_test/types1");
    stringElem.addTextNode("test string");
    elem.addChildElement(stringElem);

    StructWithAnyArrayLax x = new StructWithAnyArrayLax();
    x.setName("Name x");
    x.setAddress("Some Address x");
    x.getAny().add(elem);
    StructWithAnyArrayLax yOrig = new StructWithAnyArrayLax();
    yOrig.setName("Name y");
    yOrig.setAddress("Some Other Address y");
    yOrig.getAny().add(elem);

    Holder<StructWithAnyArrayLax> y = new Holder<>(yOrig);
    Holder<StructWithAnyArrayLax> z = new Holder<>();
    StructWithAnyArrayLax ret;
    if (testDocLiteral) {
        ret = docClient.testStructWithAnyArrayLax(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testStructWithAnyArrayLax(x, y, z);
    } else {
        ret = rpcClient.testStructWithAnyArrayLax(x, y, z);
    }
    if (!perfTestOnly) {
        assertEqualsStructWithAnyArrayLax(x, y.value);
        assertEqualsStructWithAnyArrayLax(yOrig, z.value);
        assertEqualsStructWithAnyArrayLax(x, ret);
    }
}