Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Skip File Generation(Generate report in memory only)
Skip File Generation [message #1794912] Mon, 10 September 2018 23:48
Teran Briggs is currently offline Teran BriggsFriend
Messages: 2
Registered: September 2018
Junior Member
Hi there,

I'm using apache.camel as an event listener, when an XML file is dropped into a directoy camel will call a Java processor method that pulls out an ID from the XML and passes it on to my DocGenerator that uses Birt. I need the DocGenerator to return a File to the processor so that camel can send it to another process.

Is there a way for Birt to not create a physical file in the file system? It would be convenient if I could keep it in memory the whole time.

I know that a File is a physical representation of the file system so I need to think of something else.

Thanks so much for your help and please let me know if I left out any info you need.

Camel code:
	    <description>Generate Report</description>
		<from uri="file:C:\dir\to\watch\"/>
		<setHeader headerName="reportPath">
		<bean ref="processor" method="generateDocument"/>

Processor code:
	public void generateDocument(Exchange exchange)
		processorLogger.debug("--------------------     Generating PDF Document from Report     --------------------");
		Element root = exchangeToElement(exchange);
		String reportPath = exchange.getIn().getHeaders().get("reportPath").toString();
		String id = null;
		List<Element> updatedItems = root.getChildren();
		for (Element item : updatedItems) {
			if (item.getAttribute("name").equals("id")) {
				id = item.getChild("new").getValue();
		// call birt report with id, return PDF doc generated by birt
		DocGenerator generator = new DocGenerator();
		File pdfDoc = generator.createDoc(id, reportPath);

		// update exchage with pdfDoc

DocGenerator code:
public class DocGenerator {
	private IReportEngine engine;

	public DocGenerator() {
		try {
			EngineConfig config = new EngineConfig();
			IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);

			engine = factory.createReportEngine(config);
			System.out.println("Birt report engine is up and running.");
		} catch (Exception ex) {
			System.out.println("Error instantiating the DocGenerator class");

	public void close() {
		// destroy the engine.
		try {
		} catch (Exception e) {
			// Ignore
	public File createDoc(String id, String reportPath) {
		String output = null;
		try {
			IReportRunnable report = engine.openReportDesign(reportPath);
			IRunAndRenderTask task = engine.createRunAndRenderTask(report);
			ByteArrayOutputStream oStream = new ByteArrayOutputStream();
			HashMap parameters = new HashMap();
			parameters.put("id", id);
                        // this method is not included, but it assigns the id to the birt report parameter, this works fine.
			setTaskParameters(report, task, parameters);
			PDFRenderOption pdfOptions = new PDFRenderOption();
			// pdfOptions.setOutputFileName(fullDesiredFilePath);
			// save doc in memory, don't write it to file system;
			output = oStream.toString();

                        // this is what I have so far but I'm obviously working in the wrong direction since this still creates a file in the file system.
                       // I was thinking of creating a temporary File using the OutputStream because I still have the oStream in memory at this point
			File temp = File.createTempFile("birt-pdf", ".pdf");
			BufferedWriter out = new BufferedWriter(new FileWriter(temp));
			return temp;
		} catch (EngineException | IOException ex) {

Eclipse: Kepler (build: 20130614-0229)
JDK: jdk1.7.0_80
Birt: 4.5.0
camel-core: 2.15.2
Previous Topic:Raport don't work
Next Topic:Birt 4.8 ignores height of empty table rows
Goto Forum:

Current Time: Sun Nov 18 22:36:38 GMT 2018

Powered by FUDForum. Page generated in 0.01510 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top