Example usage for javax.servlet ServletOutputStream close

List of usage examples for javax.servlet ServletOutputStream close

Introduction

In this page you can find the example usage for javax.servlet ServletOutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with this stream.

Usage

From source file:com.arcadian.loginservlet.CourseContentServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getParameter("filename") != null) {
        String fileName = request.getParameter("filename");
        File file = new File(request.getServletContext().getAttribute("FILES_DIR") + File.separator + fileName);
        System.out.println("File location on server::" + file.getAbsolutePath());
        ServletContext ctx = getServletContext();
        InputStream fis = new FileInputStream(file);
        String mimeType = ctx.getMimeType(file.getAbsolutePath());
        System.out.println("mime type=" + mimeType);
        response.setContentType(mimeType != null ? mimeType : "application/octet-stream");
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

        ServletOutputStream os = response.getOutputStream();
        byte[] bufferData = new byte[102400];
        int read = 0;
        while ((read = fis.read(bufferData)) != -1) {
            os.write(bufferData, 0, read);
        }//from   w w  w.  j av a 2  s.c om
        os.flush();
        os.close();
        fis.close();
        System.out.println("File downloaded at client successfully");
    }
    processRequest(request, response);
}

From source file:ShowFile.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    String fileName = request.getParameter("file");

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Welcome</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h2>The File</h2>");
    out.println(fileName);// ww w .  ja v  a 2 s.c  o  m
    out.println("</body>");
    out.println("</html>");
    out.close();

}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateGatewaySenderController.java

@RequestMapping(value = "/creategatewaysender", method = RequestMethod.POST)
public String createGatewaySenderAction(
        @ModelAttribute("gatewaySenderAttribute") NewGatewaySender gatewaySenderAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from   www  .  j a  v a  2 s  .c  o  m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create Gateway Sender");

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();

    List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key"));

    model.addAttribute("diskstores", dsks);

    String gatewaySenderName = gatewaySenderAttribute.getGatewaySenderName();

    logger.debug("New Gateway Sender Name = " + gatewaySenderName);

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");
    boolean needCloseBracket = false;

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createGatewaySender = new StringBuffer();

        createGatewaySender.append("CREATE GATEWAYSENDER " + gatewaySenderName + " (\n");
        createGatewaySender.append("REMOTEDSID " + gatewaySenderAttribute.getRemoteSID() + " \n");

        if (!checkIfParameterEmpty(request, "socketBufferSize")) {
            createGatewaySender
                    .append("SOCKETBUFFERSIZE " + gatewaySenderAttribute.getSocketBufferSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "socketReadTimeout")) {
            createGatewaySender
                    .append("SOCKETREADTIMEOUT " + gatewaySenderAttribute.getSocketReadTimeout() + " \n");
        }

        if (!checkIfParameterEmpty(request, "manualStart")) {
            createGatewaySender.append("MANUALSTART " + gatewaySenderAttribute.getManualStart() + " \n");
        }

        if (!checkIfParameterEmpty(request, "enableBatchConflation")) {
            createGatewaySender.append(
                    "ENABLEBATCHCONFLATION " + gatewaySenderAttribute.getEnableBatchConflation() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchSize")) {
            createGatewaySender.append("BATCHSIZE " + gatewaySenderAttribute.getBatchSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchTimeInterval")) {
            createGatewaySender
                    .append("BATCHTIMEINTERVAL " + gatewaySenderAttribute.getBatchTimeInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "enablePersistence")) {
            createGatewaySender
                    .append("ENABLEPERSISTENCE " + gatewaySenderAttribute.getEnablePersistence() + " \n");
            if (gatewaySenderAttribute.getEnablePersistence().equals("TRUE")) {
                if (!checkIfParameterEmpty(request, "diskStore")) {
                    createGatewaySender
                            .append("DISKSTORENAME " + gatewaySenderAttribute.getDiskStore() + " \n");
                }
            }
        }

        if (!checkIfParameterEmpty(request, "maxQueueMemory")) {
            createGatewaySender.append("MAXQUEUEMEMORY " + gatewaySenderAttribute.getMaxQueueMemory() + " \n");
        }

        if (!checkIfParameterEmpty(request, "alertThreshold")) {
            createGatewaySender.append("ALERTTHRESHOLD " + gatewaySenderAttribute.getAlertThreshold() + " \n");
        }

        createGatewaySender.append(") \n");

        if (!checkIfParameterEmpty(request, "serverGroups")) {
            createGatewaySender.append("SERVER GROUPS (" + gatewaySenderAttribute.getServerGroups() + ") \n");
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating gateway sender as -> " + createGatewaySender.toString());

            result = GemFireXDWebDAOUtil.runCommand(createGatewaySender.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create Gateway Sender SQL as follows as -> " + createGatewaySender.toString());
            model.addAttribute("sql", createGatewaySender.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, gatewaySenderName));

            ServletOutputStream out = response.getOutputStream();
            out.println(createGatewaySender.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/create-gatewaysender.jsp
    return "create-gatewaysender";
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateHDFSStoreController.java

@RequestMapping(value = "/createhdfsstore", method = RequestMethod.POST)
public String createHDFSStoreAction(@ModelAttribute("hdfsStoreAttribute") NewHDFSStore hdfsStoreAttribute,
        Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session)
        throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from   w  w w . ja v a  2 s  .  c  o m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create HDFS Store");

    String storeName = hdfsStoreAttribute.getStoreName();
    String nameNode = hdfsStoreAttribute.getNameNode();
    String homeDir = hdfsStoreAttribute.getHomeDir();

    logger.debug("New HDFS Store Name = " + storeName);

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createHDFSStore = new StringBuffer();

        createHDFSStore.append("create HDFSSTORE " + storeName + " \n");
        createHDFSStore.append("NAMENODE '" + nameNode + "' \n");
        createHDFSStore.append("HOMEDIR '" + homeDir + "' \n");

        if (!checkIfParameterEmpty(request, "batchSize")) {
            createHDFSStore.append("BatchSize " + hdfsStoreAttribute.getBatchSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchTimeInterval")) {
            createHDFSStore.append("BatchTimeInterval " + hdfsStoreAttribute.getBatchTimeInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxQueueMemory")) {
            createHDFSStore.append("MaxQueueMemory " + hdfsStoreAttribute.getMaxQueueMemory() + " \n");
        }

        if (!checkIfParameterEmpty(request, "minorCompact")) {
            createHDFSStore.append("MinorCompact " + hdfsStoreAttribute.getMinorCompact() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxInputFileSize")) {
            createHDFSStore.append("MaxInputFileSize " + hdfsStoreAttribute.getMaxInputFileSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "minInputFileCount")) {
            createHDFSStore.append("MinInputFileCount " + hdfsStoreAttribute.getMinInputFileCount() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxInputFileCount")) {
            createHDFSStore.append("MaxInputFileCount " + hdfsStoreAttribute.getMaxInputFileCount() + " \n");
        }

        if (!checkIfParameterEmpty(request, "minorCompactionThreads")) {
            createHDFSStore
                    .append("MinorCompactionThreads " + hdfsStoreAttribute.getMinorCompactionThreads() + " \n");
        }

        if (!checkIfParameterEmpty(request, "majorCompact")) {
            createHDFSStore.append("MajorCompact " + hdfsStoreAttribute.getMajorCompact() + " \n");
        }

        if (!checkIfParameterEmpty(request, "majorCompactionInterval")) {
            createHDFSStore.append(
                    "MajorCompactionInterval " + hdfsStoreAttribute.getMajorCompactionInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "majorCompactionThreads")) {
            createHDFSStore
                    .append("MajorCompactionThreads " + hdfsStoreAttribute.getMajorCompactionThreads() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxWriteOnlyFileSize")) {
            createHDFSStore
                    .append("MaxWriteOnlyFileSize " + hdfsStoreAttribute.getMaxWriteOnlyFileSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "writeOnlyRolloverInterval")) {
            createHDFSStore.append("WriteOnlyFileRolloverInterval "
                    + hdfsStoreAttribute.getWriteOnlyRolloverInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "additionalParams")) {
            createHDFSStore.append(hdfsStoreAttribute.getAdditionalParams());
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating hdfs store as -> " + createHDFSStore.toString());

            result = GemFireXDWebDAOUtil.runCommand(createHDFSStore.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create HDFS Store SQL as follows as -> " + createHDFSStore.toString());
            model.addAttribute("sql", createHDFSStore.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, storeName));

            ServletOutputStream out = response.getOutputStream();
            out.println(createHDFSStore.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/create-table.jsp
    return "create-hdfsstore";
}

From source file:pivotal.au.se.gemfirexdweb.controller.CreateIndexController.java

@RequestMapping(value = "/createindex", method = RequestMethod.POST)
public String createIndexAction(@ModelAttribute("indexAttribute") NewIndex indexAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from  w  ww . j av a  2 s  . c om*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to action an event for create index");

    String tabName = indexAttribute.getTableName();
    String schema = indexAttribute.getSchemaName();
    String unique = indexAttribute.getUnique();
    String idxName = indexAttribute.getIndexName();
    String submit = request.getParameter("pSubmit");

    String[] selectedColumns = request.getParameterValues("selected_column[]");
    String[] indexOrder = request.getParameterValues("idxOrder[]");
    String[] position = request.getParameterValues("position[]");

    logger.debug("selectedColumns = " + Arrays.toString(selectedColumns));
    logger.debug("indexOrder = " + Arrays.toString(indexOrder));
    logger.debug("position = " + Arrays.toString(position));

    IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO();

    List<IndexColumn> columns = indexDAO.retrieveIndexColumns(schema, tabName,
            (String) session.getAttribute("user_key"));

    StringBuffer createIndex = new StringBuffer();

    if (unique.equalsIgnoreCase("Y")) {
        createIndex.append("create unique index " + idxName + " on " + schema + "." + tabName + " ");
    } else {
        createIndex.append("create index " + idxName + " on " + schema + "." + tabName + " ");
    }

    createIndex.append("(");

    if (selectedColumns != null) {
        int i = 0;
        Map<String, IndexDefinition> cols = new HashMap<String, IndexDefinition>();

        for (String column : selectedColumns) {
            String columnName = column.substring(0, column.indexOf("_"));
            String index = column.substring(column.indexOf("_") + 1);
            String pos = position[Integer.parseInt(index) - 1];
            if (pos.trim().length() == 0) {
                pos = "" + i;
            }

            logger.debug("Column = " + columnName + ", indexOrder = " + indexOrder[Integer.parseInt(index) - 1]
                    + ", position = " + pos);

            IndexDefinition idxDef = new IndexDefinition(columnName, indexOrder[Integer.parseInt(index) - 1]);

            cols.put("" + pos, idxDef);
            i++;
        }

        // sort map and create index now
        SortedSet<String> keys = new TreeSet<String>(cols.keySet());
        int length = keys.size();
        i = 0;
        for (String key : keys) {
            IndexDefinition idxDefTemp = cols.get(key);
            if (i == (length - 1)) {
                createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ")");
            } else {
                createIndex.append(idxDefTemp.getColumnName() + " " + idxDefTemp.getOrderType() + ", ");
            }

            i++;

        }
    }

    if (!checkIfParameterEmpty(request, "caseSensitive")) {
        createIndex.append(" " + request.getParameter("caseSensitive") + "\n");
    }

    if (submit.equalsIgnoreCase("create")) {
        Result result = new Result();

        logger.debug("Creating index as -> " + createIndex.toString());

        result = GemFireXDWebDAOUtil.runCommand(createIndex.toString(),
                (String) session.getAttribute("user_key"));

        model.addAttribute("result", result);
        model.addAttribute("tabName", tabName);
        model.addAttribute("tableSchemaName", schema);
        model.addAttribute("columns", columns);
        model.addAttribute("schema", schema);

        session.removeAttribute("numColumns");
    } else if (submit.equalsIgnoreCase("Show SQL")) {
        logger.debug("Index SQL as follows as -> " + createIndex.toString());
        model.addAttribute("sql", createIndex.toString());
        model.addAttribute("tabName", tabName);
        model.addAttribute("tableSchemaName", schema);
        model.addAttribute("columns", columns);
        model.addAttribute("schema", schema);
    } else if (submit.equalsIgnoreCase("Save to File")) {
        response.setContentType(SAVE_CONTENT_TYPE);
        response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, idxName));

        ServletOutputStream out = response.getOutputStream();
        out.println(createIndex.toString());
        out.close();
        return null;
    }
    // This will resolve to /WEB-INF/jsp/create-index.jsp
    return "create-index";
}

From source file:com.arcadian.loginservlet.StudentAssignmentServlet.java

/**
 * Handles the HTTP/*from   w w w .j a  v a 2  s .  c  om*/
 * <code>GET</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (request.getParameter("filename") != null) {
        String fileName = request.getParameter("filename");
        File file = new File(request.getServletContext().getAttribute("FILES_DIR") + File.separator + fileName);
        System.out.println("File location on server::" + file.getAbsolutePath());
        ServletContext ctx = getServletContext();
        InputStream fis = new FileInputStream(file);
        String mimeType = ctx.getMimeType(file.getAbsolutePath());
        System.out.println("mime type=" + mimeType);
        response.setContentType(mimeType != null ? mimeType : "application/octet-stream");
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

        ServletOutputStream os = response.getOutputStream();
        byte[] bufferData = new byte[102400];
        int read = 0;
        while ((read = fis.read(bufferData)) != -1) {
            os.write(bufferData, 0, read);
        }
        os.flush();
        os.close();
        fis.close();
        System.out.println("File downloaded at client successfully");
    }
    processRequest(request, response);
}

From source file:org.primeframework.mvc.action.result.StreamResult.java

/**
 * {@inheritDoc}/*from   ww  w.  j  a v a 2s  .c  om*/
 */
public void execute(Stream stream) throws IOException, ServletException {
    ActionInvocation current = actionInvocationStore.getCurrent();
    Object action = current.action;
    String property = stream.property();
    String length = expand(stream.length(), action, false);
    String name = expand(stream.name(), action, true);
    String type = expand(stream.type(), action, false);

    Object object = expressionEvaluator.getValue(property, action);
    if (object == null || !(object instanceof InputStream)) {
        throw new PrimeException("Invalid property [" + property + "] for Stream result. This "
                + "property returned null or an Object that is not an InputStream.");
    }

    response.setContentType(type);

    if (StringUtils.isNotBlank(length)) {
        response.setContentLength(Integer.parseInt(length));
    }

    if (StringUtils.isNotBlank(name)) {
        response.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\"");
    }

    if (!isCurrentActionHeadRequest(current)) {
        InputStream is = (InputStream) object;
        ServletOutputStream sos = response.getOutputStream();
        try {
            // Then output the file
            byte[] b = new byte[8192];
            int len;
            while ((len = is.read(b)) != -1) {
                sos.write(b, 0, len);
            }
        } finally {
            sos.flush();
            sos.close();
        }
    }
}

From source file:org.sakaiproject.kernel.rest.RestMySitesProvider.java

/**
 * @param response//from  w  ww.j  a va 2  s .c o  m
 * @param itemMap
 * @throws IOException
 */
private void sendOutput(HttpServletResponse response, Map<String, Object> itemMap) throws IOException {
    response.setContentType(RestProvider.CONTENT_TYPE);
    ServletOutputStream outputStream = response.getOutputStream();

    outputStream.print(beanConverter.convertToString(itemMap));

    outputStream.flush();
    outputStream.close();

}

From source file:com.jaeksoft.searchlib.web.ServletTransaction.java

public void sendFile(File file, String filename, String contentType, boolean attach) throws SearchLibException {
    response.setContentType(contentType);
    if (attach)//from   www  . j a v a2s .  com
        response.addHeader("Content-Disposition", "attachment; filename=" + filename);
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
        ServletOutputStream outputStream = getOutputStream();
        IOUtils.copy(inputStream, outputStream);
        outputStream.close();
    } catch (FileNotFoundException e) {
        throw new SearchLibException(e);
    } catch (IOException e) {
        throw new SearchLibException(e);
    } finally {
        IOUtils.close(inputStream);
    }
}

From source file:org.wso2.carbon.reporting.ui.servlet.GraphGenerateServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String type = request.getParameter("reportType");
    String typeSecond = request.getParameter("reportTypeSecond");
    String dataSessionVar = request.getParameter("reportDataSession");
    String component = request.getParameter("component");
    String template = request.getParameter("template");
    String generateType;//w w  w.  ja v a2 s.c o m
    String downloadFileName = null;

    if (type == null) {
        type = " ";
    } else {
        typeSecond = " ";
    }

    if (type.equals("pdf") || typeSecond.equals("pdf")) {
        generateType = "pdf";
        response.setContentType("application/pdf");
        downloadFileName = template + ".pdf";
    } else if (type.equals("excel") || typeSecond.equals("excel")) {
        generateType = "excel";
        response.setContentType("application/vnd.ms-excel");
        downloadFileName = template + ".xsl";
    } else if (type.equals("html") || typeSecond.equals("html")) {
        generateType = "html";
        response.setContentType("text/html");

    } else {
        throw new ReportingException("requested report type can not be support");
    }
    if (downloadFileName != null) {
        response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
    }
    Object reportDataObject = request.getSession().getAttribute(dataSessionVar);
    if (reportDataObject == null) {
        throw new ReportingException("can't generate report , data unavailable in session ");
    }
    try {
        String serverURL = CarbonUIUtil.getServerURL(request.getSession().getServletContext(),
                request.getSession());
        ConfigurationContext configurationContext = (ConfigurationContext) request.getSession()
                .getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        String cookie = (String) request.getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

        ReportResourceSupplierClient resourceSupplierClient = new ReportResourceSupplierClient(cookie,
                serverURL, configurationContext);

        String reportResource = resourceSupplierClient.getReportResources(component, template);
        JRDataSource jrDataSource = new BeanCollectionReportData().getReportDataSource(reportDataObject);
        JasperPrintProvider jasperPrintProvider = new JasperPrintProvider();
        JasperPrint jasperPrint = jasperPrintProvider.createJasperPrint(jrDataSource, reportResource,
                new ReportParamMap[0]);
        request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
        ReportStream reportStream = new ReportStream();
        ByteArrayOutputStream outputStream = reportStream.getReportStream(jasperPrint, generateType);
        ServletOutputStream servletOutputStream = response.getOutputStream();
        try {
            outputStream.writeTo(servletOutputStream);
            outputStream.flush();
        } finally {
            outputStream.close();
            servletOutputStream.close();
        }

    } catch (Exception e) {
        String msg = "Error occurred handling " + template + "report request from " + component;
        log(msg);
        throw e;
    }
}