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:com.thinkberg.webdav.GetHandler.java

void setHeader(HttpServletResponse response, FileContent content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(content.getLastModifiedTime()));
    response.setHeader("Content-Type", content.getContentInfo().getContentType());
    response.setHeader("ETag", Util.getETag(content.getFile()));
}

From source file:cn.vlabs.umt.ui.servlet.LoginServlet.java

private void addCrossDomainHeader(HttpServletResponse response) {
    //?IE//from  w  w  w .  j a v  a2 s  .  c  o  m
    response.setHeader("P3P", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
}

From source file:shiver.me.timbers.spring.security.CookieJwtAuthenticationApplier.java

@Override
public void apply(Authentication authentication, HttpServletResponse response) {
    final String token = tokenParser.create(authentication);
    response.setHeader(tokenName, token);
    response.addCookie(bakery.bake(tokenName, token));
}

From source file:com.acc.storefront.controllers.misc.RobotsController.java

@RequestMapping(value = "/robots.txt", method = RequestMethod.GET)
public String getRobots(final HttpServletResponse response) {
    // Add cache control header to cache response for a day
    response.setHeader("Cache-Control", "public, max-age=" + ONE_DAY);

    return ControllerConstants.Views.Pages.Misc.MiscRobotsPage;
}

From source file:me.doshou.admin.maintain.push.web.controller.PushController.java

/**
 * ?????/*from   w w  w.  j a v a 2s  .co  m*/
 * @return
 */
@RequestMapping(value = "/admin/polling")
@ResponseBody
public Object polling(HttpServletResponse resp, @CurrentUser User user) {
    resp.setHeader("Connection", "Keep-Alive");
    resp.addHeader("Cache-Control", "private");
    resp.addHeader("Pragma", "no-cache");

    Long userId = user.getId();
    if (userId == null) {
        return null;
    }
    //? ?
    if (!pushService.isOnline(userId)) {
        Long unreadMessageCount = messageApi.countUnread(userId);
        List<Map<String, Object>> notifications = notificationApi.topFiveNotification(user.getId());

        Map<String, Object> data = Maps.newHashMap();
        data.put("unreadMessageCount", unreadMessageCount);
        data.put("notifications", notifications);
        pushService.online(userId);
        return data;
    } else {
        //
        return pushService.newDeferredResult(userId);
    }
}

From source file:com.ibm.cf.ManifestController.java

@RequestMapping(value = "/download", method = RequestMethod.POST)
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Manifest manifest = new Manifest(request);
    response.setHeader("Content-Disposition", "attachment; filename=manifest.yml");
    response.setContentType("text/plain");
    response.getWriter().write(manifest.toString());
}

From source file:fi.hsl.parkandride.ApplicationVersionFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    if (StringUtils.hasText(version)) {
        response.setHeader("Liipi-Version", version);
    }/*from ww w  .  ja v a  2  s.  co  m*/
    chain.doFilter(req, res);
}

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

@RequestMapping(value = "/metrics/ping", method = RequestMethod.GET)
public void process(HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);
    if (message != null || message.isEmpty()) {
        PrintWriter writer = resp.getWriter();
        try {/*ww  w . j  ava2 s  . c  om*/
            writer.println(message);
        } finally {
            writer.close();
        }
    }
}

From source file:de.hska.ld.core.config.filter.CrossOriginFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    String url = request.getRequestURL().toString();
    if (!url.contains("push")) {
        String origin = request.getHeader("Origin");
        HttpServletResponse response = (HttpServletResponse) res;
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Origin", origin);
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type, Authorization");
    }//from  ww w.  ja v a  2 s  .c o  m
    try {
        chain.doFilter(req, res);
    } catch (NestedServletException nse) {
        if (!(nse.getCause() instanceof NullPointerException && nse.getCause().getMessage() == null)) {
            if (!(nse.getCause() instanceof IllegalArgumentException)) {
                nse.printStackTrace();
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:io.lavagna.web.api.ExportImportController.java

@RequestMapping(value = "/api/export", method = RequestMethod.POST)
public void export(HttpServletResponse resp) throws IOException {
    resp.setHeader("Content-Disposition", "attachment; filename=\"lavagna-export-"
            + new SimpleDateFormat("YYYY-MM-dd").format(new Date()) + ".zip\"");
    resp.setContentType("application/octet-stream");
    exportImportService.exportData(resp.getOutputStream());
}