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:com.cognifide.aet.rest.LockServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("POST: " + req.toString());
    }//w ww.  jav a  2s . c  o m
    resp.setContentType(APPLICATION_JSON_CONTENT_TYPE);
    String value = req.getParameter(VALUE_PARAM);
    String key = getKey(req);
    if (StringUtils.isBlank(key) || StringUtils.isBlank(value)) {
        resp.setStatus(404);
    } else if (lockService.trySetLock(key, value)) {
        resp.setStatus(200);
    } else {
        resp.setStatus(409);
    }
    resp.flushBuffer();
}

From source file:server.UpgradeController.java

@RequestMapping("/getupgradefile")
public String getUpgradeFile(@RequestParam(value = "licensekey") String licensekey,
        @RequestParam(value = "url") String url, @RequestParam(value = "version") String version,
        HttpServletResponse response) {
    try {/*from  w w w  .ja va2  s .  c  o  m*/

        License license = new License(counter.incrementAndGet(), licensekey, url, version,
                new java.sql.Date(Calendar.getInstance().getTime().getTime()));

        if (license.isCurrent() && license.isValid()) {
            // get your file as InputStream
            InputStream is = new FileInputStream(new File("upgrades/latest.zip"));

            response.addHeader("Content-disposition", "attachment;filename=latest.zip");
            response.setContentType("txt/plain");

            IOUtils.copy(is, response.getOutputStream());

            response.flushBuffer();

            return "License successfully validated.";

        } else {
            return "License validation unsuccessful. Unable to download upgrade files";
        }

    } catch (Exception e) {
        System.out.println(e);
        return "License validation unsuccessful. Unable to download upgrade files";
    }
}

From source file:waffle.spring.NegotiateSecurityFilter.java

/**
 * Send a 401 Unauthorized along with protocol authentication headers.
 * /*from   ww  w.ja va  2  s .c  o  m*/
 * @param response
 *            HTTP Response
 * @param close
 *            Close connection.
 */
protected void sendUnauthorized(final HttpServletResponse response, final boolean close) {
    try {
        this.provider.sendUnauthorized(response);
        if (close) {
            response.setHeader("Connection", "close");
        } else {
            response.setHeader("Connection", "keep-alive");
        }
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        response.flushBuffer();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.milton.servlet.SpringMiltonFilter.java

private void doMiltonProcessing(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    try {/*from  w  ww .j a  va 2s.c om*/
        MiltonServlet.setThreadlocals(req, resp);
        Request request = new io.milton.servlet.ServletRequest(req, servletContext);
        Response response = new io.milton.servlet.ServletResponse(resp);
        httpManager.process(request, response);
    } finally {
        MiltonServlet.clearThreadlocals();
        //resp.getOutputStream().flush();
        resp.flushBuffer();
    }
}

From source file:org.openmrs.contrib.metadatarepository.webapp.controller.PackageFormController.java

@RequestMapping(value = "/packagedownload")
public void downloadPackage(@RequestParam(required = false) final Long id, HttpServletResponse response)
        throws IOException {
    MetadataPackage p = packageManager.loadPackage(id);

    response.setContentType("application/x-zip-compressed");
    response.setHeader("Content-disposition", "attatchment;filename=\"" + id + ".zip");
    IOUtils.copy(new ByteArrayInputStream(p.getFile()), response.getOutputStream());
    Long i = p.getDownloadCount();
    log.debug("download count:" + i);
    i = i + 1;/*  w  ww  .j  av a2  s  .  c  om*/
    p.setDownloadCount(i);
    log.debug("download count:" + p.getDownloadCount());
    packageManager.save(p);
    response.flushBuffer();

}

From source file:com.indoqa.httpproxy.HttpClientProxy.java

@SuppressWarnings("resource")
private void writeProxyResponse(HttpServletResponse response, HttpResponse proxyResponse) throws IOException {
    this.writeResponseStatus(response, proxyResponse);
    this.writeResponseHeaders(response, proxyResponse);

    HttpEntity entity = proxyResponse.getEntity();

    if (entity == null) {
        return;/*from  w w w.j  a  va2  s. c  o  m*/
    }

    InputStream responseBody = entity.getContent();
    ServletOutputStream outputStream = response.getOutputStream();

    this.writeResponseBody(responseBody, outputStream);

    response.flushBuffer();
}

From source file:org.eclipse.orion.server.authentication.form.servlets.LoginServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    if (req.getParameter("login") == null && FormAuthHelper.getAuthenticatedUser(req) != null) {
        FormAuthHelper.writeLoginResponse(FormAuthHelper.getAuthenticatedUser(req), resp);
        return;//from www  . j  ava 2  s.c  o  m
    }

    try {
        if (FormAuthHelper.performAuthentication(req, resp)) {
            if (req.getParameter("redirect") != null && !req.getParameter("redirect").equals("")) { //$NON-NLS-1$
                resp.sendRedirect(req.getParameter("redirect"));
            } else {
                resp.flushBuffer();
            }
        } else {
            // redirection from
            // FormAuthenticationService.setNotAuthenticated
            String versionString = req.getHeader("Orion-Version"); //$NON-NLS-1$
            Version version = versionString == null ? null : new Version(versionString);

            // TODO: This is a workaround for calls
            // that does not include the WebEclipse version header
            String xRequestedWith = req.getHeader("X-Requested-With"); //$NON-NLS-1$

            String invalidLoginError = "Invalid user or password";

            if (version == null && !"XMLHttpRequest".equals(xRequestedWith)) { //$NON-NLS-1$
                RequestDispatcher rd = req.getRequestDispatcher(
                        "/loginform?error=" + new String(Base64.encode(invalidLoginError.getBytes()))); //$NON-NLS-1$
                rd.include(req, resp);
            } else {
                PrintWriter writer = resp.getWriter();
                JSONObject jsonError = new JSONObject();
                try {
                    jsonError.put("error", invalidLoginError); //$NON-NLS-1$
                    writer.print(jsonError);
                    resp.setContentType("application/json"); //$NON-NLS-1$
                } catch (JSONException e) {/* ignore */
                }
                resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            }
            resp.flushBuffer();
        }
    } catch (UnsupportedUserStoreException e) {
        LogHelper.log(e);
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    }

}

From source file:org.josso.gateway.protocol.handler.NtlmProtocolHandler.java

private void startsNegotiation(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setHeader("WWW-Authenticate", "NTLM");
    if (this.isOfferBasic(request))
        response.addHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.setContentLength(0);/*  ww w .j  av a  2s .co  m*/
    response.flushBuffer();
}

From source file:org.apache.jetspeed.modules.actions.NTLMSessionValidator.java

/**
 * Extracts user name from http headers// w ww .  j  a  v a  2 s.c o m
 * 
 * @param data
 * @return
 * @exception Exception
 */
private String getRemoteUser(RunData data) throws Exception {
    HttpServletRequest request = data.getRequest();
    HttpServletResponse response = data.getResponse();

    if (data.getUser().hasLoggedIn() && request.getMethod().equalsIgnoreCase("get")) {
        return data.getUser().getUserName();
    }

    String auth = request.getHeader("Authorization");
    if (auth == null) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setHeader("WWW-Authenticate", "NTLM");
        response.flushBuffer();

        return null;
    }
    if (auth.startsWith("NTLM ")) {

        byte[] msg = Base64.decodeBase64(auth.substring(5).getBytes());
        int off = 0, length, offset;

        if (msg[8] == 1) {
            response.setHeader("WWW-Authenticate", encodedMsg1);
            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

            return null;
        } else if (msg[8] == 3) {
            if (data.getUser().hasLoggedIn()) {
                return data.getUser().getUserName();
            }

            off = 30;

            // length = msg[off + 17] * 256 + msg[off + 16];
            // offset = msg[off + 19] * 256 + msg[off + 18];
            // String remoteHost = new String(msg, offset, length);

            // length = msg[off + 1] * 256 + msg[off];
            // offset = msg[off + 3] * 256 + msg[off + 2];
            // String domain = new String(msg, offset, length);

            length = msg[off + 9] * 256 + msg[off + 8];
            offset = msg[off + 11] * 256 + msg[off + 10];
            String username = new String(msg, offset, length);

            return username;
        }

    }

    return null;
}

From source file:com.unidev.polycms.hateoas.controller.StorageIndexController.java

@GetMapping(value = "/storage/{storage}/raw", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void raw(@PathVariable("storage") String storage, HttpServletResponse response) {
    if (!polyCore.existTenant(storage)) {
        LOG.warn("Not found storage {}", storage);
        throw new StorageNotFoundException("Storage " + storage + " not found");
    }// w  w  w.  ja  va  2s.  c  o m
    FlatFileStorage flatFileStorage = polyCore.fetchFlatFileStorage(storage);
    if ("true".equals(flatFileStorage.metadata().fetch(ALLOW_STORAGE_TRANSFER_KEY, ""))) { //  storageTransferAllowed=true
        File sqliteFile = polyCore.fetchSqliteFile(storage);
        try {
            FileUtils.copyFile(sqliteFile, response.getOutputStream());
            response.flushBuffer();
        } catch (IOException e) {
            LOG.error("Failed to send raw storage", e);
            throw new StorageTransferException("Failed to transfer storage " + storage);
        }
    } else {
    }
}