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:irille.pub.verify.RandomImageServlet.java

/**
 * ????HTTP?/*from  w ww  .  j  a v a  2 s . c  om*/
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    boolean gif_enabled = support(req, "image/gif") || !support(req, "image/png");
    HttpSession ssn = req.getSession(true);
    String randomString = random();
    ssn.setAttribute(RANDOM_LOGIN_KEY, randomString);
    res.setContentType(gif_enabled ? "image/gif" : "image/png");
    res.setHeader("Pragma", "No-cache");
    res.setHeader("Cache-Control", "no-cache");
    res.setDateHeader("Expires", 0);
    render(randomString, gif_enabled, res.getOutputStream());
}

From source file:com.netflix.spinnaker.gate.ratelimit.RateLimitingInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    // Hystrix et-al can return 429's, which we'll want to intercept to provide a reset header
    if (response.getStatus() == 429 && !response.getHeaderNames().contains(Rate.RESET_HEADER)) {
        response.setIntHeader(Rate.CAPACITY_HEADER, -1);
        response.setIntHeader(Rate.REMAINING_HEADER, 0);
        response.setDateHeader(Rate.RESET_HEADER, ZonedDateTime.now().plusSeconds(5).toEpochSecond());
        response.setHeader(Rate.LEARNING_HEADER, "false");
    }//from  w w w . j  av  a2s.  c  om
}

From source file:org.apache.qpid.server.management.plugin.servlet.rest.SaslServlet.java

protected void doGetWithSubjectAndActor(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json");
    response.setStatus(HttpServletResponse.SC_OK);

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);

    HttpSession session = request.getSession();
    getRandom(session);/*from  www .  jav  a  2s .c  o m*/

    SubjectCreator subjectCreator = getSubjectCreator(request);
    String[] mechanisms = subjectCreator.getMechanisms().split(" ");
    Map<String, Object> outputObject = new LinkedHashMap<String, Object>();

    final Subject subject = getAuthorisedSubjectFromSession(session);
    if (subject != null) {
        Principal principal = AuthenticatedPrincipal.getAuthenticatedPrincipalFromSubject(subject);
        outputObject.put("user", principal.getName());
    } else if (request.getRemoteUser() != null) {
        outputObject.put("user", request.getRemoteUser());
    }

    outputObject.put("mechanisms", (Object) mechanisms);

    final PrintWriter writer = response.getWriter();

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
    mapper.writeValue(writer, outputObject);

}

From source file:org.openiot.gsn.http.ContainerInfoHandler.java

public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    String reqName = request.getParameter("name");

    //Added by Behnaz
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");

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

    response.getWriter().write(buildOutput(reqName, user));
}

From source file:org.extremecomponents.table.filter.AbstractExportFilter.java

protected void setResponseHeaders(HttpServletResponse response, String exportFileName) {
    String mimeType = MimeUtils.getFileMimeType(exportFileName);
    if (StringUtils.isNotBlank(mimeType)) {
        response.setContentType(mimeType);
    }/*w  w  w.  j  a  va 2s .c  o m*/

    response.setHeader("Content-Disposition", "attachment;filename=\"" + exportFileName + "\"");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    response.setDateHeader("Expires", (System.currentTimeMillis() + 1000));
}

From source file:com.data2semantics.yasgui.server.servlets.AppCacheServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String strongName = getPermutationFromCookies(request.getCookies());

    if (strongName != null && strongName.length() > 0) {
        boolean getCount = request.getParameterMap().keySet().contains("count");

        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", new Date().getTime());

        String moduleDir = getServletContext().getRealPath("/Yasgui/");
        String appcacheFile = moduleDir + "/" + strongName;
        if (fetchManifestForDev(request)) {
            appcacheFile += ".dev";
        }//from w  w w  .jav  a2  s  . com
        appcacheFile += ".appcache";
        String manifestString = IOUtils.toString(new FileReader(appcacheFile));

        PrintWriter out = response.getWriter();
        if (getCount) {
            out.println(Integer.toString(getCacheCount(manifestString)));
        } else {
            response.setContentType("text/cache-manifest");
            out.println(manifestString);

        }
        out.close();
    }

}

From source file:com.liusoft.dlog4j.servlet.DLOG_RandomImageServlet.java

/**
 * ????HTTP?/*from   ww w . ja  v  a2 s . c  om*/
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    boolean gif_enabled = RequestUtils.support(req, "image/gif") || !RequestUtils.support(req, "image/png");
    HttpSession ssn = req.getSession(true);
    String randomString = random();
    ssn.setAttribute(Globals.RANDOM_LOGIN_KEY, randomString);
    res.setContentType(gif_enabled ? "image/gif" : "image/png");
    res.setHeader("Pragma", "No-cache");
    res.setHeader("Cache-Control", "no-cache");
    res.setDateHeader("Expires", 0);
    render(randomString, gif_enabled, res.getOutputStream());
}

From source file:com.manydesigns.portofino.pageactions.chart.ChartAction.java

public Resolution chart() throws FileNotFoundException {
    final File file = RandomUtil.getTempCodeFile(CHART_FILENAME_FORMAT, chartId);
    if (!file.exists()) {
        return new ErrorResolution(404);
    }//ww  w  .j a v  a 2 s.  co  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:be.fedict.eid.dss.webapp.DocumentViewerServlet.java

private void setResponseHeaders(HttpServletRequest request, HttpServletResponse response) {

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http
    // 1.1/*  w  w w  .  ja v  a  2 s.  c o m*/
    if (!request.getScheme().equals("https")) {
        // else the download fails in IE
        response.setHeader("Pragma", "no-cache"); // http 1.0
    } else {
        response.setHeader("Pragma", "public");
    }
    response.setDateHeader("Expires", -1);

}

From source file:de.itsvs.cwtrpc.controller.CacheControlFilter.java

protected void addHeaders(HttpServletResponse response, PreparedCacheControlUriConfig uriConfig) {
    final Long expiresValue;

    expiresValue = getExpiresValue(uriConfig.getExpires());

    if (uriConfig.getCacheControl() != null) {
        response.setHeader("Cache-Control", uriConfig.getCacheControl());
    }//  w  w  w  .  j a v a 2s . c  o  m
    if (expiresValue != null) {
        response.setDateHeader("Expires", expiresValue);
    }
    if (uriConfig.isPragmaNoCache()) {
        response.setHeader("Pragma", "no-cache");
    }
}