Search in sources :

Example 1 with StreamingDataHandler

use of com.sun.xml.ws.developer.StreamingDataHandler in project gdmatrix by gdmatrix.

the class DocumentManagerClient method saveContent.

private void saveContent(Content content) throws IOException {
    String contentId = content.getContentId();
    // **** save content data ****
    DataHandler data = content.getData();
    if (data != null) {
        File tempFile = File.createTempFile(contentId, ".data");
        if (data instanceof StreamingDataHandler)
            ((StreamingDataHandler) data).moveTo(tempFile);
        else {
            try (FileOutputStream os = new FileOutputStream(tempFile)) {
                data.writeTo(os);
            }
        }
        // rename file to actual filename
        File contentFile = getContentFile(content);
        if (!tempFile.renameTo(contentFile)) {
            // file already exits
            tempFile.delete();
        }
        content.setData(new DataHandler(new FileDataSource(contentFile)));
    }
    // **** save content properties ****
    {
        File tempFile = File.createTempFile(contentId, ".xml");
        FileOutputStream os = new FileOutputStream(tempFile);
        try {
            Properties properties = new Properties();
            if (content.getContentType() != null) {
                properties.setProperty("contentType", content.getContentType());
            }
            if (content.getFormatId() != null) {
                properties.setProperty("formatId", content.getFormatId());
            }
            if (content.getLanguage() != null) {
                properties.setProperty("language", content.getLanguage());
            }
            if (content.getSize() != null) {
                properties.setProperty("size", String.valueOf(content.getSize()));
            }
            if (content.getCreationDate() != null) {
                properties.setProperty("creationDate", content.getCreationDate());
            }
            if (content.getCaptureDateTime() != null) {
                properties.setProperty("captureDate", content.getCaptureDateTime());
            }
            if (content.getCaptureUserId() != null) {
                properties.setProperty("captureUser", content.getCaptureUserId());
            }
            if (content.getUrl() != null) {
                properties.setProperty("url", content.getUrl());
            }
            properties.storeToXML(os, contentId);
        } finally {
            os.close();
        }
        // rename file to actual filename
        File propertiesFile = getPropertiesFile(contentId);
        if (!tempFile.renameTo(propertiesFile)) {
            // file already exits
            tempFile.delete();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler) JAXWSProperties(com.sun.xml.ws.developer.JAXWSProperties) Properties(java.util.Properties) File(java.io.File)

Example 2 with StreamingDataHandler

use of com.sun.xml.ws.developer.StreamingDataHandler in project gdmatrix by gdmatrix.

the class DocumentManager method getDataFile.

private File getDataFile(Content content) throws Exception {
    File dataFile = null;
    DataHandler dh = content.getData();
    if (// internal
    dh != null) {
        DataSource ds = dh.getDataSource();
        if (ds instanceof javax.activation.FileDataSource) {
            dataFile = ((javax.activation.FileDataSource) ds).getFile();
        } else if (dh instanceof StreamingDataHandler) {
            StreamingDataHandler sdh = (StreamingDataHandler) dh;
            String contentType = content.getContentType() != null ? content.getContentType() : sdh.getContentType();
            dataFile = createTempFile(contentType);
            sdh.moveTo(dataFile);
        } else if (ds != null) {
            String contentType = content.getContentType();
            dataFile = createTempFile(contentType);
            try (InputStream dis = ds.getInputStream()) {
                IOUtils.writeToFile(dis, dataFile);
            }
        }
    }
    return dataFile;
}
Also used : InputStream(java.io.InputStream) DataHandler(javax.activation.DataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler) StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler) File(java.io.File) TemporaryDataSource(org.santfeliu.util.TemporaryDataSource) DataSource(javax.activation.DataSource)

Example 3 with StreamingDataHandler

use of com.sun.xml.ws.developer.StreamingDataHandler in project metro-jax-ws by eclipse-ee4j.

the class MimeApp method validateDataHandler.

private static void validateDataHandler(int expTotal, DataHandler dh) throws IOException {
    // readOnce() doesn't store attachment on the disk in some cases
    // for e.g when only one attachment is in the message
    StreamingDataHandler sdh = (StreamingDataHandler) dh;
    InputStream in = sdh.readOnce();
    byte[] buf = new byte[8192];
    int total = 0;
    int len;
    while ((len = in.read(buf, 0, buf.length)) != -1) {
        for (int i = 0; i < len; i++) {
            if ((byte) ('A' + (total + i) % 26) != buf[i]) {
                System.out.println("FAIL: DataHandler data is different");
            }
        }
        total += len;
        if (total % (8192 * 250) == 0) {
            System.out.println("Total so far=" + total);
        }
    }
    System.out.println();
    if (total != expTotal) {
        System.out.println("FAIL: DataHandler data size is different. Expected=" + expTotal + " Got=" + total);
    }
    in.close();
    sdh.close();
}
Also used : StreamingDataHandler(com.sun.xml.ws.developer.StreamingDataHandler)

Example 4 with StreamingDataHandler

use of com.sun.xml.ws.developer.StreamingDataHandler 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 5 with StreamingDataHandler

use of com.sun.xml.ws.developer.StreamingDataHandler 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

StreamingDataHandler (com.sun.xml.ws.developer.StreamingDataHandler)18 InputStream (java.io.InputStream)5 WebServiceException (jakarta.xml.ws.WebServiceException)4 Attachment (com.sun.xml.ws.api.message.Attachment)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 MessageContext (com.oracle.webservices.api.message.MessageContext)2 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)2 Message (com.sun.xml.ws.api.message.Message)2 Packet (com.sun.xml.ws.api.message.Packet)2 MIMEPartStreamingDataHandler (com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler)2 SOAPException (jakarta.xml.soap.SOAPException)2 SOAPMessage (jakarta.xml.soap.SOAPMessage)2 DataHandler (javax.activation.DataHandler)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 JAXWSProperties (com.sun.xml.ws.developer.JAXWSProperties)1 DataSourceStreamingDataHandler (com.sun.xml.ws.encoding.DataSourceStreamingDataHandler)1 DataHandler (jakarta.activation.DataHandler)1 AttachmentPart (jakarta.xml.soap.AttachmentPart)1 FileOutputStream (java.io.FileOutputStream)1