Example usage for javax.servlet.http HttpServletResponse setDateHeader

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

Introduction

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

Prototype

public void setDateHeader(String name, long date);

Source Link

Document

Sets a response header with the given name and date-value.

Usage

From source file:net.ymate.platform.webmvc.view.AbstractView.java

public IView addDateHeader(String name, long date) {
    HttpServletResponse _response = WebContext.getResponse();
    if (_response.containsHeader(name)) {
        _response.addDateHeader(name, date);
    } else {//from  w w  w.  jav  a2 s .  com
        _response.setDateHeader(name, date);
    }
    return this;
}

From source file:com.image32.demo.simpleapi.ContentHandler.java

private void httpHeaderNoCache(HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
}

From source file:org.shredzone.cilla.view.AbstractView.java

/**
 * If the page is restricted and unlocked, send headers so public caches won't cache
 * the page, but private caches (user-agent) do.
 *
 * @param page//  www.j  ava 2s. c  o  m
 *            {@link Page} to check
 * @param req
 *            {@link HttpServletRequest} request to be checked
 * @param resp
 *            {@link HttpServletResponse} response to add headers to
 */
protected void addHeadersIfRestricted(Page page, HttpServletRequest req, HttpServletResponse resp) {
    if (page.isRestricted() && unlockService.isUnlocked(req.getSession(), page)) {
        // Page is restricted and unlocked
        resp.setDateHeader("Expires", 0L);
        resp.setHeader("Cache-Control", "s-max-age=0, private");
    }
}

From source file:no.kantega.publishing.admin.content.spellcheck.SpellcheckAction.java

private void setResponseValues(HttpServletResponse response) {
    response.setContentType("text/plain; charset=utf-8");
    response.setHeader("Cache-Control", "no-store, no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", System.currentTimeMillis());
}

From source file:org.codehaus.httpcache4j.VaryResourceServlet.java

protected void commonWrites(HttpServletResponse response, String output) throws IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=30000");
    Date date = new Date();
    response.setHeader(HttpHeaders.VARY, HttpHeaders.ACCEPT);
    response.setDateHeader(HttpHeaders.DATE, date.getTime());
    response.getWriter().write(output);//from  w  ww.jav  a 2 s  .  co m
    response.getWriter().close();
}

From source file:net.webpasswordsafe.server.report.JasperReportServlet.java

private void setNoCache(HttpServletResponse res) {
    res.setHeader("Pragma", "no-cache");
    res.setHeader("Cache-Control", "no-cache,no-store");
    res.setDateHeader("Expires", 0);
}

From source file:com.mirantis.cachemod.filter.CacheFilter.java

public void writeCacheToResponse(CacheEntry cacheEntry, ServletResponse response, boolean fragment)
        throws IOException {

    if (cacheEntry.getContentType() != null) {
        response.setContentType(cacheEntry.getContentType());
    }/*from  www . j ava2  s.c om*/

    if (!fragment) {

        if (response instanceof HttpServletResponse) {
            HttpServletResponse httpResponse = (HttpServletResponse) response;

            if (cacheEntry.getLastModified() != -1) {
                httpResponse.setDateHeader("Last-Modified", cacheEntry.getLastModified());
            }

            if (cacheEntry.getExpires() != Long.MAX_VALUE) {
                httpResponse.setDateHeader("Expires", cacheEntry.getExpires());
            }

            if (cacheEntry.getMaxAge() != -1) {
                if (cacheEntry.getMaxAge() < 0) { // set max-age based on life time
                    long currentMaxAge = -cacheEntry.getMaxAge() / 1000 - System.currentTimeMillis() / 1000;
                    if (currentMaxAge < 0) {
                        currentMaxAge = 0;
                    }
                    httpResponse.addHeader("Cache-Control", "max-age=" + currentMaxAge);
                } else {
                    httpResponse.addHeader("Cache-Control", "max-age=" + cacheEntry.getMaxAge());
                }
            }

        }
    }

    if (cacheEntry.getLocale() != null) {
        response.setLocale(cacheEntry.getLocale());
    }

    OutputStream out = new BufferedOutputStream(response.getOutputStream());
    response.setContentLength(cacheEntry.getContent().length);
    out.write(cacheEntry.getContent());
    out.flush();
}

From source file:org.eclipse.skalli.view.internal.filter.CacheFilter.java

@SuppressWarnings("nls")
@Override/*ww w .j  ava  2  s. co m*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String requestURI = httpRequest.getRequestURI();
    String extension = FilenameUtils.getExtension(requestURI);
    if (cachedResources.contains(extension)) {
        if (maxAge != -1L) {
            httpResponse.setDateHeader("Expires", System.currentTimeMillis() + maxAge * 1000);
        }
        httpResponse.setHeader("Cache-Control",
                "public" + (maxAge != -1 ? ", maxAge=" + Long.toString(maxAge) : "") + ", must-revalidate");
    }
    chain.doFilter(request, response);
}

From source file:org.olat.core.gui.media.ServletUtil.java

/**
 * @param httpReq//from  w  ww  .j  a  va  2s .  c  om
 * @param httpResp
 * @param mr
 */
public static void serveResource(HttpServletRequest httpReq, HttpServletResponse httpResp, MediaResource mr) {
    boolean debug = log.isDebug();

    try {
        Long lastModified = mr.getLastModified();
        if (lastModified != null) {
            // give browser a chance to cache images
            long ifModifiedSince = httpReq.getDateHeader("If-Modified-Since");
            // TODO: if no such header, what is the return value
            long lastMod = lastModified.longValue();
            if (ifModifiedSince >= (lastMod / 1000L) * 1000L) {
                httpResp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
            httpResp.setDateHeader("Last-Modified", lastModified.longValue());
        }

        if (isFlashPseudoStreaming(httpReq, mr)) {
            httpResp.setContentType("video/x-flv");
            pseudoStreamFlashResource(httpReq, httpResp, mr);
        } else {
            String mime = mr.getContentType();
            if (mime != null) {
                httpResp.setContentType(mime);
            }
            serveFullResource(httpReq, httpResp, mr);
        }

        // else there is no stream, but probably just headers
        // like e.g. in case of a 302 http-redirect
    } catch (Exception e) {
        if (debug) {
            log.warn("client browser abort when serving media resource", e);
        }
    } finally {
        try {
            mr.release();
        } catch (Exception e) {
            //we did our best here to clean up
        }
    }
}

From source file:elw.miniweb.ViewJackson.java

public void render(Map model, HttpServletRequest request, HttpServletResponse resp) throws Exception {
    resp.setContentType(getContentType() + "; charset=UTF-8");
    resp.setCharacterEncoding("UTF-8");

    resp.setHeader("Pragma", "no-cache");
    resp.setHeader("Cache-Control", "no-cache");
    resp.setDateHeader("Expires", System.currentTimeMillis());

    MAPPER.writeValue(resp.getWriter(), stateOrData);
}