Search in sources :

Example 1 with SOAPBodyElement

use of jakarta.xml.soap.SOAPBodyElement in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageTest method testWhiteSpaceCharacters.

public void testWhiteSpaceCharacters() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPBody body = message.getSOAPBody();
    QName name = new QName("testString1");
    SOAPBodyElement bodyElement = body.addBodyElement(name);
    bodyElement.addTextNode("Hello World, ---\003\007\024---");
    name = new QName("testString2");
    bodyElement = body.addBodyElement(name);
    bodyElement.addTextNode("Hello \t\n\r World");
    SAAJMessage saajMsg = new SAAJMessage(message);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    saajMsg.writeTo(writer);
    writer.close();
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(baos.toString())));
    NodeList nodeList = doc.getElementsByTagName("testString1");
    assertEquals(nodeList.item(0).getFirstChild().getNodeValue(), "Hello World, ------");
    nodeList = doc.getElementsByTagName("testString2");
    assertEquals(nodeList.item(0).getFirstChild().getNodeValue(), "Hello \t\n\r World");
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) InputSource(org.xml.sax.InputSource) MessageFactory(jakarta.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) SOAPMessage(jakarta.xml.soap.SOAPMessage) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement)

Example 2 with SOAPBodyElement

use of jakarta.xml.soap.SOAPBodyElement in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageTester method testDOMLevel1WriteTo.

public void testDOMLevel1WriteTo() throws Exception {
    DocumentBuilderFactory builderFactory = null;
    DocumentBuilder builder = null;
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
    soapEnvelope.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    soapEnvelope.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
    SOAPBody soapBody = soapEnvelope.getBody();
    Name elementName = soapEnvelope.createName("addNumbers", "", "http://duke.org");
    SOAPBodyElement bodyElement = soapBody.addBodyElement(elementName);
    SAAJMessage msg = new SAAJMessage(soapMessage);
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.createXMLStreamWriter(baos);
    msg.writeTo(writer);
    writer.flush();
}
Also used : SOAPBody(jakarta.xml.soap.SOAPBody) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MessageFactory(jakarta.xml.soap.MessageFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) SOAPMessage(jakarta.xml.soap.SOAPMessage) Name(jakarta.xml.soap.Name) QName(javax.xml.namespace.QName) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 3 with SOAPBodyElement

use of jakarta.xml.soap.SOAPBodyElement in project openmq by eclipse-ee4j.

the class MessageUtil method getJMSBodyElement.

public static SOAPBodyElement getJMSBodyElement(SOAPMessage message, String localName) throws SOAPException {
    Name name = createJMSName(localName);
    Iterator it = message.getSOAPBody().getChildElements(name);
    if (it.hasNext()) {
        return (SOAPBodyElement) it.next();
    }
    return null;
}
Also used : Iterator(java.util.Iterator) Name(jakarta.xml.soap.Name) SOAPBodyElement(jakarta.xml.soap.SOAPBodyElement)

Aggregations

SOAPBodyElement (jakarta.xml.soap.SOAPBodyElement)3 MessageFactory (jakarta.xml.soap.MessageFactory)2 Name (jakarta.xml.soap.Name)2 SOAPBody (jakarta.xml.soap.SOAPBody)2 SOAPMessage (jakarta.xml.soap.SOAPMessage)2 QName (javax.xml.namespace.QName)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)1 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)1 SOAPEnvelope (jakarta.xml.soap.SOAPEnvelope)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 Iterator (java.util.Iterator)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1 InputSource (org.xml.sax.InputSource)1