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:cs425.yogastudio.controller.CustomerController.java

@RequestMapping(value = "/customerpic/{id}", method = RequestMethod.GET)
public void getUserImage(Model model, @PathVariable int id, HttpServletResponse response) {
    try {//from  w w  w . j a v  a2  s  . c  o m
        Customer c = customerService.get(id);
        if (c != null) {
            OutputStream out = response.getOutputStream();
            out.write(c.getProductImage());
            response.flushBuffer();
        }
    } catch (IOException ex) {
        //Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.nuxeo.ecm.platform.rendition.url.AbstractRenditionRestHelper.java

@Begin(id = "#{conversationIdGenerator.nextMainConversationId}", join = true)
public void render(DocumentView docView) throws Exception {

    DocumentLocation docLoc = docView.getDocumentLocation();
    if (documentManager == null) {
        RepositoryLocation loc = new RepositoryLocation(docLoc.getServerName());
        navigationContext.setCurrentServerLocation(loc);
        documentManager = navigationContext.getOrCreateDocumentManager();
    }/*from  ww w.  jav  a2s  . c  om*/
    DocumentModel doc = documentManager.getDocument(docLoc.getDocRef());
    if (doc != null) {
        String renditionName = docView.getParameter(RenditionBasedCodec.RENDITION_PARAM_NAME);
        FacesContext context = FacesContext.getCurrentInstance();
        Blob rendered = null;
        try {
            rendered = renderAsBlob(doc, renditionName);
        } catch (NuxeoException e) {
            log.error("Unable to generate rendition " + renditionName, e);
            facesMessages.add(StatusMessage.Severity.WARN, messages.get("rendition.not.available"),
                    renditionName);
            // now we need to redirect
            // otherwise the page will be rendered via Seam PDF
            HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
            String url = DocumentModelFunctions.documentUrl(doc, req);

            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
            try {
                response.sendRedirect(url);
                // be sure we block the codec chain
                response.flushBuffer();
                FacesContext.getCurrentInstance().responseComplete();
            } catch (IOException ioe) {
                log.error("Error while redirecting to standard view", ioe);
            }
            return;
        }
        if (rendered != null) {
            if (rendered.getMimeType() != null && rendered.getMimeType().startsWith("text/")) {
                HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
                // add inline download flag
                request.setAttribute("inline", "true");
            }
            ComponentUtils.download(doc, null, rendered, rendered.getFilename(), "rendition",
                    Collections.singletonMap("rendition", renditionName));
        } else {
            HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
            response.sendError(404, "Unable to find rendition " + renditionName);
        }
    }
}

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

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override/*from   ww w.  jav  a 2s  .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("text/xml");
            response.setContentLength(1000);
            response.getOutputStream().close();
            response.flushBuffer();
            baseRequest.setHandled(true);
        }
    };
}

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

private void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException {
    LOG.info("doGet called");
    final String downloadKey = request.getParameter(ServerConstants.KEY_PARAMETER_NAME);
    LOG.info("Key is " + downloadKey);
    try {//ww w .j  av a  2 s  .c o  m
        response.setStatus(HttpServletResponse.SC_OK);
        response.flushBuffer();
        fileKeyResolver.handleDownload(downloadKey, response.getOutputStream());
    } catch (final Exception e) {
        LOG.info("handleDownload threw exception", e);
        throw new ServletException(e);
    }
}

From source file:com.mnt.base.web.DigestAuthenticator.java

/**
 * WWW-Authenticate: Digest realm="testrealm@host.com",
  *                   qop="auth,auth-int",
  *                   nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",
  *                   opaque="5ccc069c403ebaf9f0171e9517f40e41"
 * @param req //from w ww.  java2  s. c om
 *
 * @param resp
 * @param authInfoMap
 */
private static void postAuthRequired(HttpServletRequest req, HttpServletResponse resp,
        Map<String, Object> authInfoMap) {

    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

    StringBuilder sb = new StringBuilder();
    String siteHost;
    siteHost = req.getHeader("Host");
    if (siteHost == null) {
        siteHost = "www.mntplay.com";
    }

    sb.append("Digest realm=\"" + siteHost + "\",algorithm=\"md5\",");
    sb.append("qop=\"auth,auth-int\",");

    String nonce = (String) authInfoMap.get("nonce");

    if (nonce == null) {
        nonce = UUID.randomUUID().toString();
    }

    String opaque = UUID.randomUUID().toString();

    sb.append("nonce=\"" + nonce + "\",");
    sb.append("opaque=\"" + opaque + "\"");

    authInfoMap.put("nonce", nonce);
    resp.setHeader("WWW-Authenticate", sb.toString());

    try {
        resp.flushBuffer();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.codice.ddf.security.handler.basic.BasicAuthenticationHandler.java

/**
 * Return a 401 response back to the web browser to prompt for basic auth.
 *
 * @param response//  w w w. j av a 2 s.  c  om
 */
private void doAuthPrompt(HttpServletResponse response) {
    try {
        response.setHeader(HttpHeaders.WWW_AUTHENTICATE, AUTHENTICATION_SCHEME_BASIC);
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setContentLength(0);
        response.flushBuffer();
    } catch (IOException ioe) {
        LOGGER.debug("Failed to send auth response: {}", ioe);
    }
}

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

/**
 * Image display// w  ww  . jav a 2  s.com
 */
@RequestMapping(value = "/productImage/{id}", method = RequestMethod.GET)
public void getProductImage(Model model, @PathVariable int id, HttpServletResponse response) {
    try {
        Product p = productService.getProduct(id);
        if (p != null) {
            OutputStream out = response.getOutputStream();
            out.write(p.getImage());
            response.flushBuffer();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:eu.freme.common.exception.ExceptionHandlerService.java

public void writeExceptionToResponse(HttpServletRequest request, HttpServletResponse response,
        Throwable exception) throws IOException {
    ResponseEntity<String> responseEntity = handleError(request, exception);
    response.setStatus(responseEntity.getStatusCode().value());
    response.getWriter().write(responseEntity.getBody());
    response.flushBuffer();
}

From source file:org.apache.unomi.web.EventsCollectorServlet.java

@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //        logger.debug(HttpUtils.dumpRequestInfo(request));
    HttpUtils.setupCORSHeaders(request, response);
    response.flushBuffer();
}

From source file:com.ewcms.publication.filter.render.TemplateSourceRender.java

/**
 * ?//ww w  .  ja  va 2 s  . com
 * 
 * @param response
 * @param uri   ?
 * @return
 * @throws IOException
 */
protected boolean output(HttpServletResponse response, Long siteId, String uri) throws IOException {
    TemplateSource source = templateSourcePublishDao.findByUri(siteId, uri);
    if (source == null) {
        logger.debug("TemplateSource is not exist,uri is {}", uri);
        return false;
    }
    IOUtils.write(source.getContent(), response.getOutputStream());
    response.flushBuffer();
    return true;
}