Search in sources :

Example 1 with MTOMFeature

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

the class PacketTest method testEncodeDecodedPacketMtom.

/**
 * Tests that a server response Packet with MTOM feature, but
 * decoded from an InputStream with a user specified non-MTOM
 * content type, does NOT use MTOM when re-encoded
 */
public void testEncodeDecodedPacketMtom() throws Exception {
    String msg = "<?xml version='1.0' encoding='UTF-8'?>" + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Body><soapenv:Fault>" + "<faultcode>soapenv:Server</faultcode>" + "<faultstring>ABC-380001:Internal Server Error</faultstring>" + "<detail><con:fault xmlns:con=\"http://www.bea.com/wli/sb/context\">" + "<con:errorCode>ABC-380001</con:errorCode>" + "<con:reason>Internal Server Error</con:reason>" + "<con:location><con:node>RouteNode1</con:node><con:path>response-pipeline</con:path></con:location>" + "</con:fault></detail>" + "</soapenv:Fault></soapenv:Body></soapenv:Envelope>";
    WebServiceFeature[] features = { new MTOMFeature(true, 0) };
    MessageContextFactory mcf = new MessageContextFactory(features);
    Packet fakeRequest = (Packet) mcf.createContext();
    Packet p = (Packet) mcf.createContext(new ByteArrayInputStream(msg.getBytes()), "text/xml");
    fakeRequest.relateServerResponse(p, null, null, BindingImpl.create(BindingID.SOAP11_HTTP, features));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    p.writeTo(bos);
    String writtenMsg = new String(bos.toByteArray());
    System.out.println(writtenMsg);
    assertEquals("text/xml", p.getContentType().getContentType());
    // try reading the message as a soap message with text/xml - this should succeed
    // in parsing the message
    Packet reReadPacket = (Packet) mcf.createContext(new ByteArrayInputStream(writtenMsg.getBytes()), "text/xml");
    SOAPMessage soap = reReadPacket.getAsSOAPMessage();
    Node bodyChild = soap.getSOAPBody().getFirstChild();
    assertEquals("Fault", bodyChild.getLocalName());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) Node(org.w3c.dom.Node) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 2 with MTOMFeature

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

the class WebServiceFeatureList method getFeature.

/**
 * Returns a corresponding feature for a feature annotation(i.e which has
 * {@link WebServiceFeatureAnnotation} meta annotation)
 *
 * @return corresponding feature for the annotation
 *         null, if the annotation is nota feature annotation
 */
public static WebServiceFeature getFeature(Annotation a) {
    WebServiceFeature ftr = null;
    if (!(a.annotationType().isAnnotationPresent(WebServiceFeatureAnnotation.class))) {
        ftr = null;
    } else if (a instanceof Addressing) {
        Addressing addAnn = (Addressing) a;
        try {
            ftr = new AddressingFeature(addAnn.enabled(), addAnn.required(), addAnn.responses());
        } catch (NoSuchMethodError e) {
            // throw error. We can't default to Responses.ALL as we dont know if the user has not used 2.2 annotation with responses.
            throw new RuntimeModelerException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(Addressing.class))));
        }
    } else if (a instanceof MTOM) {
        MTOM mtomAnn = (MTOM) a;
        ftr = new MTOMFeature(mtomAnn.enabled(), mtomAnn.threshold());
    } else if (a instanceof RespectBinding) {
        RespectBinding rbAnn = (RespectBinding) a;
        ftr = new RespectBindingFeature(rbAnn.enabled());
    } else {
        ftr = getWebServiceFeatureBean(a);
    }
    return ftr;
}
Also used : MTOM(jakarta.xml.ws.soap.MTOM) AddressingFeature(jakarta.xml.ws.soap.AddressingFeature) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) RespectBindingFeature(jakarta.xml.ws.RespectBindingFeature) ImpliesWebServiceFeature(com.sun.xml.ws.api.ImpliesWebServiceFeature) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) RespectBinding(jakarta.xml.ws.RespectBinding) RuntimeModelerException(com.sun.xml.ws.model.RuntimeModelerException) Addressing(jakarta.xml.ws.soap.Addressing)

Example 3 with MTOMFeature

use of jakarta.xml.ws.soap.MTOMFeature 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 4 with MTOMFeature

use of jakarta.xml.ws.soap.MTOMFeature 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 5 with MTOMFeature

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

the class MtomApp method main.

public static void main(String[] args) {
    try {
        MtomSample port = new MtomService().getMtomPort(new MTOMFeature());
        if (port == null) {
            System.out.println("FAILURE: Couldnt get port!");
            System.exit(-1);
        }
        testUpload(port);
        testDownload(port);
    } catch (Exception ex) {
        System.out.println("SOAP 1.2 MtomApp FAILED!");
        ex.printStackTrace();
    }
}
Also used : MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) IOException(java.io.IOException)

Aggregations

MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)22 BindingProvider (jakarta.xml.ws.BindingProvider)7 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)5 SOAPMessage (jakarta.xml.soap.SOAPMessage)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IOException (java.io.IOException)4 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)3 Message (com.sun.xml.ws.api.message.Message)3 Packet (com.sun.xml.ws.api.message.Packet)3 DataHandler (jakarta.activation.DataHandler)3 AttachmentPart (jakarta.xml.soap.AttachmentPart)3 MessageFactory (jakarta.xml.soap.MessageFactory)3 MimeHeaders (jakarta.xml.soap.MimeHeaders)3 InputStream (java.io.InputStream)3 QName (javax.xml.namespace.QName)3 MessageContext (com.oracle.webservices.api.message.MessageContext)2 BindingID (com.sun.xml.ws.api.BindingID)2 ImpliesWebServiceFeature (com.sun.xml.ws.api.ImpliesWebServiceFeature)2 StreamingDataHandler (com.sun.xml.ws.developer.StreamingDataHandler)2