}
logger.debug("Request parameters read sucesfully" + params);
// AUDIT UPDATE
String auditId = request.getParameter("SPAGOBI_AUDIT_ID");
AuditAccessUtils auditAccessUtils = (AuditAccessUtils) request.getSession().getAttribute("SPAGOBI_AUDIT_UTILS");
if (auditAccessUtils != null)
auditAccessUtils.updateAudit(session,(String) profile.getUserUniqueIdentifier(), auditId, new Long(System
.currentTimeMillis()), null, "EXECUTION_STARTED", null, null);
logger.debug("GetConnection...");
JasperReportRunner jasperReportRunner = new JasperReportRunner(session);
logger.debug("GetConnection...");
Connection con = getConnection(requestConnectionName,session,profile,documentId);
if (con == null) {
logger.error("Cannot obtain" + " connection for engine ["
+ this.getClass().getName() + "] control document configurations");
// AUDIT UPDATE
if (auditAccessUtils != null)
auditAccessUtils.updateAudit(session,(String) profile.getUserUniqueIdentifier(), auditId, null, new Long(System
.currentTimeMillis()), "EXECUTION_FAILED", "No connection available", null);
return;
}
try {
String outputType = (params.get(PARAM_OUTPUT_FORMAT) == null)?"html":(String) params.get(PARAM_OUTPUT_FORMAT);
String tmpdir = (String) EnginConf.getInstance().getConfig().getAttribute("GENERALSETTINGS.tmpdir");
if (!tmpdir.startsWith("/")) {
String contRealPath = getServletContext().getRealPath("/");
if (contRealPath.endsWith("\\") || contRealPath.endsWith("/")) {
contRealPath = contRealPath.substring(0, contRealPath.length() - 1);
}
tmpdir = contRealPath + "/" + tmpdir;
}
tmpdir = tmpdir + System.getProperty("file.separator") + "reports";
File dir = new File(tmpdir);
dir.mkdirs();
File tmpFile = File.createTempFile("report", "." + outputType, dir);
OutputStream out = new FileOutputStream(tmpFile);
jasperReportRunner.runReport(con, params, out, getServletContext(), response, request);
out.flush();
out.close();
// if (outputType == null) outputType = "html";
//outputType = ExporterFactory.getDefaultType();
response.setHeader("Content-Disposition", "filename=\"report." + outputType + "\";");
// response.setContentType((String)extensions.get(outputType));
response.setContentLength((int) tmpFile.length());
BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile));
int b = -1;
while ((b = in.read()) != -1) {
response.getOutputStream().write(b);
}
response.getOutputStream().flush();
in.close();
// instant cleaning
tmpFile.delete();
// AUDIT UPDATE
if (auditAccessUtils != null)
auditAccessUtils.updateAudit(session,(String) profile.getUserUniqueIdentifier(), auditId, null, new Long(System
.currentTimeMillis()), "EXECUTION_PERFORMED", null, null);
} catch (Exception e) {
logger.error( "Error during report production \n\n " + e);
// AUDIT UPDATE
if (auditAccessUtils != null)
auditAccessUtils.updateAudit(session,(String) profile.getUserUniqueIdentifier(), auditId, null, new Long(System
.currentTimeMillis()), "EXECUTION_FAILED", e.getMessage(), null);
return;
} finally {
try {
if (con != null && !con.isClosed())