Example usage for javax.servlet.http HttpServletResponse flushBuffer

List of usage examples for javax.servlet.http HttpServletResponse flushBuffer

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse flushBuffer.

Prototype

public void flushBuffer() throws IOException;

Source Link

Document

Forces any content in the buffer to be written to the client.

Usage

From source file:org.craftercms.cstudio.publishing.servlet.DeployVersionServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter serverOut = response.getWriter();
    try {//from  w  w  w  .j  a v  a2 s .c  o m
        String target = request.getParameter(FileUploadServlet.PARAM_TARGET);
        if (StringUtils.isEmpty(target)) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            serverOut.write("Parameter \"" + FileUploadServlet.PARAM_TARGET + "\" is need");
        } else {
            String currerntVersion = versioningService.readVersion(target);
            response.setStatus(HttpServletResponse.SC_OK);
            serverOut.write(currerntVersion);
        }
    } catch (VersionException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        serverOut.write(ex.getMessage());
    }
    setDefaultHeaders(response);
    serverOut.flush();
    response.flushBuffer();
}

From source file:com.qcadoo.mes.cmmsMachineParts.controller.MaintenanceEventMultiUploadController.java

@RequestMapping(value = "/getAttachmentForEvent.html", method = RequestMethod.GET)
public final void getAttachment(@RequestParam("id") final Long[] ids, HttpServletResponse response) {
    DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "eventAttachment");
    Entity attachment = attachmentDD.get(ids[0]);
    InputStream is = fileService/*  w w w. j av  a2s  .c om*/
            .getInputStream(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT));

    try {
        if (is == null) {
            response.sendRedirect("/error.html?code=404");
        }

        response.setHeader("Content-disposition",
                "inline; filename=" + attachment.getStringField(TechnologyAttachmentFields.NAME));
        response.setContentType(
                fileService.getContentType(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)));

        int bytes = IOUtils.copy(is, response.getOutputStream());
        response.setContentLength(bytes);

        response.flushBuffer();

    } catch (IOException e) {
        logger.error("Unable to copy attachment file to response stream.", e);
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.controller.MachinePartMultiUploadController.java

@RequestMapping(value = "/getAttachment.html", method = RequestMethod.GET)
public final void getAttachment(@RequestParam("id") final Long[] ids, HttpServletResponse response) {
    DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "machinePartAttachment");
    Entity attachment = attachmentDD.get(ids[0]);
    InputStream is = fileService/*from www. ja  v a 2  s  .  com*/
            .getInputStream(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT));

    try {
        if (is == null) {
            response.sendRedirect("/error.html?code=404");
        }

        response.setHeader("Content-disposition",
                "inline; filename=" + attachment.getStringField(TechnologyAttachmentFields.NAME));
        response.setContentType(
                fileService.getContentType(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)));

        int bytes = IOUtils.copy(is, response.getOutputStream());
        response.setContentLength(bytes);

        response.flushBuffer();

    } catch (IOException e) {
        logger.error("Unable to copy attachment file to response stream.", e);
    }
}

From source file:org.nuxeo.ecm.platform.ui.web.auth.krb5.Krb5Authenticator.java

@Override
public Boolean handleLoginPrompt(HttpServletRequest req, HttpServletResponse res, String baseURL) {

    logger.debug("Sending login prompt...");
    if (res.getHeader(WWW_AUTHENTICATE) == null) {
        res.setHeader(WWW_AUTHENTICATE, NEGOTIATE);
    }//from  ww  w. j a  v  a 2  s .c om
    // hack to support fallback to form auth in case the
    // client does not answer the SPNEGO challenge.
    // This will obviously break if form auth is disabled; but this isn't
    // much of an issue since other sso filters will not work nicely after
    // this one (as this one takes over the response and flushes it to start
    // negotiation).
    String refresh = String.format("1;url=/%s/login.jsp", VirtualHostHelper.getWebAppName(req));
    res.setHeader("Refresh", refresh);
    res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    res.setContentLength(0);
    try {
        res.flushBuffer();

    } catch (IOException e) {
        logger.warn("Cannot flush response", e);
    }
    return true;
}

From source file:com.almende.eve.transport.http.DebugServlet.java

/**
 * Handle hand shake.//from w  w w.j a v  a  2s  . co  m
 * 
 * @param req
 *            the req
 * @param res
 *            the res
 * @return true, if successful
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private boolean handleHandShake(final HttpServletRequest req, final HttpServletResponse res)
        throws IOException {
    final String time = req.getHeader("X-Eve-requestToken");

    if (time == null) {
        return false;
    }

    final String url = req.getRequestURI();
    final String id = getId(url);
    final HttpTransport transport = HttpService.get(myUrl, id);
    if (transport != null) {
        final String token = transport.getTokenstore().get(time);
        if (token == null) {
            res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        } else {
            res.setHeader("X-Eve-replyToken", token);
            res.setStatus(HttpServletResponse.SC_OK);
            res.flushBuffer();
        }
    }
    return true;
}

From source file:com.vico.license.controller.LicenseController.java

/**
 * @param serialNumberId/*  w w w .j av  a2 s. co  m*/
 * @return
 * @throws IOException
 * @param:
 * @return: ProcessResult
 * @Title: useLicense
 * @Description: ??
 */
@RequestMapping(value = "uselicense")
public void useLicense(@PathParam("serialNumberId") String serialNumberId, HttpServletResponse response) {
    ProcessResult processResult = new ProcessResult();
    String path = ClassPathResourceURI.getResourceURI("/").getPath();
    boolean creatsucess = false;
    String nameofzip = "license.zip";
    creatsucess = licenseService.createZIPFile(Integer.parseInt(serialNumberId));
    if (!creatsucess) {
        logger.error("?ZIP!");
        return;
    }

    try {
        FileInputStream inputStream1 = new FileInputStream(path + nameofzip);
        response.addHeader("Content-disposition", "attachment;filename=license.zip");
        response.setContentType("zip/plain");
        IOUtils.copy(inputStream1, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        logger.error(e);
    }

    try {
        int i = licenseService.modifyLicenseState(Integer.parseInt(serialNumberId));
        if (i == 1) {
            processResult.setResultcode(ProcessResultEnum.RETURN_RESULT_SUCCESS);
            processResult.setResultdesc(ProcessResultEnum.MODIFY_SUCCESS);
        } else {
            processResult.setResultcode(ProcessResultEnum.RETURN_RESULT_FAIL);
            processResult.setResultdesc(ProcessResultEnum.MODIFY_FAIL);
        }
    } catch (Exception e) {
        logger.error(ProcessResultEnum.MODIFY_ERROR + ProcessResultEnum.getClassPath());
    }
}

From source file:com.vico.license.controller.LicenseController.java

@RequestMapping(value = "uselicense/{serialNumberId}")
public void useLicenseAngu(@PathVariable("serialNumberId") String serialNumberId,
        HttpServletResponse response) {
    ProcessResult processResult = new ProcessResult();
    String path = ClassPathResourceURI.getResourceURI("/").getPath();
    boolean creatsucess = false;
    String nameofzip = "license.zip";
    creatsucess = licenseService.createZIPFile(Integer.parseInt(serialNumberId));
    if (!creatsucess) {
        logger.error("?ZIP!");
        return;/* www  .  j  a  va  2  s  . c  om*/
    }

    try {
        FileInputStream inputStream1 = new FileInputStream(path + nameofzip);
        response.addHeader("Content-disposition", "attachment;filename=license.zip");
        response.setContentType("zip/plain");
        IOUtils.copy(inputStream1, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        logger.error(e);
    }

    try {
        int i = licenseService.modifyLicenseState(Integer.parseInt(serialNumberId));
        if (i == 1) {
            processResult.setResultcode(ProcessResultEnum.RETURN_RESULT_SUCCESS);
            processResult.setResultdesc(ProcessResultEnum.MODIFY_SUCCESS);
        } else {
            processResult.setResultcode(ProcessResultEnum.RETURN_RESULT_FAIL);
            processResult.setResultdesc(ProcessResultEnum.MODIFY_FAIL);
        }
    } catch (Exception e) {
        logger.error(ProcessResultEnum.MODIFY_ERROR + ProcessResultEnum.getClassPath());
    }
}

From source file:org.apache.cocoon.servlet.RequestUtil.java

private static void manageException(HttpServletRequest req, HttpServletResponse res, Environment env,
        String uri, int errorStatus, String title, String message, String description, Exception e,
        ServletSettings settings, boolean verbose, Object sender) throws IOException {
    if (settings.isManageExceptions()) {
        if (env != null) {
            env.tryResetResponse();/*from ww  w.  ja  va  2s . c o m*/
        } else {
            res.reset();
        }

        String type = Notifying.FATAL_NOTIFICATION;
        Map extraDescriptions = null;

        if (errorStatus == HttpServletResponse.SC_NOT_FOUND) {
            type = "resource-not-found";
            // Do not show the exception stacktrace for such common errors.
            e = null;
        } else {
            extraDescriptions = new HashMap(2);
            extraDescriptions.put(Notifying.EXTRA_REQUESTURI, req.getRequestURI());
            if (uri != null) {
                extraDescriptions.put("Request URI", uri);
            }

            // Do not show exception stack trace when log level is WARN or above. Show only message.
            if (verbose) {
                Throwable t = DefaultNotifyingBuilder.getRootCause(e);
                if (t != null) {
                    extraDescriptions.put(Notifying.EXTRA_CAUSE, t.getMessage());
                }

                e = null;
            }
        }

        Notifying n = new DefaultNotifyingBuilder().build(sender, e, type, title, "Cocoon Servlet", message,
                description, extraDescriptions);

        res.setContentType("text/html");
        res.setStatus(errorStatus);
        Notifier.notify(n, res.getOutputStream(), "text/html");
    } else {
        res.sendError(errorStatus, title);
        res.flushBuffer();
    }
}

From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // figure out the real path
    String pathInfo = StringUtils.trimToEmpty(req.getPathInfo());

    while (pathInfo.endsWith("/")) {
        pathInfo = StringUtils.removeEnd(pathInfo, "/");
    }//  w  w  w . j  ava  2s .  co m

    while (pathInfo.startsWith("/")) {
        pathInfo = StringUtils.removeStart(pathInfo, "/");
    }

    if (StringUtils.isBlank(pathInfo)) {
        resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE);
    } else {
        // get the resource
        AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader
                .getResource(SWAGGER_DIRECTORY + "/" + pathInfo);

        // send it to the response
        if (resource.exists()) {
            StreamUtils.copy(resource.getInputStream(), resp.getOutputStream());
            resp.setStatus(HttpServletResponse.SC_OK);
            resp.flushBuffer();
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}