Example usage for javax.servlet.http HttpServletResponse setHeader

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

Introduction

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

Prototype

public void setHeader(String name, String value);

Source Link

Document

Sets a response header with the given name and value.

Usage

From source file:org.wte4j.examples.showcase.server.services.GwtOrderServiceServlet.java

private void sendDocument(File file, HttpServletResponse resp) throws IOException {
    resp.setContentType(DOCUMENT_CONTENT_TYPE);
    resp.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName());
    Files.copy(file, resp.getOutputStream());
}

From source file:org.zalando.stups.stupsback.admin.SimpleCORSFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    //TODO, restrict origin in production
    response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
    response.setHeader("Access-Control-Allow-Credentials", "true");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");

    chain.doFilter(req, res);/*  w  w w .j  a v a2  s .  c  o  m*/
}

From source file:org.craftercms.core.controller.rest.ContentStoreRestController.java

private boolean checkNotModified(long lastModifiedTimestamp, WebRequest request, HttpServletResponse response) {
    response.setHeader(CACHE_CONTROL_HEADER_NAME, MUST_REVALIDATE_HEADER_VALUE);

    return request.checkNotModified(lastModifiedTimestamp);
}

From source file:com.controlj.green.modstat.servlets.ModstatZipServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/zip");
    resp.setHeader("Content-disposition", "attachment;filename=modstat.zip");
    try {/* w ww.  j a  v a  2 s.c om*/
        RunnableProgress work = (RunnableProgress) LongRunning.getWork(req);
        if (work == null || work.isAlive() || work.hasError()) {
            throw new Exception("Modstats not gathered yet");
        }

        InputStream in = work.getCache();
        IOUtils.copy(in, resp.getOutputStream());
        resp.getOutputStream().flush();
    } catch (Exception e) {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        System.err.println("Add-On Error in " + AddOnInfo.getAddOnInfo().getName());
        e.printStackTrace(new PrintWriter(System.err));
    }
}

From source file:com.enonic.cms.core.tools.LivePortalTraceController.java

private void returnJson(String json, HttpServletResponse res) throws Exception {
    res.setHeader("Content-Type", "application/json; charset=UTF-8");
    res.getWriter().println(json);//from w  w  w  . j a v a 2  s .  c  om
}

From source file:org.vbossica.springbox.metrics.MetricsController.java

@RequestMapping(value = "/metrics/metrics", method = RequestMethod.GET)
public void process(
        @RequestParam(value = "pretty", required = false, defaultValue = "true") boolean prettyPrint,
        HttpServletResponse resp) throws IOException {
    resp.setContentType("application/json");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);

    final OutputStream output = resp.getOutputStream();
    try {/* www .  j  a v  a  2  s  .co m*/
        (prettyPrint ? mapper.writerWithDefaultPrettyPrinter() : mapper.writer()).writeValue(output, registry);
    } finally {
        output.close();
    }
}

From source file:controllers.FreeOptionController.java

@RequestMapping("/getXls")
public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception {
    response.setContentType("application/octet-stream");
    response.setHeader("Content-Disposition", "attachment; filename=Options.xls");
    freeOptionService.getXls().write(response.getOutputStream());
}

From source file:nl.dtls.fairdatapoint.api.config.ApplicationFilter.java

@Override
public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) sr1;
    HttpServletRequest request = (HttpServletRequest) sr;
    response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
    response.setHeader(HttpHeaders.ALLOW, (RequestMethod.GET.name()));
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, (HttpHeaders.ACCEPT));
    ThreadContext.put("ipAddress", request.getRemoteAddr());
    ThreadContext.put("responseStatus", String.valueOf(response.getStatus()));
    fc.doFilter(sr, sr1);// w w w  .j  av  a 2 s  .c om
    ThreadContext.clearAll();
}

From source file:org.easyj.rest.view.EasyView.java

protected void responsePreventCache(HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
    response.setHeader("Pragma", "no-cache"); //HTTP 1.0
    response.setDateHeader("Expires", 0); //prevents caching at the proxy server
}

From source file:com.adito.core.MessageResourceLoaderServlet.java

private void sendFile(InputStream in, long length, HttpServletResponse response) throws IOException {
    response.setHeader("Content-Type", "text/plain");
    response.setHeader("Content-Length", String.valueOf(length));
    response.setContentLength((int) length);
    Util.noCache(response);/*from   w  w  w .  j a va  2 s.  co  m*/
    try {
        Util.copy(in, response.getOutputStream());
        response.getOutputStream().flush();
    } catch (IOException ex) {
    } finally {
        Util.closeStream(in);
        Util.closeStream(response.getOutputStream());
    }

}