PDA

View Full Version : Embedding the Reporting Engine Into a Java Application



tanbui
08-13-2014, 02:44 AM
Hi,

Pentaho Reporting works great inside Java Web App. But I run into issues below:

Report generated with a set of parameters. The problem is that creates a lot of files/folders inside Web Server because users can view the same report with his input at the same time. That why I cannot override the generated report by newer one. So When/How I should remove/delete it?

Any one can help?

Best,

Taqua
08-13-2014, 07:39 AM
The most simple solution I recommend is to bind a session listener to your HTTP session and to clean up the report's data when the session ends. To make that easy, generate a session-id (not the one used in the cookie, but just a UUID object stored on the session) and use that as part of the directory name that holds the report data.

So lets assume you store your temp-files in the temp-directory:

${TEMP}/

then each user's report data would go into a subdirectory under it

${TEMP}/${UUID}/

and when the session finishes, you can safely delete that directory and all its files. That delete operation can be a one-liners with the help of Commons-IO's FileUtils#deleteDirectory (http://commons.apache.org/proper/commons-io/javadocs/api-release/src-html/org/apache/commons/io/FileUtils.html#line.1529) method.

Why use a extra UUID and not the user's name or login info? The same user may be logged in via two different browsers or devices and then would generate conflicts. Killing/timing out the session on his first browser will also kill his content of the still-alive second session.

Why not use the session ID the servlet framework maintains? Exposing the session id anywhere is a security risk. If its not on disk, it cannot be seen by any attacker and thus they wont be able to steal sessions from legitimate users.