use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class SwAServiceImpl method echoData.
public void echoData(Holder<String> text, Holder<DataHandler> data) {
try {
InputStream bis = null;
bis = data.value.getDataSource().getInputStream();
byte[] b = new byte[6];
bis.read(b, 0, 6);
String string = IOUtils.newStringFromBytes(b);
ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
data.value = new DataHandler(source);
} catch (IOException e) {
e.printStackTrace();
}
}
use of javax.mail.util.ByteArrayDataSource in project cxf by apache.
the class SwAServiceImpl method echoDataRef.
public void echoDataRef(Holder<DataStruct> data) {
try {
InputStream bis = null;
bis = data.value.getDataRef().getDataSource().getInputStream();
byte[] b = new byte[6];
bis.read(b, 0, 6);
String string = IOUtils.newStringFromBytes(b);
ByteArrayDataSource source = new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
data.value.setDataRef(new DataHandler(source));
} catch (IOException e) {
e.printStackTrace();
}
}
use of javax.mail.util.ByteArrayDataSource in project kernel by exoplatform.
the class MailServiceImpl method sendMessage.
/**
* {@inheritDoc}
*/
public void sendMessage(Message message) throws Exception {
MimeMessage mimeMessage = new MimeMessage(getMailSession());
String FROM = message.getFrom();
String TO = message.getTo();
String CC = message.getCC();
String BCC = message.getBCC();
String subject = message.getSubject();
String mimeType = message.getMimeType();
String body = message.getBody();
List<Attachment> attachment = message.getAttachment();
// set From to the message
if (FROM != null && !FROM.equals("")) {
InternetAddress sentFrom = new InternetAddress(FROM);
mimeMessage.setFrom(sentFrom);
}
// set To to the message
InternetAddress[] sendTo = new InternetAddress[getArrs(TO).length];
for (int i = 0; i < getArrs(TO).length; i++) {
sendTo[i] = new InternetAddress(getArrs(TO)[i]);
}
mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO, sendTo);
// set CC to the message
if ((getArrs(CC) != null) && (getArrs(CC).length > 0)) {
InternetAddress[] copyTo = new InternetAddress[getArrs(CC).length];
for (int i = 0; i < getArrs(CC).length; i++) {
copyTo[i] = new InternetAddress(getArrs(CC)[i]);
}
mimeMessage.setRecipients(javax.mail.Message.RecipientType.CC, copyTo);
}
// set BCC to the message
if ((getArrs(BCC) != null) && (getArrs(BCC).length > 0)) {
InternetAddress[] bccTo = new InternetAddress[getArrs(BCC).length];
for (int i = 0; i < getArrs(BCC).length; i++) {
bccTo[i] = new InternetAddress(getArrs(BCC)[i]);
}
mimeMessage.setRecipients(javax.mail.Message.RecipientType.BCC, bccTo);
}
// set Subject to the message
mimeMessage.setSubject(subject);
mimeMessage.setSubject(message.getSubject(), "UTF-8");
mimeMessage.setSentDate(new Date());
MimeMultipart multipPartRoot = new MimeMultipart("mixed");
MimeMultipart multipPartContent = new MimeMultipart("alternative");
if (attachment != null && attachment.size() != 0) {
MimeBodyPart contentPartRoot = new MimeBodyPart();
if (mimeType != null && mimeType.indexOf("text/plain") > -1)
contentPartRoot.setContent(body, "text/plain; charset=utf-8");
else
contentPartRoot.setContent(body, "text/html; charset=utf-8");
MimeBodyPart mimeBodyPart1 = new MimeBodyPart();
mimeBodyPart1.setContent(body, mimeType);
multipPartContent.addBodyPart(mimeBodyPart1);
multipPartRoot.addBodyPart(contentPartRoot);
for (Attachment att : attachment) {
InputStream is = att.getInputStream();
MimeBodyPart mimeBodyPart = new MimeBodyPart();
ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(is, att.getMimeType());
mimeBodyPart.setDataHandler(new DataHandler(byteArrayDataSource));
mimeBodyPart.setDisposition(Part.ATTACHMENT);
if (att.getName() != null)
mimeBodyPart.setFileName(MimeUtility.encodeText(att.getName(), "utf-8", null));
multipPartRoot.addBodyPart(mimeBodyPart);
}
mimeMessage.setContent(multipPartRoot);
} else {
if (mimeType != null && mimeType.indexOf("text/plain") > -1)
mimeMessage.setContent(body, "text/plain; charset=utf-8");
else
mimeMessage.setContent(body, "text/html; charset=utf-8");
}
sendMessage(mimeMessage);
}
use of javax.mail.util.ByteArrayDataSource in project VaadinUtils by rlsutton1.
the class JasperManager method run.
@Override
public void run() {
JRSwapFileVirtualizer fileVirtualizer = null;
CleanupCallback cleanupCallback = null;
boolean initialized = false;
try {
logger.warn("{} permits are available", concurrentLimit.availablePermits());
concurrentLimit.acquire();
initialized = true;
inQueue = false;
queueEntry.setStatus("Gathering report data phase 1");
reportProperties.initDBConnection();
cleanupCallback = reportProperties.getCleanupCallback();
List<ReportParameter<?>> extraParams = reportProperties.prepareData(params, reportProperties.getReportFileName(), cleanupCallback);
compileReport();
if (reportProperties.getCustomReportParameterMap() != null) {
boundParams.putAll(reportProperties.getCustomReportParameterMap());
}
if (extraParams != null) {
params.removeAll(extraParams);
params.addAll(extraParams);
}
logger.info("Running report " + reportProperties.getReportFileName());
for (ReportParameter<?> param : params) {
for (String parameterName : param.getParameterNames()) {
bindParameter(param, parameterName);
if (param.displayInreport()) {
// populate dynamically added parameters to display user
// friendly parameters on the report
boundParams.put("ParamDisplay-" + parameterName, param.getDisplayValue(parameterName));
}
logger.info(parameterName + " " + param.getValue(parameterName));
}
}
reportProperties.prepareForOutputFormat(exportMethod);
queueEntry.setStatus("Gathering report data phase 2");
// use file virtualizer to prevent out of heap
String fileName = "/tmp";
JRSwapFile file = new JRSwapFile(fileName, 100, 10);
fileVirtualizer = new JRSwapFileVirtualizer(500, file);
boundParams.put(JRParameter.REPORT_VIRTUALIZER, fileVirtualizer);
if (stop) {
return;
}
if (exportMethod == OutputFormat.CSV) {
boundParams.put(JRParameter.IS_IGNORE_PAGINATION, true);
}
JasperPrint jasper_print = fillReport(exportMethod);
queueEntry.setStatus("Waiting for browser to start streaming");
if (stop) {
return;
}
logger.warn("Output stream is ready");
progressListener.outputStreamReady();
logger.warn("Waiting for reader stream");
if (readerReady.await(10, TimeUnit.SECONDS)) {
outputStream = new PipedOutputStream(inputStream);
writerReady.countDown();
exportMethod.export(jasper_print, outputStream, getPageMonitorConfig(exportMethod.getConfig()), images);
imagesrcs = (images.size() <= 0) ? null : new DataSource[images.size()];
if (imagesrcs != null) {
int xi = 0;
for (Map.Entry<String, byte[]> entry : images.entrySet()) {
ByteArrayDataSource image = new ByteArrayDataSource(entry.getValue(), "image/gif");
image.setName(entry.getKey());
imagesrcs[xi++] = image;
}
}
} else {
logger.error("Couldn't attach to reader stream");
}
Thread.sleep(750);
queueEntry.setStatus("Cleaning up");
} catch (Exception e) {
logger.error(e, e);
} finally {
if (queueEntry != null) {
jobQueue.remove(queueEntry);
queueEntry = null;
}
try {
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
logger.error(e, e);
}
if (cleanupCallback != null) {
try {
cleanupCallback.cleanup();
} catch (Exception e) {
logger.error(e, e);
}
}
if (fileVirtualizer != null) {
try {
fileVirtualizer.cleanup();
} catch (Exception e) {
logger.error(e, e);
}
}
if (initialized) {
concurrentLimit.release();
try {
reportProperties.closeDBConnection();
} catch (Exception e) {
logger.error(e, e);
}
}
completeBarrier.countDown();
if (progressListener != null) {
progressListener.completed();
}
}
}
use of javax.mail.util.ByteArrayDataSource in project VaadinUtils by rlsutton1.
the class RenderedReport method getBodyAsDataSource.
public DataSource getBodyAsDataSource(String fileName, AttachmentType type) throws IOException {
final ByteArrayDataSource body = new ByteArrayDataSource(reportBody, type.toString());
body.setName(fileName);
return body;
}
Aggregations