Search in sources :

Example 1 with SAAJFactory

use of com.sun.xml.internal.ws.api.message.saaj.SAAJFactory in project jdk8u_jdk by JetBrains.

the class SaajEmptyNamespaceTest method testResetDefaultNamespaceSAAJ.

/*
     * Test that SOAP message with default namespace declaration that contains empty
     * string is properly processed by SAAJ reader.
     */
@Test
public void testResetDefaultNamespaceSAAJ() throws Exception {
    // Create SOAP message from XML string and process it with SAAJ reader
    XMLStreamReader envelope = XMLInputFactory.newFactory().createXMLStreamReader(new StringReader(INPUT_SOAP_MESSAGE));
    StreamMessage streamMessage = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
    SAAJFactory saajFact = new SAAJFactory();
    SOAPMessage soapMessage = saajFact.readAsSOAPMessage(SOAPVersion.SOAP_11, streamMessage);
    // Check if constructed object model meets local names and namespace expectations
    SOAPElement request = (SOAPElement) soapMessage.getSOAPBody().getFirstChild();
    // Check top body element name
    Assert.assertEquals(request.getLocalName(), "SampleServiceRequest");
    // Check top body element namespace
    Assert.assertEquals(request.getNamespaceURI(), TEST_NS);
    SOAPElement params = (SOAPElement) request.getFirstChild();
    // Check first child name
    Assert.assertEquals(params.getLocalName(), "RequestParams");
    // Check if first child namespace is null
    Assert.assertNull(params.getNamespaceURI());
    // Check inner elements of the first child
    SOAPElement param1 = (SOAPElement) params.getFirstChild();
    Assert.assertEquals(param1.getLocalName(), "Param1");
    Assert.assertNull(param1.getNamespaceURI());
    SOAPElement param2 = (SOAPElement) params.getChildNodes().item(1);
    Assert.assertEquals(param2.getLocalName(), "Param2");
    Assert.assertNull(param2.getNamespaceURI());
    // Check full content of SOAP body
    Assert.assertEquals(nodeToText(request), EXPECTED_RESULT);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SAAJFactory(com.sun.xml.internal.ws.api.message.saaj.SAAJFactory) StringReader(java.io.StringReader) SOAPElement(javax.xml.soap.SOAPElement) StreamMessage(com.sun.xml.internal.ws.message.stream.StreamMessage) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.testng.annotations.Test)

Aggregations

SAAJFactory (com.sun.xml.internal.ws.api.message.saaj.SAAJFactory)1 StreamMessage (com.sun.xml.internal.ws.message.stream.StreamMessage)1 StringReader (java.io.StringReader)1 SOAPElement (javax.xml.soap.SOAPElement)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Test (org.testng.annotations.Test)1