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:com.sammyun.controller.shop.RegisterController.java

/**
 * E-mail?//from www .  j  a  va2 s .  com
 */
@RequestMapping(value = "/check_email", method = RequestMethod.GET)
public @ResponseBody boolean checkEmail(String email, HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    if (StringUtils.isEmpty(email)) {
        return false;
    }
    if (memberService.emailExists(email)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.sammyun.controller.shop.RegisterController.java

/**
 * E-mail?/*w ww.  j  ava 2  s .  c o  m*/
 */
@RequestMapping(value = "/mobileUnique", method = RequestMethod.GET)
public @ResponseBody boolean mobileUnique(String mobile, HttpServletResponse response) {
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    if (StringUtils.isEmpty(mobile)) {
        return false;
    }
    if (memberService.mobileUnique(mobile)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.impala.paga.all.BankRouteRemit.java

/**
 * /*  w  w w.  ja va  2  s  .  c  o  m*/
 * @param request
 * @param response
 * @throws ServletException
 *             , IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    OutputStream out = response.getOutputStream();

    response.setContentType("text/plain;charset=UTF-8");
    response.setDateHeader("Expires", new Date().getTime()); // Expiration
    // date
    response.setDateHeader("Date", new Date().getTime()); // Date and time
    // that the
    // message was
    // sent
    out.write(SendRequest(request).getBytes());
    out.flush();
    out.close();
}

From source file:com.manydesigns.portofino.pageactions.chart.jfreechart.JFreeChartAction.java

public Resolution chart() throws FileNotFoundException {
    final File file = RandomUtil.getTempCodeFile(CHART_FILENAME_FORMAT, chartId);
    if (!file.exists()) {
        return new ErrorResolution(404);
    }//w  ww.  j av  a  2  s .  c o  m
    final InputStream inputStream = new FileInputStream(file);

    //Cache the file, expire after 12h
    int expiresAfter = 12 * 60 * 60 * 1000;
    long now = System.currentTimeMillis();
    HttpServletResponse response = context.getResponse();
    response.setHeader("Cache-Control", "max-age=" + expiresAfter);
    response.setDateHeader("Last-Modified", now);
    response.setDateHeader("Expires", now + expiresAfter);
    response.setHeader("Pragma", "");

    return new StreamingResolution("image/png", inputStream) {
        @Override
        protected void stream(HttpServletResponse response) throws Exception {
            super.stream(response);
            if (!file.delete()) {
                logger.warn("Could not delete temporary file for chart: " + file.getAbsolutePath());
            }
        }
    };
}

From source file:com.impala.paga.all.RouteRemit.java

/**
 * /*from   ww  w.  j a va  2 s. co m*/
 * @param request
 * @param response
 * @throws ServletException
 *             , IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    OutputStream out = response.getOutputStream();

    response.setContentType("text/plain;charset=UTF-8");
    response.setDateHeader("Expires", new Date().getTime()); // Expiration
    // date
    response.setDateHeader("Date", new Date().getTime()); // Date and time
    try {
        // that the
        // message was
        // sent
        out.write(moneytransfer(request).getBytes());
    } catch (JSONException ex) {
        Logger.getLogger(RouteRemit.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(RouteRemit.class.getName()).log(Level.SEVERE, null, ex);
    }
    out.flush();
    out.close();
}

From source file:com.huateng.ebank.framework.web.TransFilter.java

private boolean expiredSystem(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    String uriStr = StringUtils.substringAfterLast(req.getServletPath(), "/");
    if (StringUtils.indexOf(loginRef, uriStr) == -1) {
        resp.setHeader("Pragma", "No-cache");
        resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
        resp.setDateHeader("Expires", 1);
        RequestDispatcher rd = (req).getRequestDispatcher(expiredPageName);
        rd.forward(req, resp);/*from   w  w  w  . j  a v  a 2  s .  co  m*/
        return true;
    }
    return false;
}

From source file:net.shopxx.controller.shop.QRCodeController.java

/**
  * ?base64?  ?? base64/*from ww w  .  jav  a  2 s. co m*/
  */
@RequestMapping(value = "/encodeBase64", method = RequestMethod.GET)
public void image(String text, String ico, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    text = new String(new BASE64Decoder().decodeBuffer(text), "utf-8");
    String[] splits = text.split("\\?");

    text = splits[0] + "?parameter=" + Base64.encodeBase64String(splits[1].getBytes());

    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setContentType("image/jpeg");

    ServletOutputStream servletOutputStream = null;
    try {
        servletOutputStream = response.getOutputStream();
        BufferedImage bufferedImage = QRCodeUtil.createImageInUrl(text, ico, true, 0, 0);
        ImageIO.write(bufferedImage, "jpg", servletOutputStream);
        servletOutputStream.flush();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(servletOutputStream);
    }
}

From source file:no.sesat.search.http.servlet.BoomerangServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
        throws ServletException, IOException {

    // clients must not cache these requests
    res.setHeader("Cache-Control", "no-cache, must-revalidate, post-check=0, pre-check=0");
    res.setHeader("Pragma", "no-cache"); // for old browsers
    res.setDateHeader("Expires", 0); // to be double-safe

    // entrails is the map of logging information
    final Map<String, Object> entrails = new HashMap<String, Object>();

    // request attribute to keep
    entrails.put("referer", req.getHeader("Referer"));
    entrails.put("method", req.getMethod());
    entrails.put("ipaddress", req.getRemoteAddr());
    entrails.put("user-agent", req.getHeader("User-Agent"));
    entrails.put("user-id", SearchServlet.getCookieValue(req, "SesamID"));
    entrails.put("user", SearchServlet.getCookieValue(req, "SesamUser"));

    if (req.getRequestURI().startsWith(CEREMONIAL)) {

        // ceremonial boomerang
        final StringBuffer url = req.getRequestURL();
        if (null != req.getQueryString()) {
            url.append('?' + req.getQueryString());
        }//  w w  w  .j a  v a  2s  .co m

        // pick out the entrails
        final int boomerangStart = url.indexOf(CEREMONIAL) + CEREMONIAL.length();

        try {
            final String grub = url.substring(boomerangStart, url.indexOf("/", boomerangStart));
            LOG.debug(grub);

            // the url to return to
            final String destination = url
                    .substring(url.indexOf("/", url.indexOf(CEREMONIAL) + CEREMONIAL.length() + 1) + 1);

            // the grub details to add
            if (0 < grub.length()) {
                final StringTokenizer tokeniser = new StringTokenizer(grub, ";");
                while (tokeniser.hasMoreTokens()) {
                    final String[] entry = tokeniser.nextToken().split("=");
                    entrails.put(entry[0], 1 < entry.length ? entry[1] : entry[0]);
                }
            }
            entrails.put("boomerang", destination);
            kangerooGrub(entrails);

            LOG.debug("Ceremonial boomerang to " + destination.toString());

            if (ROBOTS.matcher(req.getHeader("User-agent")).find()) {
                // robots like permanent redirects. and we're not interested in their clicks so ok to cache.
                res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                res.setHeader("Location", destination.toString());
                res.setHeader("Connection", "close");

            } else {
                // default behaviour for users.
                res.sendRedirect(destination.toString());
            }

        } catch (StringIndexOutOfBoundsException sioobe) {
            // SEARCH-4668
            LOG.error("Boomerang url not to standard --> " + url);
            LOG.debug(sioobe.getMessage(), sioobe);
        }

    } else {

        // hunting boomerang, just grub, and the grub comes as clean parameters.
        final DataModel datamodel = (DataModel) req.getSession().getAttribute(DataModel.KEY);
        entrails.putAll(datamodel.getParameters().getValues());
        kangerooGrub(entrails);

    }

}

From source file:com.ddubyat.develop.jhawtcode.web.InternalResourceController.java

/**
 * Controller method to deliver application CSS
 *
 * @param response The http response object from a spring controller
 * @throws IOException if the css content is inaccessible
 *//*from w  w  w  .  j av a2  s  .  c  om*/
@RequestMapping(value = "/jhawtcode/jhc.css", method = { RequestMethod.GET })
public void requestCSS(HttpServletResponse response) throws IOException {
    log.debug("Creating application CSS");

    response.setHeader("Server", "jhawtconsole");
    response.setContentType("text/css");
    response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", -1);

    if (!propertyUtil.canHawtTheCode()) {
        log.trace("Not delivering CSS, application not enabled");
    }

    String heightOriginal = "height: 200px;";
    String heightOverride = heightOriginal;
    String sysHeightProp = System.getProperty("jhawtcode.console.height");
    if (sysHeightProp != null && StringUtil.isNotEmpty(sysHeightProp) && isNumeric(sysHeightProp)) {
        heightOverride = heightOriginal.replaceAll("200", sysHeightProp);
        log.debug("Overriding console height to {}", heightOverride);
    }

    try {
        log.debug("Attempting to return CSS");
        response.getWriter().write(resourceUtil.readLocalResource("classpath:/css/jhawtcode.css")
                .replaceAll(heightOriginal, heightOverride));
    } catch (IOException ioe) {
        log.debug("Unable to create CSS", ioe);
    }
}

From source file:com.ddubyat.develop.jhawtcode.web.InternalResourceController.java

/**
 * Controller method to deliver application JS
 *
 * @param response The http response object from a spring controller
 * @param request The http request object from a spring controller
 * @throws IOException if the js file was inaccessible
 *//*from  www  . j av  a2  s  .  com*/
@RequestMapping(value = "/jhawtcode/jhc.js", method = { RequestMethod.GET })
public void requestJS(HttpServletRequest request, HttpServletResponse response) throws IOException {
    log.debug("Creating application JS");

    response.setHeader("Server", "jhawtconsole");
    response.setContentType("application/javascript");
    response.setHeader("Cache-Control", "no-cache,no-store,must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", -1);

    if (!propertyUtil.canHawtTheCode()) {
        log.trace("Not delivering CSS, application not enabled");
    }

    setTraceProps(request);

    String javascript = resourceUtil.readLocalResource(new String[] { "classpath:/js/jhawtcode.js" });
    javascript = javascript.replace("|systemUUID|", systemUUID);
    javascript = javascript.replace("|username|", username);
    javascript = javascript.replace("|license|", license);
    javascript = javascript.replace("|lCode|", PropertyUtil.license);
    javascript = javascript.replace("|appname|", appname);

    log.debug("Attempting to return JS");
    response.getWriter().write(javascript);
}