Search in sources :

Example 1 with Attachment

use of com.sun.xml.ws.api.message.Attachment 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 2 with Attachment

use of com.sun.xml.ws.api.message.Attachment 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)

Example 3 with Attachment

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

the class EndpointMessageContextImpl method get.

@Override
@SuppressWarnings("element-type-mismatch")
public Object get(Object key) {
    if (packet.supports(key)) {
        // strongly typed
        return packet.get(key);
    }
    if (packet.getHandlerScopePropertyNames(true).contains(key)) {
        // no such application-scope property
        return null;
    }
    Object value = packet.invocationProperties.get(key);
    // add the attachments from the Message to the corresponding attachment property
    if (key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) || key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)) {
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if (atts == null)
            atts = new HashMap<>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for (Attachment att : attSet) {
            atts.put(att.getContentId(), att.asDataHandler());
        }
        return atts;
    }
    return value;
}
Also used : AttachmentSet(com.sun.xml.ws.api.message.AttachmentSet) Attachment(com.sun.xml.ws.api.message.Attachment) DataHandler(jakarta.activation.DataHandler)

Example 4 with Attachment

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

the class SwaMimeAttachmentTest method testAttachmentContentId.

public void testAttachmentContentId() throws Exception {
    WSDLPort wsdlPort = getWSDLPort(getResource("WSW2JDLSwaTestService.wsdl"));
    Class proxySEIClass = SwaTest1.class;
    WebServiceFeature[] f = { databindingMode() };
    DatabindingConfig cliConfig = new DatabindingConfig();
    cliConfig.setContractClass(proxySEIClass);
    cliConfig.setFeatures(f);
    cliConfig.setWsdlPort(wsdlPort);
    cliConfig.setWsdlPort(wsdlPort);
    cliConfig.getMappingInfo().setServiceName(new QName("http://SwaTestService.org/wsdl", "WSIDLSwaTestService"));
    Databinding cli = (Databinding) factory.createRuntime(cliConfig);
    URL url1 = getResource("attach.text");
    URL url2 = getResource("attach.html");
    URL url3 = getResource("attach.xml");
    URL url4 = getResource("attach.jpeg1");
    URL url5 = getResource("attach.jpeg2");
    DataHandler dh1 = new DataHandler(url1);
    DataHandler dh2 = new DataHandler(url2);
    DataHandler dh3 = new DataHandler(url3);
    // DataHandler dh4 = new DataHandler(url4);
    // DataHandler dh5 = new DataHandler(url5);
    jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach1 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
    attach1.value = dh1;
    jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach2 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
    attach2.value = dh2;
    jakarta.xml.ws.Holder<javax.xml.transform.Source> attach3 = new jakarta.xml.ws.Holder<javax.xml.transform.Source>();
    attach3.value = new StreamSource(dh3.getInputStream());
    jakarta.xml.ws.Holder<java.awt.Image> attach4 = new jakarta.xml.ws.Holder<java.awt.Image>();
    jakarta.xml.ws.Holder<java.awt.Image> attach5 = new jakarta.xml.ws.Holder<java.awt.Image>();
    attach4.value = javax.imageio.ImageIO.read(url4);
    attach5.value = javax.imageio.ImageIO.read(url5);
    VoidRequest request = new VoidRequest();
    Object[] args = { request, attach1, attach2, attach3, attach4, attach5 };
    Method method = findMethod(proxySEIClass, "echoAllAttachmentTypes");
    JavaCallInfo cliCall = cli.createJavaCallInfo(method, args);
    Packet cliSoapReq = (Packet) cli.serializeRequest(cliCall);
    SOAPMessageContextImpl smc = new SOAPMessageContextImpl(null, cliSoapReq, null);
    Map<String, DataHandler> smcAtts1 = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    smc.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, smcAtts1);
    assertEquals(5, smcAtts1.size());
    for (String cid : smcAtts1.keySet()) assertTrue(cid.charAt(0) != '<');
    for (com.sun.xml.ws.api.message.Attachment a : cliSoapReq.getMessage().getAttachments()) assertTrue(a.getContentId().charAt(0) != '<');
    Object s1 = cliSoapReq.getAsSOAPMessage();
    Object s2 = smc.getMessage();
    assertTrue(s1 == s2);
    for (com.sun.xml.ws.api.message.Attachment a : cliSoapReq.getMessage().getAttachments()) assertTrue(a.getContentId().charAt(0) != '<');
    // {
    // Map<String, DataHandler> atts = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    // AttachmentSet attSet = cliSoapReq.getMessage().getAttachments();
    // for(String cid : atts.keySet()){
    // if (attSet.get(cid) == null) {  // Otherwise we would be adding attachments twice
    // Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
    // attSet.add(att);
    // }
    // }
    // }
    Map<String, DataHandler> smcAtts2 = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    assertEquals(5, smcAtts1.size());
    for (String cid : smcAtts2.keySet()) assertTrue(cid.charAt(0) != '<');
}
Also used : DataHandler(jakarta.activation.DataHandler) Image(java.awt.Image) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) Databinding(com.sun.xml.ws.api.databinding.Databinding) Attachment(com.sun.xml.ws.api.message.Attachment) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) Packet(com.sun.xml.ws.api.message.Packet) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) Method(java.lang.reflect.Method) SOAPMessageContextImpl(com.sun.xml.ws.handler.SOAPMessageContextImpl) DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) HashMap(java.util.HashMap) Map(java.util.Map) MailcapCommandMap(jakarta.activation.MailcapCommandMap) CommandMap(jakarta.activation.CommandMap)

Example 5 with Attachment

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

the class SwaMimeAttachmentTest method testCustomAttachmentContentId.

public void testCustomAttachmentContentId() throws Exception {
    WSDLPort wsdlPort = getWSDLPort(getResource("WSW2JDLSwaTestService.wsdl"));
    Class proxySEIClass = SwaTest1.class;
    WebServiceFeature[] f = { databindingMode() };
    DatabindingConfig cliConfig = new DatabindingConfig();
    cliConfig.setContractClass(proxySEIClass);
    cliConfig.setFeatures(f);
    cliConfig.setWsdlPort(wsdlPort);
    cliConfig.setWsdlPort(wsdlPort);
    cliConfig.getMappingInfo().setServiceName(new QName("http://SwaTestService.org/wsdl", "WSIDLSwaTestService"));
    Databinding cli = (Databinding) factory.createRuntime(cliConfig);
    URL url1 = getResource("attach.text");
    URL url2 = getResource("attach.html");
    URL url3 = getResource("attach.xml");
    URL url4 = getResource("attach.jpeg1");
    URL url5 = getResource("attach.jpeg2");
    DataHandler dh1 = new DataHandler(url1);
    DataHandler dh2 = new DataHandler(url2);
    DataHandler dh3 = new DataHandler(url3);
    DataHandler dh4 = new DataHandler(url4);
    // DataHandler dh5 = new DataHandler(url5);
    jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach1 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
    attach1.value = dh1;
    jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach2 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
    attach2.value = dh2;
    jakarta.xml.ws.Holder<javax.xml.transform.Source> attach3 = new jakarta.xml.ws.Holder<javax.xml.transform.Source>();
    attach3.value = new StreamSource(dh3.getInputStream());
    jakarta.xml.ws.Holder<java.awt.Image> attach4 = new jakarta.xml.ws.Holder<java.awt.Image>();
    jakarta.xml.ws.Holder<java.awt.Image> attach5 = new jakarta.xml.ws.Holder<java.awt.Image>();
    attach4.value = javax.imageio.ImageIO.read(url4);
    attach5.value = javax.imageio.ImageIO.read(url5);
    VoidRequest request = new VoidRequest();
    Object[] args = { request, attach1, attach2, attach3, attach4, attach5 };
    Method method = findMethod(proxySEIClass, "echoAllAttachmentTypes");
    JavaCallInfo cliCall = cli.createJavaCallInfo(method, args);
    Packet cliSoapReq = (Packet) cli.serializeRequest(cliCall);
    String customContentId = "<abcd@example.org>";
    Map<String, DataHandler> attMap = new HashMap<String, DataHandler>();
    attMap.put(customContentId, dh4);
    cliSoapReq.invocationProperties.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attMap);
    SOAPMessageContextImpl smc = new SOAPMessageContextImpl(null, cliSoapReq, null);
    Map<String, DataHandler> smcAtts1 = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    assertEquals(6, smcAtts1.size());
    assertNotNull(smcAtts1.get(customContentId));
    {
        // ClientSOAPHandlerTube.callHandlersOnRequest
        Map<String, DataHandler> atts = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
        AttachmentSet attSet = cliSoapReq.getMessage().getAttachments();
        for (String cid : atts.keySet()) {
            if (attSet.get(cid) == null) {
                // Otherwise we would be adding attachments twice
                Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
                attSet.add(att);
            }
        }
    }
    int attCount = 0;
    for (com.sun.xml.ws.api.message.Attachment a : cliSoapReq.getMessage().getAttachments()) {
        // assertTrue(a.getContentId().charAt(0)!='<');
        attCount++;
    }
    assertEquals(6, attCount);
    Object s1 = cliSoapReq.getAsSOAPMessage();
    Object s2 = smc.getMessage();
    assertTrue(s1 == s2);
    int attCountSaaj = 0;
    for (com.sun.xml.ws.api.message.Attachment a : cliSoapReq.getMessage().getAttachments()) {
        assertTrue(a.getContentId().charAt(0) != '<');
        attCountSaaj++;
    }
    assertEquals(6, attCountSaaj);
    Map<String, DataHandler> smcAtts2 = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    assertEquals(6, smcAtts2.size());
    // System.out.println(smcAtts2.size() + " " + smcAtts2);
    assertNotNull(smcAtts2.get(customContentId));
}
Also used : DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) HashMap(java.util.HashMap) DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) Attachment(com.sun.xml.ws.api.message.Attachment) DataHandler(jakarta.activation.DataHandler) Image(java.awt.Image) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) Databinding(com.sun.xml.ws.api.databinding.Databinding) AttachmentSet(com.sun.xml.ws.api.message.AttachmentSet) Attachment(com.sun.xml.ws.api.message.Attachment) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) Packet(com.sun.xml.ws.api.message.Packet) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) Method(java.lang.reflect.Method) SOAPMessageContextImpl(com.sun.xml.ws.handler.SOAPMessageContextImpl) DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) HashMap(java.util.HashMap) Map(java.util.Map) MailcapCommandMap(jakarta.activation.MailcapCommandMap) CommandMap(jakarta.activation.CommandMap)

Aggregations

Attachment (com.sun.xml.ws.api.message.Attachment)20 DataHandler (jakarta.activation.DataHandler)12 AttachmentSet (com.sun.xml.ws.api.message.AttachmentSet)9 DataHandlerAttachment (com.sun.xml.ws.message.DataHandlerAttachment)8 Map (java.util.Map)7 HashMap (java.util.HashMap)5 Packet (com.sun.xml.ws.api.message.Packet)4 Message (com.sun.xml.ws.api.message.Message)3 StreamingDataHandler (com.sun.xml.ws.developer.StreamingDataHandler)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 JavaCallInfo (com.oracle.webservices.api.databinding.JavaCallInfo)2 MessageContext (com.oracle.webservices.api.message.MessageContext)2 Nullable (com.sun.istack.Nullable)2 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)2 Databinding (com.sun.xml.ws.api.databinding.Databinding)2 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)2 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)2 Codec (com.sun.xml.ws.api.pipe.Codec)2 MIMEPartStreamingDataHandler (com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler)2 SOAPMessageContextImpl (com.sun.xml.ws.handler.SOAPMessageContextImpl)2