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.mule.transport.servlet.AbstractReceiverServlet.java

protected void writeResponse(HttpServletResponse servletResponse, MuleMessage message) throws Exception {
    if (message == null) {
        writeEmptyResponse(servletResponse);
    } else {/* ww w.j a  v a2  s. c  om*/
        writeResponseFromMessage(servletResponse, message);
    }
    servletResponse.flushBuffer();
}

From source file:org.ejbca.ui.web.RequestHelper.java

/**
 * Sends back certificate as binary file (application/octet-stream)
 *
 * @param b64cert base64 encoded certificate to be returned
 * @param out output stream to send to// w  w w  .j a v a  2 s.c  o m
 * @param filename filename sent as 'Content-disposition' header 
 * @param beginKey String containing key information, i.e. BEGIN_CERTIFICATE_WITH_NL or BEGIN_PKCS7_WITH_NL
 * @param endKey String containing key information, i.e. END_CERTIFICATE_WITH_NL or END_PKCS7_WITH_NL
 * @throws IOException 
 * @throws Exception on error
 */
public static void sendNewB64File(byte[] b64cert, HttpServletResponse out, String filename, String beginKey,
        String endKey) throws IOException {
    if (b64cert.length == 0) {
        log.error("0 length certificate can not be sent to client!");
        return;
    }

    // We must remove cache headers for IE
    ServletUtils.removeCacheHeaders(out);

    // Set content-type to general file
    out.setContentType("application/octet-stream");
    out.setHeader("Content-disposition", "filename=\"" + StringTools.stripFilename(filename) + "\"");

    out.setContentLength(b64cert.length + beginKey.length() + endKey.length());

    // Write the certificate
    ServletOutputStream os = out.getOutputStream();
    os.write(beginKey.getBytes());
    os.write(b64cert);
    os.write(endKey.getBytes());
    out.flushBuffer();
    if (log.isDebugEnabled()) {
        log.debug("Sent reply to client");
        log.debug(new String(b64cert));
    }
}

From source file:cs544.wamp_blog_engine.controller.UserController.java

@RequestMapping(value = "/image/{id}", method = RequestMethod.GET)
public void getUserImage(Model model, @PathVariable int id, HttpServletResponse response) {
    try {/*w  w  w  .j a  va2s .com*/
        User u = userService.getUser(id);
        if (u != null) {
            OutputStream out = response.getOutputStream();
            out.write(u.getProfilepic());
            response.flushBuffer();
        }
    } catch (IOException ex) {
        Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.druid.server.AsyncManagementForwardingServlet.java

private void handleBadRequest(HttpServletResponse response, String errorMessage) throws IOException {
    if (!response.isCommitted()) {
        response.resetBuffer();/*from   ww w  .jav a2  s. c  o  m*/
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        jsonMapper.writeValue(response.getOutputStream(), ImmutableMap.of("error", errorMessage));
    }
    response.flushBuffer();
}

From source file:org.cloudfoundry.practical.demo.web.controller.TimeoutController.java

@RequestMapping("/timeout/ajaxdrip")
public void ajax(HttpServletResponse response) throws IOException {
    ServletOutputStream outputStream = response.getOutputStream();
    this.logger.info("Long running task...");
    try {//from w  w  w.  j  a v  a2s  .  c o m
        for (int i = 1; i <= TOTAL_SECONDS_DELAY; i++) {
            Thread.sleep(ONE_SECOND);
            this.logger.info(" Thinking..." + i);
            outputStream.write('.');
            response.flushBuffer();
        }
    } catch (InterruptedException e) {
    }
    outputStream.write("Hello from the server".getBytes());
}

From source file:org.mule.transport.servlet.ServletResponseWriter.java

/**
 * Writes a servlet response with an error code without html code wrapping the error message.
 *
 * @param servletResponse response object
 * @param errorCode http error code to be sent back to the client
 * @param errorMessage http error message
 * @param httpHeaders headers to be set in the response object. Can be null.
 * @throws Exception//from   w w  w.  j a va  2  s.  c  o  m
 */
public void writeNonHtmlErrorResponse(HttpServletResponse servletResponse, int errorCode, String errorMessage,
        Map<String, String> httpHeaders) throws Exception {
    addHeaders(servletResponse, httpHeaders);
    servletResponse.setStatus(errorCode);
    servletResponse.getOutputStream().write(errorMessage.getBytes());
    servletResponse.flushBuffer();
}

From source file:com.goodhuddle.huddle.web.api.ExportApiController.java

@RequestMapping(value = "/{fileName:.+}", method = RequestMethod.GET)
public void downloadExport(@PathVariable String fileName, HttpServletResponse response) throws IOException {
    log.debug("Downloading export file: {}", fileName);
    response.setContentType("text/csv");
    response.setHeader("Content-Disposition", "attachment; filename=\"members.csv\"");
    File exportFile = exportService.getExportFile(fileName);
    try (FileInputStream in = new FileInputStream(exportFile)) {
        IOUtils.copy(in, response.getOutputStream());
        response.flushBuffer();
    }// w w  w . j  ava  2s .c o m
}

From source file:org.dataone.proto.trove.mn.rest.v1.CoreController.java

/**
 * return the object requested//  w w  w  .j  a  va 2s . c  o  m
 *
 * @param request
 * @param response
 * @param pid
 * @throws InvalidToken
 * @throws ServiceFailure
 * @throws IOException
 * @throws NotAuthorized
 * @throws NotFound
 * @throws NotImplemented
 */
@RequestMapping(value = "/v1/monitor/ping", method = RequestMethod.GET)
public void ping(HttpServletRequest request, HttpServletResponse response) throws InvalidToken, ServiceFailure,
        IOException, NotAuthorized, NotFound, NotImplemented, InvalidRequest, InsufficientResources {

    debugRequest(request);

    mnCore.ping();
    response.setStatus(200);
    OutputStream out = response.getOutputStream();
    response.flushBuffer();
    out.close();

}

From source file:nl.strohalm.cyclos.controls.customization.documents.AbstractViewDocumentAction.java

@Override
protected ActionForward executeAction(final ActionContext context) throws Exception {
    final PreviewDocumentForm form = context.getForm();
    final long documentId = form.getDocumentId();
    if (documentId < 1) {
        throw new ValidationException();
    }/*from  ww  w  .  j  a v a2 s. c o m*/
    final StaticDocument document = (StaticDocument) documentService.load(documentId,
            StaticDocument.Relationships.BINARY_FILE);
    final BinaryFile binaryFile = document.getBinaryFile();
    final HttpServletResponse response = context.getResponse();
    ResponseHelper.setDownload(response, binaryFile.getName());
    response.setContentType(binaryFile.getContentType());
    response.setContentLength(binaryFile.getSize());
    response.setDateHeader("Last-Modified", binaryFile.getLastModified().getTimeInMillis());
    IOUtils.copy(binaryFile.getContents().getBinaryStream(), response.getOutputStream());
    response.flushBuffer();
    return null;
}

From source file:org.deegree.services.authentication.HttpBasicAuthentication.java

/**
 * Handles the authentication./*from  w ww . j a va 2s . co m*/
 * 
 * @param response
 * @param e
 * @throws IOException
 */
private void doAuthenticationException(HttpServletResponse response, SecurityException e) throws IOException {

    LOG.debug("SecurityException: ");
    response.reset();
    response.resetBuffer();
    response.setHeader("WWW-Authenticate", "Basic realm=\" Backroom ");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.flushBuffer();

}