Example usage for javax.servlet.http HttpServletResponse reset

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

Introduction

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

Prototype

public void reset();

Source Link

Document

Clears any data that exists in the buffer as well as the status code, headers.

Usage

From source file:de.itsvs.cwtrpc.controller.UnexpectedErrorFilter.java

protected void processUnexpectedFailure(HttpServletRequest request, HttpServletResponse response, Throwable e) {
    log.error("Unexpected error while processing service request", e);

    if (!response.isCommitted()) {
        response.reset();
        /*// ww  w .ja v  a 2s.  c  om
         * Since unexpected failure does a non cachable status code, we do
         * not need to initialize caching.
         */
        RPCServletUtils.writeResponseForUnexpectedFailure(getServletContext(), response, e);
    }
}

From source file:cn.cug.laboratory.web.BaseController.java

/**
 * /*from   w  w w. j  av  a 2  s .  co m*/
 * @param response
 * @param string
 * @return
 */
protected String renderString(HttpServletResponse response, String string, String type) {
    try {
        response.reset();
        response.setContentType(type);
        response.setCharacterEncoding("utf-8");
        response.getWriter().print(string);
        return null;
    } catch (IOException e) {
        return null;
    }
}

From source file:com.yunmel.syncretic.utils.io.IOUtils.java

/**
 * //from   w  ww.  j  a v a2  s  . c o  m
 * 
 * @param filePath 
 * @param fileName ??
 * @param inline ??
 * @throws Exception
 */
public static void downloadFile(HttpServletResponse response, File file, String fileName, boolean inline)
        throws Exception {

    OutputStream outp = null;
    FileInputStream br = null;
    int len = 0;
    try {
        br = new FileInputStream(file);
        response.reset();
        outp = response.getOutputStream();
        outp.flush();
        response.setContentType("application/octet-stream");
        response.setContentLength((int) file.length());
        String header = (inline ? "inline" : "attachment") + ";filename="
                + new String(fileName.getBytes(), "ISO8859-1");
        response.addHeader("Content-Disposition", header);
        byte[] buf = new byte[1024];
        while ((len = br.read(buf)) != -1) {
            outp.write(buf, 0, len);
        }
        outp.flush();
        outp.close();
    } finally {
        if (br != null) {
            if (0 == br.available()) {
                br.close();
            }
        }
    }

}

From source file:com.zte.gu.webtools.web.download.DownloadController.java

@RequestMapping(method = RequestMethod.GET)
public void download(HttpSession session, HttpServletResponse response) {
    String filePath = (String) session.getAttribute("filePath");
    String fileName = (String) session.getAttribute("fileName");
    if (filePath != null) {
        response.reset();
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        response.setContentType("application/octet-stream; charset=UTF-8");
        InputStream in = null;/* ww w. ja  va  2s.co m*/
        try {
            in = new FileInputStream(filePath);
            IOUtils.copy(in, response.getOutputStream());
        } catch (Exception e) {
            LoggerFactory.getLogger(DownloadController.class).warn("download error,", e);
        } finally {
            IOUtils.closeQuietly(in);
            session.removeAttribute("filePath");
            session.removeAttribute("fileName");
        }
    }
}

From source file:de.betterform.agent.web.servlet.XFormsErrorServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.reset();
    response.resetBuffer();/*from   www .  j  a  v a2 s  .com*/

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.println(getHtmlhead(request.getContextPath()));
    writer.println(getHTML(request));
    writer.println(HTMLFOOT);
    writer.flush();
    response.getOutputStream().close();

}

From source file:com.sun.socialsite.web.filters.CustomizedPageCachingFilter.java

@Override
protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws Exception {
    if (enabled) {
        response.reset();
        //response.setHeader("Cache-Control", "max-age=0, must-revalidate");
        super.doFilter(request, response, chain);
    } else {/*w  w w . java  2 s.c  o  m*/
        chain.doFilter(request, response);
    }
}

From source file:sernet.verinice.web.AttachmentBean.java

public void download() throws CommandException, IOException {
    String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"); //$NON-NLS-1$
    String name = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("name"); //$NON-NLS-1$
    LoadAttachmentFile command = new LoadAttachmentFile(Integer.valueOf(id));
    command = getCommandService().executeCommand(command);
    AttachmentFile attachmentFile = command.getAttachmentFile();

    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
    response.reset(); // Some JSF component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide.
    response.setContentLength(attachmentFile.getFileData().length); // Set it with the file size. This header is optional. It will work if it's omitted, but the download progress will be unknown.
    response.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\""); // The Save As popup magic is done here. You can give it any file name you want, this only won't work in MSIE, it will use current request URL as file name instead. //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    OutputStream output = response.getOutputStream();
    output.write(attachmentFile.getFileData());

    facesContext.responseComplete();//from ww w  .j  a  v a2 s . co m
}

From source file:org.beangle.web.io.DefaultStreamDownloader.java

public void download(HttpServletRequest request, HttpServletResponse response, InputStream inStream,
        String name, String display) {
    String attach_name = getAttachName(name, display);
    try {/*w w w .java 2 s .c  o  m*/
        response.reset();
        addContent(request, response, attach_name);
        IOUtils.copy(inStream, response.getOutputStream());
    } catch (Exception e) {
        logger.warn("download file error " + attach_name, e);
    } finally {
        IOUtils.closeQuietly(inStream);
    }
}

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

/**
 * Handles the authentication./* www  . java  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();

}

From source file:com.cloud.ops.resource.ResourcePackageController.java

@RequestMapping(value = "/{id}/download", method = RequestMethod.GET)
public void download(HttpServletResponse response, @PathVariable("id") String id) {
    ResourcePackage resourcePackage = service.get(id);
    try {// w w  w.  j a  v a 2  s  .c o m
        response.reset();
        response.setContentType("licenseInfo/octet-stream;charset=UTF-8");
        File file = new File(resourcePackage.getWarPath());
        response.setHeader("Content-Disposition",
                "attachment;filename=" + java.net.URLEncoder.encode(file.getName(), "UTF-8"));
        FileUtils.copyFile(file, response.getOutputStream());
    } catch (IOException e) {
        LOGGER.error("file download error: ", e);
    }
}