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:costumetrade.common.verify.CapchaController.java

@EscapeLogin
@RequestMapping("/capcha/get")
public void get(String businessKey, HttpServletResponse response) throws IOException {

    if (StringUtils.isBlank(businessKey)) {
        throw new IllegalArgumentException("key?");
    }//from  w  w w . j a  va2  s  .  co  m

    response.setContentType("image/png");
    response.setDateHeader("exprise", -1);
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    Pair<String, BufferedImage> codeImage = ImageVerification.create();
    captchaService.save(businessKey, codeImage.first());
    OutputStream outputStream = response.getOutputStream();
    ImageIO.write(codeImage.second(), "png", outputStream);
    outputStream.flush();
}

From source file:com.ewcms.component.checkcode.web.ImageCaptchaServlet.java

private void initResponseHeader(final HttpServletResponse response) {
    response.setHeader("Content-Language", "zh-CN");
    response.setHeader("Cache-Control", "no-store");
    //set on cache
    ///Http 1.0 header
    response.setDateHeader("Expires", 0);
    response.addHeader("Pragma", "no-cache");
    //Http 1.1 header
    response.setHeader("Cache-Control", "no-cache");
    response.setContentType(IMG_JPEG_TYPE);
}

From source file:com.salesmanager.core.security.JAASCustomerSecurityFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.setHeader("Cache-Control", "no-cache");
    resp.setHeader("Pragma", "no-cache");
    resp.setDateHeader("Expires", 0);
    String url = req.getRequestURI();
    if (isEscapeUrlFromFilter(url) || url.endsWith(".css") || url.endsWith(".js")) {
        chain.doFilter(request, response);
        return;/*from   w  w w.j  ava 2s  . c o m*/
    }

    String authToken = request.getParameter(CUSTOMER_AUTH_TOKEN);
    if (StringUtils.isBlank(authToken)) {

        HttpSession session = req.getSession();
        if (session == null) {
            resp.sendRedirect(getLogonPage(req));
        } else {
            if (session.getAttribute(SecurityConstants.SM_CUSTOMER_USER) != null) {
                chain.doFilter(request, response);
            } else {
                resp.sendRedirect(getLogonPage(req));
            }
        }
    } else {
        if (logonModule.isValidAuthToken(authToken)) {
            chain.doFilter(request, response);
        } else {
            ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }
    }

}

From source file:org.hyperic.hq.ui.util.RequestUtils.java

/**
 * When you really really want to defeat a browser's cache, expire the content and set the
 * no-cache header//from   w  w w  . j av a2  s.  com
 * @param expire set <i>true</i> to have the content expire immediately
 */
public static void bustaCache(ServletRequest request, ServletResponse response, boolean expire) {
    if (!(response instanceof HttpServletResponse))
        return;
    HttpServletResponse res = (HttpServletResponse) response;
    if (request.getProtocol().equalsIgnoreCase("HTTP/1.0")) {
        res.setHeader("Pragma", "no-cache");
    } else if (request.getProtocol().equalsIgnoreCase("HTTP/1.1")) {
        res.setHeader("Cache-Control", "no-cache");
    }
    if (expire) {
        Date now = new Date();
        res.setDateHeader("Date", now.getTime());
        res.setDateHeader("Expires", now.getTime() + 1000);
    }
}

From source file:org.jtalks.jcommune.web.controller.ImageUploadController.java

/**
 * Sets up avatar cache related headers.
 *
 * @param response                   - HTTP response object where set headers
 * @param avatarLastModificationTime - last modification time of avatar
 *///ww w  .j  a  v a 2  s  .  c om
protected void setupAvatarHeaders(HttpServletResponse response, Date avatarLastModificationTime) {
    response.setHeader("Pragma", "public");
    response.setDateHeader("Expires", System.currentTimeMillis() + AVATAR_CACHE_AGE_SEC * 1000);
    response.setHeader("Cache-Control", "public");
    response.addHeader("Cache-Control", "max-age=" + AVATAR_CACHE_AGE_SEC);

    String formattedDateLastModified = DateFormatUtils.format(avatarLastModificationTime,
            HTTP_HEADER_DATETIME_PATTERN, Locale.US);
    response.setHeader("Last-Modified", formattedDateLastModified);
}

From source file:com.mejmo.appletraus.server.controller.JnlpController.java

@RequestMapping(value = "/Applet.jnlp")
public String downloadJNLPFile(@RequestParam(value = "cookie", required = true) String cookie,
        @RequestParam(value = "sessionId", required = true) String sessionId, HttpServletResponse response,
        Model model) {/*  ww w . j a  v a 2  s .co m*/
    response.setHeader("Content-Type", "application/x-java-jnlp-file");
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    model.addAttribute("cookie", cookie);
    model.addAttribute("sessionId", sessionId);
    return "jnlp";
}

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:org.shredzone.commons.captcha.CaptchaServlet.java

@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (!request.getMethod().equals("GET")) {
        response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, request.getMethod() + " is not accepted");
    }//from w  ww .  j ava  2  s  .  c o m

    // Prepare header
    response.setDateHeader("Date", System.currentTimeMillis());
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/png");

    // Write captcha image
    CaptchaService cs = getWebApplicationContext().getBean("captchaService", CaptchaService.class);
    BufferedImage challenge = cs.createCaptcha(request.getSession());
    ImageIO.write(challenge, "png", response.getOutputStream());
}

From source file:org.apache.solr.servlet.cache.HttpCacheHeaderUtil.java

/**
* Checks if the downstream request handler wants to avoid HTTP caching of
* the response.//from ww  w. jav  a2 s .c o m
* 
* @param solrRsp The Solr response object
* @param resp The HTTP servlet response object
* @param reqMethod The HTTP request type
*/
public static void checkHttpCachingVeto(final SolrQueryResponse solrRsp, HttpServletResponse resp,
        final Method reqMethod) {
    // For POST we do nothing. They never get cached
    if (Method.POST == reqMethod || Method.OTHER == reqMethod) {
        return;
    }
    // If the request handler has not vetoed and there is no
    // exception silently return
    if (solrRsp.isHttpCaching() && solrRsp.getException() == null) {
        return;
    }

    // Otherwise we tell the caches that we don't want to cache the response
    resp.setHeader("Cache-Control", "no-cache, no-store");

    // For HTTP/1.0 proxy caches
    resp.setHeader("Pragma", "no-cache");

    // This sets the expiry date to a date in the past
    // As long as no time machines get invented this is safe
    resp.setHeader("Expires", "Sat, 01 Jan 2000 01:00:00 GMT");

    // We signal "just modified" just in case some broken
    // proxy cache does not follow the above headers
    resp.setDateHeader("Last-Modified", System.currentTimeMillis());

    // We override the ETag with something different
    resp.setHeader("ETag", '"' + Long.toHexString(System.currentTimeMillis()) + '"');
}

From source file:nl.strohalm.cyclos.controls.customization.documents.AbstractViewDocumentAction.java

@Override
protected ActionForward executeAction(final ActionContext context) throws Exception {
    final PreviewDocumentForm form = context.getForm();
    final long documentId = form.getDocumentId();
    if (documentId < 1) {
        throw new ValidationException();
    }/*w  w  w .ja v  a  2  s.c om*/
    final StaticDocument document = (StaticDocument) documentService.load(documentId,
            StaticDocument.Relationships.BINARY_FILE);
    final BinaryFile binaryFile = document.getBinaryFile();
    final HttpServletResponse response = context.getResponse();
    ResponseHelper.setDownload(response, binaryFile.getName());
    response.setContentType(binaryFile.getContentType());
    response.setContentLength(binaryFile.getSize());
    response.setDateHeader("Last-Modified", binaryFile.getLastModified().getTimeInMillis());
    IOUtils.copy(binaryFile.getContents().getBinaryStream(), response.getOutputStream());
    response.flushBuffer();
    return null;
}