Search in sources :

Example 1 with SAAJFactory

use of com.sun.xml.ws.api.message.saaj.SAAJFactory in project metro-jax-ws by eclipse-ee4j.

the class SAAJFactoryTest method testResetDefaultNamespaceToGlobalWithJDK.

/**
 * Test whether SAAJFactory.readAsSOAPMessage can handle default namespace reset correctly.
 *
 * <p>
 * This test emulates JDK-8159058 issue. The issue is that the default namespace reset was not respected
 * with built-in JDK XML input factory (it worked well with woodstax).
 * </p>
 *
 * <p>
 * This test operates against JDK XMLInputFactory.
 * </p>
 */
public void testResetDefaultNamespaceToGlobalWithJDK() throws Exception {
    XMLInputFactory inputFactory = getBuiltInJdkXmlInputFactory();
    XMLStreamReader envelope = inputFactory.createXMLStreamReader(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<s:Body>" + "<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>" + "</s:Body>" + "</s:Envelope>"));
    StreamMessage streamMessage = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
    SAAJFactory saajFac = new SAAJFactory();
    SOAPMessage soapMessage = saajFac.readAsSOAPMessage(SOAPVersion.SOAP_11, streamMessage);
    // check object model
    SOAPElement request = (SOAPElement) soapMessage.getSOAPBody().getFirstChild();
    assertEquals("SampleServiceRequest", request.getLocalName());
    assertEquals("http://sample.ex.org/", request.getNamespaceURI());
    SOAPElement params = (SOAPElement) request.getFirstChild();
    assertEquals("RequestParams", params.getLocalName());
    assertNull(params.getNamespaceURI());
    SOAPElement param1 = (SOAPElement) params.getFirstChild();
    assertEquals("Param1", param1.getLocalName());
    assertNull(param1.getNamespaceURI());
    Element param2 = (Element) params.getChildNodes().item(1);
    assertEquals("Param2", param2.getLocalName());
    assertNull(param2.getNamespaceURI());
    // check the message as string
    assertEquals("<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>", nodeToText(request));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SAAJFactory(com.sun.xml.ws.api.message.saaj.SAAJFactory) SOAPElement(jakarta.xml.soap.SOAPElement) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) SOAPElement(jakarta.xml.soap.SOAPElement) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) SOAPMessage(jakarta.xml.soap.SOAPMessage) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 2 with SAAJFactory

use of com.sun.xml.ws.api.message.saaj.SAAJFactory in project metro-jax-ws by eclipse-ee4j.

the class SAAJFactoryTest method testDuplicatedContentID.

public void testDuplicatedContentID() throws Exception {
    String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<6232425701115978772--54bee05.140acdf4f8a.-7f3f>\"; " + "type=\"text/xml\"; start-info=\"text/xml\"";
    InputStream is = getClass().getClassLoader().getResourceAsStream("etc/bug17367334InputMsg.txt");
    MessageContextFactory mcf = MessageContextFactory.createFactory();
    Packet packet = (Packet) mcf.createContext(is, ctype);
    Message message = packet.getInternalMessage();
    SAAJFactory factory = new SAAJFactory();
    SOAPMessage saajMessage = factory.readAsSOAPMessage(SOAPVersion.SOAP_11, message);
    AttachmentPart ap = (AttachmentPart) saajMessage.getAttachments().next();
    Iterator it = ap.getAllMimeHeaders();
    int countContentID = 0;
    while (it.hasNext()) {
        MimeHeader mh = (MimeHeader) it.next();
        if ("Content-Id".equalsIgnoreCase(mh.getName())) {
            countContentID++;
        }
    }
    assertEquals("More than one Content-Id", 1, countContentID);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) SAAJFactory(com.sun.xml.ws.api.message.saaj.SAAJFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MimeHeader(jakarta.xml.soap.MimeHeader) Iterator(java.util.Iterator) AttachmentPart(jakarta.xml.soap.AttachmentPart) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 3 with SAAJFactory

use of com.sun.xml.ws.api.message.saaj.SAAJFactory in project metro-jax-ws by eclipse-ee4j.

the class SAAJFactoryTest method testNullNamespacePrefix.

/**
 * Test whether SAAJFactory.readAsSOAPMessage can handle null namespace prefixes if the
 * appropriate flag is set on Woodstox
 */
public void testNullNamespacePrefix() throws Exception {
    XMLInputFactory infact = XMLInputFactory.newFactory();
    try {
        // for Woodstox, set property that ensures it will return null prefixes for default namespace
        infact.setProperty("com.ctc.wstx.returnNullForDefaultNamespace", Boolean.TRUE);
    } catch (Throwable t) {
        // is unreliable
        return;
    }
    String soap = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body>" + "<sendMessage xmlns=\"http://www.foo.bar/schema/\" xmlns:ns2=\"http://www.foo.bar/types/\">;" + "    <message xsi:type=\"ns2:someType\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "</message>" + "</sendMessage></soap:Body></soap:Envelope>";
    XMLStreamReader envelope = infact.createXMLStreamReader(new StringReader(soap));
    StreamMessage smsg = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
    SAAJFactory saajFac = new SAAJFactory();
    try {
        // Previously this line failed with NPE - should be fixed now.
        SOAPMessage msg = saajFac.readAsSOAPMessage(SOAPVersion.SOAP_11, smsg);
    } catch (NullPointerException npe) {
        fail("NPE for null namespace prefix is not fixed!");
        npe.printStackTrace();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SAAJFactory(com.sun.xml.ws.api.message.saaj.SAAJFactory) StringReader(java.io.StringReader) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) SOAPMessage(jakarta.xml.soap.SOAPMessage) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 4 with SAAJFactory

use of com.sun.xml.ws.api.message.saaj.SAAJFactory in project metro-jax-ws by eclipse-ee4j.

the class SAAJFactoryTest method testResetDefaultNamespaceToGlobalWithWoodstax.

/**
 * Test whether SAAJFactory.readAsSOAPMessage can handle default namespace reset correctly.
 *
 * <p>
 * This test emulates JDK-8159058 issue. The issue is that the default namespace reset was not respected
 * with built-in JDK XML input factory (it worked well with woodstax).
 * </p>
 *
 * <p>
 * This test operates against woodstax.
 * </p>
 */
public void testResetDefaultNamespaceToGlobalWithWoodstax() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newFactory();
    XMLStreamReader envelope = inputFactory.createXMLStreamReader(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<s:Body>" + "<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>" + "</s:Body>" + "</s:Envelope>"));
    StreamMessage streamMessage = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
    SAAJFactory saajFac = new SAAJFactory();
    SOAPMessage soapMessage = saajFac.readAsSOAPMessage(SOAPVersion.SOAP_11, streamMessage);
    // check object model
    SOAPElement request = (SOAPElement) soapMessage.getSOAPBody().getFirstChild();
    assertEquals("SampleServiceRequest", request.getLocalName());
    assertEquals("http://sample.ex.org/", request.getNamespaceURI());
    SOAPElement params = (SOAPElement) request.getFirstChild();
    assertEquals("RequestParams", params.getLocalName());
    assertNull(params.getNamespaceURI());
    SOAPElement param1 = (SOAPElement) params.getFirstChild();
    assertEquals("Param1", param1.getLocalName());
    assertNull(param1.getNamespaceURI());
    Element param2 = (Element) params.getChildNodes().item(1);
    assertEquals("Param2", param2.getLocalName());
    assertNull(param2.getNamespaceURI());
    // check the message as string
    assertEquals("<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>", nodeToText(request));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SAAJFactory(com.sun.xml.ws.api.message.saaj.SAAJFactory) SOAPElement(jakarta.xml.soap.SOAPElement) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) SOAPElement(jakarta.xml.soap.SOAPElement) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) SOAPMessage(jakarta.xml.soap.SOAPMessage) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

SAAJFactory (com.sun.xml.ws.api.message.saaj.SAAJFactory)4 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)4 SOAPMessage (jakarta.xml.soap.SOAPMessage)4 StringReader (java.io.StringReader)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 SOAPElement (jakarta.xml.soap.SOAPElement)2 Element (org.w3c.dom.Element)2 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)1 Message (com.sun.xml.ws.api.message.Message)1 Packet (com.sun.xml.ws.api.message.Packet)1 AttachmentPart (jakarta.xml.soap.AttachmentPart)1 MimeHeader (jakarta.xml.soap.MimeHeader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Iterator (java.util.Iterator)1