Search in sources :

Example 11 with SOAPMessage

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

the class SAAJMessageHeadersTest method testMustUnderstand.

public void testMustUnderstand() throws Exception {
    SOAPMessage sm = makeSOAPMessage(MESSAGE);
    // SAAJMessage saajMsg = new SAAJMessage(sm);
    MessageHeaders hdrs = new SAAJMessageHeaders(sm, SOAPVersion.SOAP_11);
    // new must understand header
    Header newHdr = new StringHeader(new QName("myNs", "stringHeader1"), "stringHeaderValue1", SOAPVersion.SOAP_11, true);
    hdrs.add(newHdr);
    Set<QName> notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstoods);
    assertEquals(1, notUnderstoods.size());
    // verify the understood headers list
    Set<QName> understoods = hdrs.getUnderstoodHeaders();
    // none of the headers is marked understood
    assertNull(understoods);
    // assertEquals(1, understoods.size());
    // the new header should not be understood yet
    assertFalse(hdrs.isUnderstood(newHdr));
    // now "understand" the header
    hdrs.understood(newHdr);
    // the new header should be understood now
    assertTrue(hdrs.isUnderstood(newHdr));
    notUnderstoods = hdrs.getNotUnderstoodHeaders(null, null, null);
    assertNotNull(notUnderstoods);
    assertEquals(0, notUnderstoods.size());
    // make sure the newly understood header now shows up in the understoodHeaders
    understoods = hdrs.getUnderstoodHeaders();
    assertNotNull(understoods);
    assertEquals(1, understoods.size());
}
Also used : SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) StringHeader(com.sun.xml.ws.message.StringHeader) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) QName(javax.xml.namespace.QName) SAAJMessageHeaders(com.sun.xml.ws.api.message.saaj.SAAJMessageHeaders) MessageHeaders(com.sun.xml.ws.api.message.MessageHeaders) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 12 with SOAPMessage

use of jakarta.xml.soap.SOAPMessage 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, ---&#3;&#7;&#20;---");
    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 13 with SOAPMessage

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

the class SAAJMessageTest method test1.

public void test1() throws Exception {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    Source src = new StreamSource(new ByteArrayInputStream(MESSAGE.getBytes()));
    message.getSOAPPart().setContent(src);
    SAAJMessage saajMsg = new SAAJMessage(message);
    assertEquals("addNumbers", saajMsg.getPayloadLocalPart());
    assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
    Header header = new StringHeader(new QName("urn:foo", "header1"), "test header  ");
    saajMsg.getHeaders().add(header);
    SOAPMessage newMsg = saajMsg.readAsSOAPMessage();
    newMsg.writeTo(System.out);
    SAAJMessage saajMsg2 = new SAAJMessage(newMsg);
    assertEquals(2, saajMsg2.getHeaders().asList().size());
    Message saajMsg3 = saajMsg2.copy();
    assertEquals("addNumbers", saajMsg3.getPayloadLocalPart());
    assertEquals("http://example.com/addNumbers", AddressingUtils.getAction(saajMsg3.getHeaders(), AddressingVersion.W3C, SOAPVersion.SOAP_11));
    assertEquals(2, saajMsg2.getHeaders().asList().size());
    XMLStreamWriter writer = XMLStreamWriterFactory.create(System.out);
    saajMsg3.writeTo(writer);
    writer.close();
}
Also used : StringHeader(com.sun.xml.ws.message.StringHeader) MessageFactory(jakarta.xml.soap.MessageFactory) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamSource(javax.xml.transform.stream.StreamSource) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource)

Example 14 with SOAPMessage

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

the class SAAJMessageTest method testMtomAttachmentCid.

public void testMtomAttachmentCid() throws Exception {
    String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
    MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
    Packet packet = (Packet) m1;
    Message riMsg = packet.getInternalMessage();
    // This will cause all the attachments to be created ...
    // Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
    // SAAJFactory:
    SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
    SOAPMessage saajMsg = soapVersion.getMessageFactory().createMessage();
    SaajStaxWriterEx writer = new SaajStaxWriterEx(saajMsg, soapVersion.nsUri);
    try {
        riMsg.writeTo(writer);
    } catch (XMLStreamException e) {
        throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
    }
    saajMsg = writer.getSOAPMessage();
    int counter = 0;
    String hredCid = null;
    for (Attachment a : riMsg.getAttachments()) {
        hredCid = ((StreamingDataHandler) a.asDataHandler()).getHrefCid();
        counter++;
    }
    assertTrue(writer.ma.size() == counter);
    AttachmentPart ap = null;
    // for (Iterator<AttachmentPart> itr = saajMsg.getAttachments(); itr.hasNext(); ) {
    // System.out.println("\r\n itr.next().getContentId()  " + itr.next().getContentId() );
    // }
    StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
    assertEquals(hredCid, sdh.getHrefCid());
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) Attachment(com.sun.xml.ws.api.message.Attachment) AttachmentPart(jakarta.xml.soap.AttachmentPart) SOAPMessage(jakarta.xml.soap.SOAPMessage) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) SOAPException(jakarta.xml.soap.SOAPException) MessageContext(com.oracle.webservices.api.message.MessageContext) MIMEPartStreamingDataHandler(com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler)

Example 15 with SOAPMessage

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

the class SAAJMessageTest method testMtomAttachment.

public void testMtomAttachment() throws Exception {
    String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
    MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
    Packet packet = (Packet) m1;
    Message message = packet.getInternalMessage();
    Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
    Attachment att = null;
    int counter = 0;
    String cid1 = null;
    while (as.hasNext()) {
        att = as.next();
        cid1 = att.getContentId();
        counter++;
    }
    assertTrue(counter == 1);
    // SAAJFactory:
    SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
    SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
    SaajStaxWriterEx writer = new SaajStaxWriterEx(msg, soapVersion.nsUri);
    try {
        message.writeTo(writer);
    } catch (XMLStreamException e) {
        throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
    }
    msg = writer.getSOAPMessage();
    counter = 0;
    String cid2 = null;
    for (Attachment a : message.getAttachments()) {
        counter++;
        cid2 = a.getContentId();
    }
    assertTrue(writer.ma.size() == counter);
    StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
    assertEquals(cid1, sdh.getHrefCid());
    assertEquals(cid2, sdh.getHrefCid());
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) Attachment(com.sun.xml.ws.api.message.Attachment) SOAPMessage(jakarta.xml.soap.SOAPMessage) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) SOAPException(jakarta.xml.soap.SOAPException) MessageContext(com.oracle.webservices.api.message.MessageContext) MIMEPartStreamingDataHandler(com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler)

Aggregations

SOAPMessage (jakarta.xml.soap.SOAPMessage)181 MessageFactory (jakarta.xml.soap.MessageFactory)66 ByteArrayInputStream (java.io.ByteArrayInputStream)51 SOAPBody (jakarta.xml.soap.SOAPBody)37 SOAPException (jakarta.xml.soap.SOAPException)36 QName (javax.xml.namespace.QName)31 MimeHeaders (jakarta.xml.soap.MimeHeaders)27 Source (javax.xml.transform.Source)25 StreamSource (javax.xml.transform.stream.StreamSource)25 WebServiceException (jakarta.xml.ws.WebServiceException)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)19 Element (org.w3c.dom.Element)18 Node (org.w3c.dom.Node)18 Packet (com.sun.xml.ws.api.message.Packet)17 Message (com.sun.xml.ws.api.message.Message)16 Iterator (java.util.Iterator)14 SOAPElement (jakarta.xml.soap.SOAPElement)12 AttachmentPart (jakarta.xml.soap.AttachmentPart)11 Dispatch (jakarta.xml.ws.Dispatch)10