I need help regarding the ManagedExecutorService (I´m using Wildfly).
I have in my JSF Bean (Controller) a method like this:
public void doSendEmail() {
myEjbean.sendOffer(offer);
}
This will call my EJB function: I would like to create now a PDF:
PipedOutputStream createPdfWithAttachments(DocumentDesigner documentDesigner, String fileName) {
List<InputStream> inputStreamList = new ArrayList<InputStream>();
// 1) Add InputStream (which should be added before the document from 2)
// // Diese hinzufügen bei: inputStreamList.add(inputStream);
// 2) Create Document (from a URL)
PipedOutputStream createPdf(PipedOutputStream os, DocumentDesigner documentDesigner, boolean preview)
inputStreamList.add(isDocument);
// 3) Add InputStream (Stream which should be attach after the document)
// Diese hinzufügen bei: inputStreamList.add(inputStream);
// 4) Merge PDF
PipedOutputStream is = pdfGenerationHelperService.mergePdf(inputStreamList, fileName);
return is;
}
In another function, I´m calling this function to create the InputStream and attach that to an object for my Email Attachment:
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
os = pdfDocumentGenerationService.createPdfWithAttachments(offer.getDocumentDesigner(),
fileName, false);
EmailAttachment emailAttachment = new EmailAttachment();
emailAttachment.setInputStream(is);
emailAttachment.setFilename(fileName);
emailAttachment.setMimeType("application/pdf");
I´m currently struggeling when I should use this:
managedExecutorService.submit(() -> {
try {
doSomething();
}
catch (Exception e) {}
return null;
});
It seems inside the createPdf - function I need this managedExecutorService.submit(() -> {...} otherwise it will not work. Here the code for this function:
/**
* Create PDF
*
* @throws IOException
*/
public PipedOutputStream createPdf(PipedOutputStream os, DocumentDesigner documentDesigner, boolean preview)
throws IOException {
managedExecutorService.submit(() -> {
try {
String url = generateUrl(documentDesigner, preview);
PdfRendererBuilder builder = new PdfRendererBuilder();
XRLog.setLevel(XRLog.CSS_PARSE, Level.SEVERE);
XRLog.setLoggingEnabled(false);
// builder.withUri(new URL(url).toString());
Document doc = html5ParseDocument(url, 0);
builder.withW3cDocument(doc, url);
builder.toStream(os);
builder.run();
os.close();
return os;
}
catch (Exception e) {
LOGGER.error(ExceptionUtils.getFullStackTrace(e));
}
return null;
});
return null;
}
I would like to know when I have to use managedExecutorService.submit(() -> and can I have nested managedExecutorService.submit(() ?
In general what I´m trying to do here:
- Send an email with a "Offer" - Object
- Offer will be generated as PDF
- PDF will merge other PDF´s to it
- Attach the PDF to EmailAttachment
- Send Email
Many thanks for help