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:net.yacy.grid.http.AbstractAPIHandler.java

private void setCORS(HttpServletResponse response) {
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST");
    response.setHeader("Access-Control-Allow-Headers", "accept, content-type");
}

From source file:com.boxedfolder.carrot.config.general.filter.CORSFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET,  DELETE, PUT");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers",
            "Accept, Content-Type, Origin, Authorization, x-auth-token");
    response.addHeader("Access-Control-Expose-Headers", "x-auth-token");

    if (request.getMethod().equals("OPTIONS")) {
        try {/*from   w w  w. jav  a 2  s  .c  o m*/
            response.getWriter().print("OK");
            response.getWriter().flush();
        } catch (IOException e) {
            Logger log = LoggerFactory.getLogger(getClass());
            log.error("Exception thrown: " + e.getMessage());
        }
    } else {
        chain.doFilter(request, response);
    }
}

From source file:com.fanya.p2p.front.user.jcaptcha.JCaptchaFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    response.setDateHeader("Expires", 0L);
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    response.setContentType("image/jpeg");

    String id = request.getRequestedSessionId();
    BufferedImage bi = JCaptcha.captchaService.getImageChallengeForID(id);

    ServletOutputStream out = response.getOutputStream();

    ImageIO.write(bi, "jpg", out);
    try {/* w w w.  j av  a 2  s.  c  o  m*/
        out.flush();
    } finally {
        out.close();
    }
}

From source file:com.ace.erp.filter.jcaptcha.JCaptchaFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    response.setDateHeader("Expires", 0L);
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    response.setContentType("image/jpeg");

    ServletOutputStream out = response.getOutputStream();

    try {//from  ww  w.java2 s.  c  om
        String id = request.getSession(true).getId();
        //String id = request.getRequestedSessionId();
        BufferedImage bi = JCaptcha.captchaService.getImageChallengeForID(id);

        ImageIO.write(bi, "jpg", out);
        out.flush();
    } finally {
        out.close();
    }
}

From source file:com.thoughtworks.go.server.web.FileView.java

private void setHeaders(HttpServletResponse response, String filename) {
    if (filename.equals("console.log")) {
        response.setHeader("Content-Disposition", "Inline; filename=fname.ext");
    }//ww  w  .j a v a 2 s. c o m
}

From source file:controllers.ColorController.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=Color.xls");
    colorService.getXls().write(response.getOutputStream());
}

From source file:eu.europa.ejusticeportal.dss.controller.action.DownloadSealedPdf.java

/**
 * Send the PDF to the http response/*  w  ww . ja v  a 2  s  .  c o m*/
 * @param is the stream containing the PDF
 * @param pdfName the name of the PDF
 * @param response the HttpServletResponse to which the PDF will be written
 * @throws IOException
 */
private void sendPdf(InputStream is, String pdfName, HttpServletResponse response) throws IOException {
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + pdfName + "\"");

    ServletOutputStream outs = null;
    try {
        outs = response.getOutputStream();
        int r = 0;
        byte[] chunk = new byte[8192];
        while ((r = is.read(chunk)) != -1) {
            outs.write(chunk, 0, r);
        }
        outs.flush();
    } finally {
        IOUtils.closeQuietly(outs);
    }

}

From source file:com.dangdang.ddframe.job.security.WwwAuthFilter.java

private void authenticateSuccess(final HttpServletResponse response, final boolean isGuest) {
    response.setStatus(200);/*from   www  . ja v  a2  s.  com*/
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("identify", isGuest ? GUEST_IDENTIFY : ROOT_IDENTIFY);
}

From source file:com.WeatherProxy.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("application/json; charset=utf-8");
    resp.setHeader("Access-Control-Allow-Origin", "*");
    PrintWriter out = resp.getWriter();
    String wenhamLat = "42.589611";
    String wenhamLng = "-70.819806";
    // Retrieve lat and lng form url
    String lat = req.getParameter("lat");
    String lng = req.getParameter("lng");

    // Get weather data
    this.getWeather(lat, lng);

    out.println(weatherNow);// w ww . ja  v  a2s  . c  om
}

From source file:com.androgogic.AikauPageView.java

@Override
protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache");
}