Search in sources :

Example 6 with DataSource

use of javax.activation.DataSource in project camel by apache.

the class AttachmentHttpBinding method populateAttachments.

@Override
protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
    try {
        Collection<Part> parts = request.getParts();
        for (Part part : parts) {
            DataSource ds = new PartDataSource(part);
            Attachment attachment = new DefaultAttachment(ds);
            for (String headerName : part.getHeaderNames()) {
                for (String headerValue : part.getHeaders(headerName)) {
                    attachment.addHeader(headerName, headerValue);
                }
            }
            message.addAttachmentObject(part.getName(), attachment);
        }
    } catch (Exception e) {
        throw new RuntimeCamelException("Cannot populate attachments", e);
    }
}
Also used : Part(javax.servlet.http.Part) DefaultAttachment(org.apache.camel.impl.DefaultAttachment) Attachment(org.apache.camel.Attachment) RuntimeCamelException(org.apache.camel.RuntimeCamelException) DefaultAttachment(org.apache.camel.impl.DefaultAttachment) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) DataSource(javax.activation.DataSource)

Example 7 with DataSource

use of javax.activation.DataSource in project nhin-d by DirectProject.

the class DirectDocuments method toProvideAndRegisterDocumentSetRequestType.

public ProvideAndRegisterDocumentSetRequestType toProvideAndRegisterDocumentSetRequestType() throws IOException {
    ProvideAndRegisterDocumentSetRequestType request = new ProvideAndRegisterDocumentSetRequestType();
    request.setSubmitObjectsRequest(this.getSubmitObjectsRequest());
    for (DirectDocument2 document : documents) {
        if (document.getData() != null) {
            DataSource source = new ByteArrayDataSource(document.getData(), document.getMetadata().getMimeType());
            DataHandler dhnew = new DataHandler(source);
            Document pdoc = new Document();
            pdoc.setValue(dhnew);
            String id = document.getMetadata().getId();
            pdoc.setId(id);
            request.getDocument().add(pdoc);
        }
    }
    return request;
}
Also used : DataHandler(javax.activation.DataHandler) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 8 with DataSource

use of javax.activation.DataSource in project nhin-d by DirectProject.

the class DefaultXdmXdsTransformer method transform.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.transform.XdmXdsTransformer#transform(java.io.File)
     */
@Override
public ProvideAndRegisterDocumentSetRequestType transform(File file) throws TransformationException {
    LOGGER.trace("Begin transformation of XDM to XDS (file)");
    String docId = null;
    ZipFile zipFile = null;
    String docName = getDocName(file);
    if (docName != null) {
        XDM_FILENAME_DATA = docName;
    }
    ProvideAndRegisterDocumentSetRequestType prsr = new ProvideAndRegisterDocumentSetRequestType();
    try {
        zipFile = new ZipFile(file, ZipFile.OPEN_READ);
        Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
        ZipEntry zipEntry = null;
        // load the ZIP archive into memory
        while (zipEntries.hasMoreElements()) {
            zipEntry = zipEntries.nextElement();
            String zname = zipEntry.getName();
            LOGGER.trace("Processing a ZipEntry " + zname);
            if (!zipEntry.isDirectory()) {
                String subsetDirspec = getSubmissionSetDirspec(zipEntry.getName());
                // Read metadata
                if (matchName(zname, subsetDirspec, XDM_FILENAME_METADATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    SubmitObjectsRequest submitObjectRequest = (SubmitObjectsRequest) XmlUtils.unmarshal(byteArrayOutputStream.toString(), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
                    prsr.setSubmitObjectsRequest(submitObjectRequest);
                    docId = getDocId(submitObjectRequest);
                } else // Read data
                if (matchName(zname, subsetDirspec, XDM_FILENAME_DATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    DataSource source = new ByteArrayDataSource(byteArrayOutputStream.toByteArray(), MimeType.APPLICATION_XML + "; charset=UTF-8");
                    DataHandler dhnew = new DataHandler(source);
                    Document pdoc = new Document();
                    pdoc.setValue(dhnew);
                    pdoc.setId(docId);
                    List<Document> docs = prsr.getDocument();
                    docs.add(pdoc);
                }
            }
            if (!prsr.getDocument().isEmpty()) {
                ((Document) prsr.getDocument().get(0)).setId(zname);
            }
        }
        zipFile.close();
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to complete transformation.", e);
        }
        throw new TransformationException("Unable to complete transformation.", e);
    }
    return prsr;
}
Also used : TransformationException(org.nhindirect.xd.transform.exception.TransformationException) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataHandler(javax.activation.DataHandler) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) SubmitObjectsRequest(oasis.names.tc.ebxml_regrep.xsd.lcm._3.SubmitObjectsRequest) TransformationException(org.nhindirect.xd.transform.exception.TransformationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) ZipFile(java.util.zip.ZipFile) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Example 9 with DataSource

use of javax.activation.DataSource in project Activiti by Activiti.

the class MailActivityBehavior method execute.

@Override
public void execute(ActivityExecution execution) {
    boolean doIgnoreException = Boolean.parseBoolean(getStringFromField(ignoreException, execution));
    String exceptionVariable = getStringFromField(exceptionVariableName, execution);
    Email email = null;
    try {
        String toStr = getStringFromField(to, execution);
        String fromStr = getStringFromField(from, execution);
        String ccStr = getStringFromField(cc, execution);
        String bccStr = getStringFromField(bcc, execution);
        String subjectStr = getStringFromField(subject, execution);
        String textStr = textVar == null ? getStringFromField(text, execution) : getStringFromField(getExpression(execution, textVar), execution);
        String htmlStr = htmlVar == null ? getStringFromField(html, execution) : getStringFromField(getExpression(execution, htmlVar), execution);
        String charSetStr = getStringFromField(charset, execution);
        List<File> files = new LinkedList<File>();
        List<DataSource> dataSources = new LinkedList<DataSource>();
        getFilesFromFields(attachments, execution, files, dataSources);
        email = createEmail(textStr, htmlStr, attachmentsExist(files, dataSources));
        addTo(email, toStr);
        setFrom(email, fromStr, execution.getTenantId());
        addCc(email, ccStr);
        addBcc(email, bccStr);
        setSubject(email, subjectStr);
        setMailServerProperties(email, execution.getTenantId());
        setCharset(email, charSetStr);
        attach(email, files, dataSources);
        email.send();
    } catch (ActivitiException e) {
        handleException(execution, e.getMessage(), e, doIgnoreException, exceptionVariable);
    } catch (EmailException e) {
        handleException(execution, "Could not send e-mail in execution " + execution.getId(), e, doIgnoreException, exceptionVariable);
    }
    leave(execution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Email(org.apache.commons.mail.Email) HtmlEmail(org.apache.commons.mail.HtmlEmail) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) SimpleEmail(org.apache.commons.mail.SimpleEmail) EmailException(org.apache.commons.mail.EmailException) File(java.io.File) LinkedList(java.util.LinkedList) DataSource(javax.activation.DataSource)

Example 10 with DataSource

use of javax.activation.DataSource in project zm-mailbox by Zimbra.

the class TextPlainHandler method getContentImpl.

@Override
protected String getContentImpl() throws MimeHandlerException {
    if (content == null) {
        DataSource source = getDataSource();
        if (source != null) {
            String ctype = source.getContentType();
            InputStream is = null;
            try {
                Reader reader = Mime.getTextReader(is = source.getInputStream(), ctype, getDefaultCharset());
                content = ByteUtil.getContent(reader, MimeHandlerManager.getIndexedTextLimit(), false);
            } catch (IOException e) {
                throw new MimeHandlerException(e);
            } finally {
                ByteUtil.closeStream(is);
            }
        }
    }
    if (content == null) {
        content = "";
    }
    return content;
}
Also used : MimeHandlerException(com.zimbra.cs.mime.MimeHandlerException) InputStream(java.io.InputStream) Reader(java.io.Reader) IOException(java.io.IOException) DataSource(javax.activation.DataSource)

Aggregations

DataSource (javax.activation.DataSource)53 DataHandler (javax.activation.DataHandler)31 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)16 InputStream (java.io.InputStream)12 MimeMultipart (javax.mail.internet.MimeMultipart)11 OMFactory (org.apache.axiom.om.OMFactory)11 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)11 MimeBodyPart (javax.mail.internet.MimeBodyPart)10 IOException (java.io.IOException)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 FileDataSource (javax.activation.FileDataSource)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 OMElement (org.apache.axiom.om.OMElement)7 File (java.io.File)6 Reader (java.io.Reader)5 QName (javax.xml.namespace.QName)5 MimeHandlerException (com.zimbra.cs.mime.MimeHandlerException)4 Document (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document)4 URI (java.net.URI)4 Multipart (javax.mail.Multipart)4