Search in sources :

Example 96 with SOAPMessage

use of javax.xml.soap.SOAPMessage 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)

Example 97 with SOAPMessage

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

the class MailTest method addSoapAttachement.

void addSoapAttachement() {
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        AttachmentPart a = message.createAttachmentPart();
        a.setContentType("binary/octet-stream");
        message.addAttachmentPart(a);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) SOAPException(javax.xml.soap.SOAPException) AttachmentPart(javax.xml.soap.AttachmentPart) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 98 with SOAPMessage

use of javax.xml.soap.SOAPMessage 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 99 with SOAPMessage

use of javax.xml.soap.SOAPMessage 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 100 with SOAPMessage

use of javax.xml.soap.SOAPMessage 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)

Aggregations

SOAPMessage (javax.xml.soap.SOAPMessage)111 SOAPException (javax.xml.soap.SOAPException)61 Element (org.w3c.dom.Element)31 SOAPBody (javax.xml.soap.SOAPBody)30 IOException (java.io.IOException)28 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)25 SOAPElement (javax.xml.soap.SOAPElement)21 MessageFactory (javax.xml.soap.MessageFactory)19 SOAPPart (javax.xml.soap.SOAPPart)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 ServletException (javax.servlet.ServletException)13 QName (javax.xml.namespace.QName)13 MimeHeaders (javax.xml.soap.MimeHeaders)12 SessionException (com.sun.identity.plugin.session.SessionException)11 OutputStream (java.io.OutputStream)11 NodeList (org.w3c.dom.NodeList)11 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)10 List (java.util.List)10 StreamSource (javax.xml.transform.stream.StreamSource)10