1 18 19 package cowsultants.itracker.web.servlets; 20 21 import java.io.*; 22 import java.rmi.*; 23 import java.util.*; 24 import javax.ejb.*; 25 import javax.rmi.*; 26 import javax.naming.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 import cowsultants.itracker.ejb.client.interfaces.*; 31 import cowsultants.itracker.ejb.client.models.*; 32 import cowsultants.itracker.ejb.client.util.*; 33 34 public class ReportDownloadController extends GenericController { 35 InitialContext ic; 36 37 public ReportDownloadController() { 38 } 39 40 public void init(ServletConfig config) { 41 try { 42 ic = new InitialContext(); 43 } catch(NamingException ne) { 44 Logger.logError("Could not locate session EJB during initalization.", ne); 45 } 46 } 47 48 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 49 if(! isLoggedInWithRedirect(request, response)) { 50 return; 51 } 52 53 HttpSession session = request.getSession(); 54 UserModel user = (UserModel) session.getAttribute("user"); 55 try { 56 Object rhRef = ic.lookup("java:comp/env/" + ReportHandler.JNDI_NAME); 57 ReportHandlerHome rhHome = (ReportHandlerHome) PortableRemoteObject.narrow(rhRef, ReportHandlerHome.class); 58 ReportHandler rh = rhHome.create(); 59 60 Integer reportId = null; 61 ReportModel report = null; 62 63 try { 64 reportId = new Integer ((request.getParameter("id") == null ? "-1" : (request.getParameter("id")))); 65 report = rh.getReport(reportId); 66 } catch(NumberFormatException nfe) { 67 if(Logger.isLoggingDebug()) { 68 Logger.logDebug("Invalid reportId " + request.getParameter("id") + " specified."); 69 } 70 } 71 72 if(report == null) { 73 forward("/error.jsp", request, response); 74 return; 75 } 76 77 response.setHeader("Content-Disposition", "attachment; filename=report" + report.getId() + "\""); 78 ServletOutputStream out = response.getOutputStream(); 79 out.write(rh.getReportFile(reportId)); 80 out.close(); 81 } catch(CreateException ce) { 82 } catch(NamingException ne) { 83 } catch(IOException ioe) { 84 Logger.logInfo("Unable to display report.", ioe); 85 } 86 87 return; 88 } 89 } | Popular Tags |