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.ejbca.ui.web.RequestHelper.java

/**
 * Sends back a number of bytes//from  w  ww.java 2 s  .c  o m
 *
 * @param bytes DER encoded certificate to be returned
 * @param out output stream to send to
 * @param contentType mime type to send back bytes as
 * @param fileName to call the file in a Content-disposition, can be null to leave out this header
 *
 * @throws Exception on error
 */
public static void sendBinaryBytes(final byte[] bytes, final HttpServletResponse out, final String contentType,
        final String filename) throws Exception {
    if ((bytes == null) || (bytes.length == 0)) {
        log.error("0 length can not be sent to client!");
        return;
    }

    if (filename != null) {
        // We must remove cache headers for IE
        ServletUtils.removeCacheHeaders(out);
        out.setHeader("Content-disposition", "filename=\"" + StringTools.stripFilename(filename) + "\"");
    }

    // Set content-type to general file
    out.setContentType(contentType);
    out.setContentLength(bytes.length);

    // Write the certificate
    final ServletOutputStream os = out.getOutputStream();
    os.write(bytes);
    out.flushBuffer();
    if (log.isDebugEnabled()) {
        log.debug("Sent " + bytes.length + " bytes to client");
    }
}

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

/**
 * Writes a servlet response based on a mule message.
 *
 * @param servletResponse response object
 * @param message must be a not null message which content will be sent as response
 * @param httpHeaders headers to be set in the response object. Can be null.
 * @throws Exception/*from  ww  w.j  a v a2 s .  c om*/
 */
public void writeResponse(HttpServletResponse servletResponse, MuleMessage message,
        Map<String, String> httpHeaders) throws Exception {
    addHeaders(servletResponse, httpHeaders);
    writeResponseFromMessage(servletResponse, message);
    servletResponse.flushBuffer();
}

From source file:edu.umn.msi.tropix.transfer.http.server.HttpTransferControllerImpl.java

private void doPost(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException {
    LOG.info("doPost called");
    final String uploadKey = request.getParameter(ServerConstants.KEY_PARAMETER_NAME);
    LOG.info("Key is " + uploadKey);
    try {//from  ww  w  . ja v  a2s.  com
        fileKeyResolver.handleUpload(uploadKey, request.getInputStream());
        response.flushBuffer();
        response.setStatus(HttpServletResponse.SC_OK);
    } catch (final Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.pm.myshop.controller.FilesController.java

@RequestMapping("/pictures/{thumb}/{fileName}")
@ResponseBody/*from   w  ww . j a va 2 s  .  c  om*/
public void viewFiles(@PathVariable("fileName") String fileName, @PathVariable("thumb") String thumb,
        HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {

        String path = request.getRealPath("/");

        response.setContentType("image/jpeg");

        InputStream inputStream = new FileInputStream(path + "../../files/" + thumb + "/" + fileName + ".jpg");
        IOUtils.copy(inputStream, response.getOutputStream());
        response.flushBuffer();

    } catch (IOException ex) {
        System.out.println(ex.getMessage());
        response.getWriter().print("File Not Found");
    }

}

From source file:com.oak_yoga_studio.controller.FacultyController.java

@RequestMapping(value = "/facultyProfileImage/{id}", method = RequestMethod.GET)
public void getProfileImage(Model model, @PathVariable int id, HttpServletResponse response) {
    try {/*  w  ww . ja  v  a  2 s .c  o m*/
        Faculty f = facultyService.getFacultyById(id);
        if (f != null) {
            OutputStream out = response.getOutputStream();
            out.write(f.getProfilePicture());
            response.flushBuffer();
        }
    } catch (IOException ex) {
        // Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.shadows.liquiblq.webapi.controllers.SongsController.java

@RequestMapping(value = "/play/{id}", method = RequestMethod.GET)
public void doPlayById(@PathVariable("id") UUID id, @RequestParam("sessionKey") UUID Session,
        @RequestParam("UserId") Integer UserId, HttpServletResponse response) {
    try {//w  w w.  j  a  va  2  s .  c  o  m
        Validator.ValidateRequest(Session, UserId);
        Song song = Context.getSongsSet().GetById(id);
        InputStream File = SongsController.class.getResourceAsStream("/songs/" + song.Filename);
        IOUtils.copy(File, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception Exp) {
        throw new RuntimeException("IOError writing file to output stream");
    }
}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServerProxyConnectionAborted3.java

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override//from www. j  a v a 2  s  .co  m
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.setContentType("multipart/mixed; boundary=foobar");
            response.setContentLength(1000);
            response.getOutputStream().close();
            response.flushBuffer();
            baseRequest.setHandled(true);
        }
    };
}

From source file:com.sishuok.chapter3.web.controller.StreamingController.java

@RequestMapping("/async3")
public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setHeader("Connection", "Keep-Alive");
    resp.addHeader("Cache-Control", "private");
    resp.addHeader("Pragma", "no-cache");
    resp.setContentType("text/html;charset=utf-8");
    resp.flushBuffer();

    //1??//from w  w  w  .j ava  2s .  c  o  m
    final AsyncContext asyncContext = req.startAsync();

    asyncContext.addListener(new AsyncListener() {
        @Override
        public void onComplete(final AsyncEvent event) throws IOException {
            queue.remove(event.getAsyncContext());
        }

        @Override
        public void onTimeout(final AsyncEvent event) throws IOException {
            event.getAsyncContext().complete();
            queue.remove(event.getAsyncContext());
        }

        @Override
        public void onError(final AsyncEvent event) throws IOException {
            queue.remove(event.getAsyncContext());
        }

        @Override
        public void onStartAsync(final AsyncEvent event) throws IOException {
        }
    });

    //????
    queue.add(asyncContext);

}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsNtlmProcessingFilterEntryPoint.java

/**
 * {@inheritDoc}/*  w w w  .ja  v a 2 s.  c  o  m*/
 * @see org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint#commence(
 *    javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *    org.springframework.security.AuthenticationException)
 */
@Override
public void commence(final ServletRequest req, final ServletResponse res,
        final AuthenticationException authException) throws IOException, ServletException {

    // start authentication, if necessary and forceIdentification in NtlmProcessingFilter is false
    if (!(authException instanceof NtlmBaseException || authException instanceof BadCredentialsException)) {

        HttpServletRequest request = (HttpServletRequest) req;
        request.getSession().setAttribute(STATE_ATTR, BEGIN);

        HttpServletResponse response = (HttpServletResponse) res;

        response.setHeader("WWW-Authenticate", new NtlmBeginHandshakeException().getMessage());
        response.setHeader("Connection", "Keep-Alive");
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setContentLength(0);
        response.flushBuffer();
    } else {
        super.commence(req, res, authException);
    }
}

From source file:com.adobe.acs.commons.mcp.impl.processes.RefreshFolderTumbnails.java

private void rebuildThumbnail(ResourceResolver rr, String folderPath) throws ServletException, IOException {
    HttpServletRequest req = requestFactory.createRequest("GET", folderPath + ".folderthumbnail.jpg",
            THUMBNAIL_PARAMS);//w  w w. ja  v a2  s .  c o m
    try (NullOutputStream out = new NullOutputStream()) {
        HttpServletResponse res = requestFactory.createResponse(out);
        slingProcessor.processRequest(req, res, rr);
        res.flushBuffer();
    }
    record(folderPath, "Rebuild", "Thumbnail was rebuilt");
}