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:pivotal.au.se.gemfirexdweb.controller.CreateTypeController.java

@RequestMapping(value = "/createtype", method = RequestMethod.POST)
public String createTypeAction(@ModelAttribute("typeAttribute") Type typeAttribute, 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 {/*  w  w  w .ja va  2s  .  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 UDT (Type)");

    String schema = typeAttribute.getSchemaName().trim();

    if (schema.length() == 0) {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("New Type schema name = " + schema);
    logger.debug("New Type name = " + typeAttribute.getTypeName());

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

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

        createType.append("CREATE TYPE " + schema + "." + typeAttribute.getTypeName() + " \n");
        createType.append("EXTERNAL NAME '" + typeAttribute.getJavaClassName() + "' \n");
        createType.append("LANGUAGE JAVA \n");

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

            logger.debug("Creating UDT Type as -> " + createType.toString());

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

            model.addAttribute("result", result);

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

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

    }

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

From source file:us.mn.state.health.lims.reports.action.CommonReportPrintAction.java

@SuppressWarnings("unchecked")
@Override/*from www  .ja va  2 s  .c  o m*/
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    BaseActionForm dynaForm = (BaseActionForm) form;

    PropertyUtils.setProperty(dynaForm, "reportType", request.getParameter("type"));

    IReportCreator reportCreator = ReportImplementationFactory.getReportCreator(request.getParameter("report"));

    String forward = FWD_FAIL;

    if (reportCreator != null) {
        reportCreator.initializeReport(dynaForm);
        reportCreator.setReportPath(getReportPath());

        HashMap<String, String> parameterMap = (HashMap<String, String>) reportCreator.getReportParameters();
        parameterMap.put("SUBREPORT_DIR", getReportPath());

        try {

            response.setContentType(reportCreator.getContentType());
            String responseHeaderName = reportCreator.getResponseHeaderName();
            String responseHeaderContent = reportCreator.getResponseHeaderContent();
            if (!GenericValidator.isBlankOrNull(responseHeaderName)
                    && !GenericValidator.isBlankOrNull(responseHeaderContent)) {
                response.setHeader(responseHeaderName, responseHeaderContent);
            }

            byte[] bytes = reportCreator.runReport();

            response.setContentLength(bytes.length);

            ServletOutputStream servletOutputStream = response.getOutputStream();

            servletOutputStream.write(bytes, 0, bytes.length);
            servletOutputStream.flush();
            servletOutputStream.close();
        } catch (Exception e) {
            LogEvent.logErrorStack("CommonReportPrintAction", "performAction", e);
            e.printStackTrace();
        }
    }

    if ("patient".equals(request.getParameter("type"))) {
        trackReports(reportCreator, request.getParameter("report"), ReportType.PATIENT);
    }

    return mapping.findForward(forward);
}

From source file:jetbrains.buildServer.torrent.web.TorrentLinksController.java

@Nullable
@Override//  w w w  .  ja  v  a2s  . c om
protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
        throws Exception {
    String buildIdParam = request.getParameter("buildId");
    if (buildIdParam == null) {
        return null;
    }

    try {
        long buildId = Long.parseLong(buildIdParam);
        SBuild build = myServer.findBuildInstanceById(buildId);
        if (build != null && myConfigurator.isDownloadEnabled()) {
            Collection<File> torrentFiles = myTorrentsManager.getTorrentFiles(build);
            File baseDir = myTorrentsManager.getTorrentFilesBaseDir(build);
            List<String> paths = getArtifactsWithTorrents(baseDir, torrentFiles);

            response.setContentType("text/plain");
            ServletOutputStream output = response.getOutputStream();
            try {
                for (String name : paths) {
                    output.println(name);
                }
            } finally {
                output.close();
            }
        }
    } catch (Exception e) {
        // ignore
    }

    return null;
}

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

@RequestMapping(value = "/addwriter", method = RequestMethod.POST)
public String createWriterAction(@ModelAttribute("writerAttribute") AddWriter writerAttribute, 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   ww  w  .  j  av  a2 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 Table Writer");

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

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

        addWriter.append("CALL SYS.ATTACH_WRITER ('" + writerAttribute.getSchemaName() + "', \n");
        addWriter.append("'" + writerAttribute.getTableName() + "', \n");
        addWriter.append("'" + writerAttribute.getFunctionString() + "', \n");

        if (!checkIfParameterEmpty(request, "initInfoString")) {
            addWriter.append("'" + writerAttribute.getInitInfoString() + "', \n");
        } else {
            addWriter.append("NULL, \n");
        }

        if (!checkIfParameterEmpty(request, "serverGroups")) {
            addWriter.append("'" + writerAttribute.getServerGroups() + "')");
        } else {
            addWriter.append("NULL), \n");
        }

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

            logger.debug("Creating Table Writer as -> " + addWriter.toString());

            result = GemFireXDWebDAOUtil.runStoredCommand(addWriter.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

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

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

    }

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

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

@RequestMapping(value = "/createschema", method = RequestMethod.POST)
public String createSchemaAction(@ModelAttribute("schemaAttribute") NewSchema schemaAttribute, 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   ww w  .j  a  va 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 Schema");

    model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key")));

    String schema = schemaAttribute.getSchemaName();

    logger.debug("New Schema name = " + schema);

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

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

        createSchema.append("CREATE SCHEMA ");

        if (!checkIfParameterEmpty(request, "authorizationSchema")) {
            createSchema.append("AUTHORIZATION " + schemaAttribute.getAuthorizationSchema() + " \n");
        } else {
            createSchema.append(schema + " \n");
        }

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

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

            logger.debug("Creating Schema as -> " + createSchema.toString());

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

            model.addAttribute("result", result);
            model.addAttribute("chosenSchema", schemaAttribute.getAuthorizationSchema());

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

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

    }

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

From source file:com.hp.security.jauth.admin.controller.BaseController.java

@RequestMapping("index")
public void index(HttpServletRequest request, HttpServletResponse response)
        throws IOException, TemplateException {
    Map<String, Object> root = new HashMap<String, Object>();
    String view = freemarkerUtil.buildView(root, "main");
    response.setContentType("text/html");
    ServletOutputStream out = response.getOutputStream();
    out.write(view.getBytes());/*from w w w . jav a  2  s.c o  m*/
    out.flush();
    out.close();
}

From source file:cn.shengyuan.yun.admin.system.controller.CommonController.java

@RequestMapping(value = "/captchaImage", method = RequestMethod.GET)
public String captchaImage(HttpServletRequest request, HttpServletResponse response) throws Exception {

    response.setDateHeader("Expires", 0);
    // Set standard HTTP/1.1 no-cache headers.
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");
    // return a jpeg
    response.setContentType("image/jpeg");
    // create the text for the image
    String capText = captchaProducer.createText();
    // store the text in the session
    request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText);
    // create the image with the text
    BufferedImage bi = captchaProducer.createImage(capText);
    ServletOutputStream out = response.getOutputStream();
    // write the data out
    ImageIO.write(bi, "jpg", out);
    try {//from  w ww  .  j  av  a2  s . c  o  m
        out.flush();
    } finally {
        out.close();
    }
    return null;

}

From source file:org.nuxeo.ecm.platform.groups.audit.seam.ExportGroupManagementActions.java

public String downloadExcelAllGroupsExport() throws ClientException {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext econtext = context.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) econtext.getResponse();
    File excelReport = excelExportAllGroupsDefinition();

    response.setContentType(new MimetypesFileTypeMap().getContentType(excelReport));
    response.setHeader("Content-disposition", "attachment; filename=\"" + excelReport.getName() + "\"");
    response.setHeader("Content-Length", String.valueOf(excelReport.length()));
    try {//from www.  jav a2  s . co  m
        ServletOutputStream os = response.getOutputStream();
        InputStream in = new FileInputStream(excelReport);
        FileUtils.copy(in, os);
        os.flush();
        in.close();
        os.close();
        context.responseComplete();
    } catch (Exception e) {
        log.error("Failure : " + e.getMessage());
    }
    return null;
}

From source file:org.nuxeo.ecm.platform.groups.audit.seam.ExportGroupManagementActions.java

public String downloadExcelListedGroupsExport() throws ClientException {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext econtext = context.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) econtext.getResponse();
    File excelReport = excelExportListedGroupsDefinition();

    response.setContentType(new MimetypesFileTypeMap().getContentType(excelReport));
    response.setHeader("Content-disposition", "attachment; filename=\"" + excelReport.getName() + "\"");
    response.setHeader("Content-Length", String.valueOf(excelReport.length()));
    try {//from  w w w  . j a va 2 s .  c  o  m
        ServletOutputStream os = response.getOutputStream();
        InputStream in = new FileInputStream(excelReport);
        FileUtils.copy(in, os);
        os.flush();
        in.close();
        os.close();
        context.responseComplete();
    } catch (Exception e) {
        log.error("Failure : " + e.getMessage());
    }
    return null;
}

From source file:org.obm.push.impl.ResponderImpl.java

private void writeData(byte[] data, String type) throws IOException {
    resp.setContentType(type);/*from   w  w w  .  j ava 2 s .co  m*/
    resp.setContentLength(data.length);
    ServletOutputStream out = resp.getOutputStream();
    out.write(data);
    out.flush();
    out.close();
}