Search in sources :

Example 1 with MessageContextFactory

use of com.oracle.webservices.api.message.MessageContextFactory in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method testWriteMtomToStreamClientRequest.

public void testWriteMtomToStreamClientRequest() throws Exception {
    // DISI may set the packet.state to State.ClientRequest
    // ((Packet)mc).setState(State.ClientRequest)
    InputStream is = null;
    ByteArrayOutputStream baos = null;
    ByteArrayInputStream bais = null;
    try {
        String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<ff2b0fb4-9bcf-4ff5-ba16-d3436c78c3fd>\"; " + "type=\"application/xop+xml\"; start-info=\"text/xml\"";
        MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
        is = getClass().getClassLoader().getResourceAsStream("etc/testMtomMessage_osb_disi.msg");
        MessageContext mc = mcf.createContext(is, ctype);
        Packet packet = (Packet) mc;
        Message message = packet.getInternalMessage();
        assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
        baos = new ByteArrayOutputStream();
        ((Packet) mc).setState(State.ClientRequest);
        mc.writeTo(baos);
        bais = new ByteArrayInputStream(baos.toByteArray());
        MessageFactory mf = MessageFactory.newInstance();
        MimeHeaders mh = new MimeHeaders();
        mh.addHeader("Content-Type", ctype);
        SOAPMessage sm = mf.createMessage(mh, bais);
        assertEquals("wrong attachment count", 1, sm.countAttachments());
        AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
        assertEquals("wrong attachemnt Content-Id", "<testAttachmentContentId>", ap.getContentId());
        NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
        assertEquals(MtomCodec.XOP_NAMESPACEURI + ":" + MtomCodec.XOP_LOCALNAME + " not found", 1, nl.getLength());
        Element elt = (Element) nl.item(0);
        assertEquals("wrong href value", "cid:testAttachmentContentId", elt.getAttribute("href"));
    } finally {
        Exception e = null;
        try {
            if (is != null)
                is.close();
        } catch (IOException e1) {
            e = e1;
        }
        try {
            if (baos != null)
                baos.close();
        } catch (IOException e2) {
            e = e2;
        }
        try {
            if (bais != null)
                bais.close();
        } catch (Exception e3) {
            e = e3;
        }
        if (e != null)
            throw e;
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(jakarta.xml.soap.SOAPMessage) IOException(java.io.IOException) MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) MessageContext(com.oracle.webservices.api.message.MessageContext)

Example 2 with MessageContextFactory

use of com.oracle.webservices.api.message.MessageContextFactory in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method testWriteMtomToStream.

public void testWriteMtomToStream() throws Exception {
    // Ensure writing StreamMessage to OutputputStream preserves CID and
    // does not create duplicate attachment.  We check this by re-parsing
    // as a SOAP message and verifying the contents.
    InputStream is = null;
    ByteArrayOutputStream baos = null;
    ByteArrayInputStream bais = null;
    try {
        String ctype = "multipart/related;type=\"application/xop+xml\";" + "boundary=\"----=_Part_0_1145105632.1353005695468\";" + "start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
        MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
        is = getClass().getClassLoader().getResourceAsStream("etc/testMtomMessageReload_01.msg");
        MessageContext mc = mcf.createContext(is, ctype);
        Packet packet = (Packet) mc;
        Message message = packet.getInternalMessage();
        assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
        baos = new ByteArrayOutputStream();
        mc.writeTo(baos);
        bais = new ByteArrayInputStream(baos.toByteArray());
        MessageFactory mf = MessageFactory.newInstance();
        MimeHeaders mh = new MimeHeaders();
        mh.addHeader("Content-Type", ctype);
        SOAPMessage sm = mf.createMessage(mh, bais);
        assertEquals("wrong attachment count", 1, sm.countAttachments());
        AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
        assertEquals("wrong attachemnt Content-Id", "<534475ae-bdab-4594-9f97-c09908bacfbd>", ap.getContentId());
        NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
        assertEquals(MtomCodec.XOP_NAMESPACEURI + ":" + MtomCodec.XOP_LOCALNAME + " not found", 1, nl.getLength());
        Element elt = (Element) nl.item(0);
        assertEquals("wrong href value", "cid:534475ae-bdab-4594-9f97-c09908bacfbd", elt.getAttribute("href"));
    } finally {
        Exception e = null;
        try {
            if (is != null)
                is.close();
        } catch (IOException e1) {
            e = e1;
        }
        try {
            if (baos != null)
                baos.close();
        } catch (IOException e2) {
            e = e2;
        }
        try {
            if (bais != null)
                bais.close();
        } catch (Exception e3) {
            e = e3;
        }
        if (e != null)
            throw e;
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(jakarta.xml.soap.SOAPMessage) IOException(java.io.IOException) MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) MessageContext(com.oracle.webservices.api.message.MessageContext)

Example 3 with MessageContextFactory

use of com.oracle.webservices.api.message.MessageContextFactory 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 4 with MessageContextFactory

use of com.oracle.webservices.api.message.MessageContextFactory in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method testWriteSwaToStreamClientRequest.

// Bug 17367334
public void testWriteSwaToStreamClientRequest() throws Exception {
    String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<6232425701115978772--54bee05.140acdf4f8a.-7f3f>\"; " + "type=\"text/xml\"; start-info=\"text/xml\"";
    MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
    InputStream is = getClass().getClassLoader().getResourceAsStream("etc/bug17367334InputMsg.txt");
    Packet packet = (Packet) mcf.createContext(is, ctype);
    Message message = packet.getInternalMessage();
    assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    packet.setState(State.ClientRequest);
    // System.out.println("SWA packet.getContentType(): " + packet.getContentType().getContentType() );
    ContentType contentType = packet.writeTo(baos);
    // System.out.println("etc/bug17367334InputMsg.txt\r\n" + contentType.getContentType() + "\r\n" + new String(baos.toByteArray()));
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    MessageFactory mf = MessageFactory.newInstance();
    MimeHeaders mh = new MimeHeaders();
    mh.addHeader("Content-Type", ctype);
    SOAPMessage sm = mf.createMessage(mh, bais);
    assertEquals("wrong attachment count", 1, sm.countAttachments());
    AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
    assertEquals("wrong attachemnt Content-Id", "<testAttachmentContentId>", ap.getContentId());
// NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) ContentType(com.oracle.webservices.api.message.ContentType) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) MimeHeaders(jakarta.xml.soap.MimeHeaders) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 5 with MessageContextFactory

use of com.oracle.webservices.api.message.MessageContextFactory in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method testEmptySoapHeader.

public void testEmptySoapHeader() throws Exception {
    String soap = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" + "<soap:Header xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'></soap:Header>" + "<soapenv:Body>" + "  <tes:fooOwsmMsgProtection xmlns:tes='http://testOwsm'>" + "   <!--Optional:-->" + "    <arg0>string</arg0>" + "  </tes:fooOwsmMsgProtection>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    MessageContextFactory mcf = MessageContextFactory.createFactory();
    MessageContext mc = mcf.createContext(new ByteArrayInputStream(soap.getBytes()), "text/xml");
    String string1 = mc.toString();
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    mc.writeTo(bo);
    String string2 = new String(bo.toByteArray());
    assertTrue(string1.indexOf("Header") != -1);
    assertTrue(string2.indexOf("Header") != -1);
}
Also used : MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContext(com.oracle.webservices.api.message.MessageContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)6 SOAPMessage (jakarta.xml.soap.SOAPMessage)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 MessageContext (com.oracle.webservices.api.message.MessageContext)4 Message (com.sun.xml.ws.api.message.Message)4 Packet (com.sun.xml.ws.api.message.Packet)4 AttachmentPart (jakarta.xml.soap.AttachmentPart)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 MessageFactory (jakarta.xml.soap.MessageFactory)3 MimeHeaders (jakarta.xml.soap.MimeHeaders)3 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)3 IOException (java.io.IOException)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 Databinding (com.oracle.webservices.api.databinding.Databinding)1 DatabindingFactory (com.oracle.webservices.api.databinding.DatabindingFactory)1 ContentType (com.oracle.webservices.api.message.ContentType)1 SAAJFactory (com.sun.xml.ws.api.message.saaj.SAAJFactory)1 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)1