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.maritimecloud.endorsement.config.SimpleCorsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    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, PUT");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers",
            "Content-Type, Accept, X-Requested-With, remember-me, authorization");
    chain.doFilter(req, res);/*  w  w  w.  j  a va2s. c  om*/
}

From source file:de.itsvs.cwtrpc.security.AbstractRpcSuccessHandler.java

protected void addNoCacheResponseHeaders(HttpServletRequest request, HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache, no-store");
    response.setDateHeader("Expires", -1L);
    response.setHeader("Pragma", "no-cache");
}

From source file:com.javiermoreno.springboot.mvc.users.SimpleCORSFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
    response.setHeader("Access-Control-Allow-Credentials", "true");
    response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
    if (request.getMethod().equals("OPTIONS")) {
        try {//from  w  ww . j  a  va 2s. com
            response.getWriter().print("OK");
            response.getWriter().flush();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }
    } else {
        chain.doFilter(request, response);
    }
}

From source file:de.codecentric.boot.admin.web.SimpleCORSFilter.java

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *      javax.servlet.FilterChain)//from ww  w.j a  va2 s .c  om
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse res = (HttpServletResponse) response;
    res.setHeader("Access-Control-Allow-Origin", origin);
    chain.doFilter(request, res);
}

From source file:springfox.test.contract.swagger.CrossOriginFilter.java

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

    log.info("Applying CORS filter");
    HttpServletResponse response = (HttpServletResponse) resp;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "0");
    chain.doFilter(req, resp);/*from   w  ww.ja va2 s .c o  m*/
}

From source file:school.controller.Controller.java

public void setHeaders(HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
    response.setHeader("Expires", "0");
    response.setHeader("Pragma", "no-cache");
}

From source file:io.sevenluck.chat.config.SimpleCorsFilter.java

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

    logger.info("SimpleCorsFilter -> Request.");
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Credentials", "true");
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, PATCH, OPTIONS, DELETE");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers",
            "Accept, Accept-CH, Accept-Charset, Accept-Datetime, Accept-Encoding, Accept-Ext, Accept-Features, Accept-Language, Accept-Params, Accept-Ranges, Access-Control-Allow-Credentials, Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Origin, Access-Control-Expose-Headers, Access-Control-Max-Age, Access-Control-Request-Headers, Access-Control-Request-Method, Age, Allow, Alternates, Authentication-Info, Authorization, C-Ext, C-Man, C-Opt, C-PEP, C-PEP-Info, CONNECT, Cache-Control, Compliance, Connection, Content-Base, Content-Disposition, Content-Encoding, Content-ID, Content-Language, Content-Length, Content-Location, Content-MD5, Content-Range, Content-Script-Type, Content-Security-Policy, Content-Style-Type, Content-Transfer-Encoding, Content-Type, Content-Version, Cookie, Cost, DAV, DELETE, DNT, DPR, Date, Default-Style, Delta-Base, Depth, Derived-From, Destination, Differential-ID, Digest, ETag, Expect, Expires, Ext, From, GET, GetProfile, HEAD, HTTP-date, Host, IM, If, If-Match, If-Modified-Since, If-None-Match, If-Range, If-Unmodified-Since, Keep-Alive, Label, Last-Event-ID, Last-Modified, Link, Location, Lock-Token, MIME-Version, Man, Max-Forwards, Media-Range, Message-ID, Meter, Negotiate, Non-Compliance, OPTION, OPTIONS, OWS, Opt, Optional, Ordering-Type, Origin, Overwrite, P3P, PEP, PICS-Label, POST, PUT, Pep-Info, Permanent, Position, Pragma, ProfileObject, Protocol, Protocol-Query, Protocol-Request, Proxy-Authenticate, Proxy-Authentication-Info, Proxy-Authorization, Proxy-Features, Proxy-Instruction, Public, RWS, Range, Referer, Refresh, Resolution-Hint, Resolver-Location, Retry-After, Safe, Sec-Websocket-Extensions, Sec-Websocket-Key, Sec-Websocket-Origin, Sec-Websocket-Protocol, Sec-Websocket-Version, Security-Scheme, Server, Set-Cookie, Set-Cookie2, SetProfile, SoapAction, Status, Status-URI, Strict-Transport-Security, SubOK, Subst, Surrogate-Capability, Surrogate-Control, TCN, TE, TRACE, Timeout, Title, Trailer, Transfer-Encoding, UA-Color, UA-Media, UA-Pixels, UA-Resolution, UA-Windowpixels, URI, Upgrade, User-Agent, Variant-Vary, Vary, Version, Via, Viewport-Width, WWW-Authenticate, Want-Digest, Warning, Width, X-Content-Duration, X-Content-Security-Policy, X-Content-Type-Options, X-CustomHeader, X-DNSPrefetch-Control, X-Forwarded-For, X-Forwarded-Port, X-Forwarded-Proto, X-Frame-Options, X-Modified, X-OTHER, X-PING, X-PINGOTHER, X-Powered-By, X-Requested-With");

    chain.doFilter(req, res);// w w w  . ja  v a2  s.  c om
}

From source file:com.timesheet.export.ExcelExportView.java

@Override
protected void buildExcelDocument(Map<String, Object> map, HSSFWorkbook hssfw, HttpServletRequest hsr,
        HttpServletResponse hsr1) throws Exception {
    hsr1.setHeader("Pragma", "public");
    hsr1.setHeader("Expires", "0");
    hsr1.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    hsr1.setHeader("Content-type", "application-download");
    hsr1.setHeader("Content-Disposition", "attachment; filename=bookings.xls");
    hsr1.setHeader("Content-Transfer-Encoding", "binary");

    HSSFSheet excelSheet = hssfw.createSheet("Time sheet report");

    HSSFRow excelHeader = excelSheet.createRow(0);
    excelHeader.createCell(0).setCellValue("Project");
    excelHeader.createCell(1).setCellValue("Option");
    excelHeader.createCell(2).setCellValue("Date");
    excelHeader.createCell(3).setCellValue("Duration");
    excelHeader.createCell(4).setCellValue("Description");

    List<Booking> bookings = (List<Booking>) map.get("bookings");
    int record = 1;

    for (Booking booking : bookings) {
        HSSFRow excelRow = excelSheet.createRow(record++);
        excelRow.createCell(0)/*from   w ww . j a va 2s  .c om*/
                .setCellValue(booking.getProject().getProjectId() + "-" + booking.getProject().getName());
        excelRow.createCell(1).setCellValue(booking.getBookingOption().getOptionLabel());
        excelRow.createCell(2).setCellValue(booking.getBookingDate().toString());
        excelRow.createCell(3).setCellValue(booking.getDuration().toString());
        excelRow.createCell(4).setCellValue(booking.getDescription());
    }

}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java

/**
 * Method to download a PDF file generated by directory record
 * @param request request/* w  w  w. j a  v a2 s  . c o m*/
 * @param response response
 * @param plugin plugin
 * @param configProducer configuration
 * @param listIdEntryConfig list of config id entry
 * @param locale locale
 * @param nIdRecord the id record
 */
public static void doDownloadPDF(HttpServletRequest request, HttpServletResponse response, Plugin plugin,
        IConfigProducer configProducer, List<Integer> listIdEntryConfig, Locale locale, int nIdRecord) {
    Record record = RecordHome.findByPrimaryKey(nIdRecord, plugin);
    Directory directory = DirectoryHome.findByPrimaryKey(record.getDirectory().getIdDirectory(), plugin);

    String strName = getFileNameFromConfig(directory, configProducer, nIdRecord, locale);
    String strFileName = doPurgeNameFile(strName) + ".pdf";

    response.setHeader("Content-Disposition", "attachment ;filename=\"" + strFileName + "\"");
    response.setHeader("Pragma", "public");
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate,post-check=0,pre-check=0");

    response.setContentType("application/pdf");

    OutputStream os = null;

    try {
        os = response.getOutputStream();

        if (listIdEntryConfig != null) {
            PDFUtils.doCreateDocumentPDF(request, strName, os, nIdRecord, listIdEntryConfig,
                    configProducer.getExtractNotFilled());
        } else {
            PDFUtils.doCreateDocumentPDF(request, strName, os, nIdRecord, configProducer.getExtractNotFilled());
        }
    } catch (IOException e) {
        AppLogService.error(e);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.log4ic.compressor.cache.filter.BrowserCacheFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    response.setHeader("Cache-Control", "max-age=" + this.cacheTime);
    filterChain.doFilter(servletRequest, response);
}