List of usage examples for javax.servlet.http HttpServletResponse setDateHeader
public void setDateHeader(String name, long date);
From source file:org.xwiki.webjars.internal.WebJarsResourceReferenceHandler.java
/** * Sets the response headers needed to cache the resource permanently, if the resource is static. * /*www . j a v a 2s .c o m*/ * @param response the response * @param resourceReference the resource that is being served */ private void setResponseHeaders(Response response, WebJarsResourceReference resourceReference) { // If the resource contains Velocity code then this code must be evaluated on each request and so the resource // must not be cached. Otherwise, if the resource is static we can cache it permanently because the resource // version is included in the URL. if (response instanceof ServletResponse && !shouldEvaluateResource(resourceReference)) { HttpServletResponse httpResponse = ((ServletResponse) response).getHttpServletResponse(); httpResponse.setHeader(HttpHeaders.CACHE_CONTROL, "public"); httpResponse.setDateHeader(HttpHeaders.EXPIRES, new Date().getTime() + CACHE_DURATION); // Even if the resource is cached permanently, most browsers are still sending a request if the user reloads // the page using F5. We send back the "Last-Modified" header in the response so that the browser will send // us an "If-Modified-Since" request for any subsequent call for this static resource. When this happens we // return a 304 to tell the browser to use its cached version. httpResponse.setDateHeader(HttpHeaders.LAST_MODIFIED, new Date().getTime()); } }
From source file:ee.pri.rl.blog.web.servlet.FileDownloadServlet.java
private void sendFile(String path, String calculatedTag, File directory, HttpServletResponse resp) { File file = new File(directory, path); String mimeType = getServletContext().getMimeType(path); if (mimeType == null) { mimeType = "application/octet-stream"; }//from w w w.ja v a2s.co m resp.setHeader("ETag", calculatedTag); resp.setDateHeader("Date", System.currentTimeMillis()); resp.setContentType(mimeType); resp.setContentLength((int) file.length()); long liveTime = 3600 * 24 * 30; resp.setDateHeader("Expires", System.currentTimeMillis() + liveTime * 1000); resp.setHeader("Cache-Control", "public, max-age=" + liveTime); try { DataInputStream input = new DataInputStream(new FileInputStream(file)); try { IOUtils.copy(input, resp.getOutputStream()); resp.getOutputStream().flush(); resp.getOutputStream().close(); } catch (IOException e) { log.warn("Sending " + file + " failed", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } if (input != null) { input.close(); } } catch (IOException e) { log.warn("Sending " + file + " failed", e); try { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (IOException e1) { log.warn("Sending response for " + file + " failed"); } } }
From source file:org.sakaiproject.nakamura.files.pool.StreamHelper.java
/** * @param resource/* w w w.j av a2 s . com*/ * @param request * @param response * @param servletContext * @throws RepositoryException */ private void setHeaders(Map<String, Object> properties, Resource resource, HttpServletResponse response, String alternativeStream, ServletContext servletContext) { long modifTime = StorageClientUtils.toLong( properties.get(StorageClientUtils.getAltField(Content.LASTMODIFIED_FIELD, alternativeStream))); if (modifTime > 0) { response.setDateHeader(HEADER_LAST_MODIFIED, modifTime); } String contentType = (String) properties .get(StorageClientUtils.getAltField(Content.MIMETYPE_FIELD, alternativeStream)); if (contentType == null && servletContext != null) { final String ct = servletContext.getMimeType(resource.getPath()); if (ct != null) { contentType = ct; } } if (contentType != null) { response.setContentType(contentType); } String encoding = (String) properties .get(StorageClientUtils.getAltField(Content.ENCODING_FIELD, alternativeStream)); if (encoding != null) { response.setCharacterEncoding(encoding); } }
From source file:com.impala.paga.all.QueryBalance.java
/** * /* w w w .jav a 2s . com*/ * @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(QueryBalance.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(QueryBalance.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }
From source file:net.unicon.academus.apps.sso.SsoCallbackServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) { try {/*from ww w. j av a 2 s . c o m*/ res.setHeader("pragma", "no-cache"); res.setHeader("Cache-Control", "no-store, no-cache, max-age=0, must-revalidate, post-check=0, pre-check=0"); res.setDateHeader("Expires", 0); Map cache = TimedCache.getCache("ssoAuthentication"); if (log.isDebugEnabled()) { log.debug("SsoCallbackServlet uri: " + req.getRequestURI() + "?" + req.getQueryString()); } HttpSession session = req.getSession(false); if (session == null) { returnErrorResponse(res, buildRedirectAttribute(req)); return; } IUserInstance userInstance = UserInstanceManager.getUserInstance(req); String gatewayUserContextKey = req.getParameter("gatewayUserContextKey"); if (gatewayUserContextKey == null) { returnErrorResponse(res); return; } String[] split = gatewayUserContextKey.split("/"); String username = split[0]; String sessionUsername = (String) userInstance.getPerson().getAttribute(IPerson.USERNAME); if (!username.equals(sessionUsername)) { log.warn("SsoCallbackServlet user not authoriated: " + sessionUsername + ", " + username); returnErrorResponse(res); return; } if (log.isDebugEnabled()) { log.debug("SsoCallbackServlet lookup name: " + gatewayUserContextKey); } SsoEvaluator evaluator = (SsoEvaluator) session.getAttribute(gatewayUserContextKey); if (evaluator == null) { evaluator = (SsoEvaluator) cache.get(gatewayUserContextKey); if (evaluator != null) { session.setAttribute(gatewayUserContextKey, evaluator); cache.remove(gatewayUserContextKey); } } if (evaluator == null) { returnErrorResponse(res); return; } String entries = evaluator.evaluateAllEntries(true); if (log.isDebugEnabled()) { log.debug("SsoCallbackServlet retrieving id/userContext: " + gatewayUserContextKey + "/" + entries); } if (entries == null) { returnErrorResponse(res); return; } res.getWriter().print(entries); } catch (Exception e) { log.error("Exception producing callback response.", e); try { returnErrorResponse(res); } catch (IOException ioe) { log.error("Exception returning error response.", e); } } }
From source file:com.impala.paga.all.BankRouteRemit1.java
/** * /* w w w . j av a 2 s . c om*/ * @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(BankRouteRemit1.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(BankRouteRemit1.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }
From source file:de.betterform.agent.web.resources.ResourceServlet.java
/** * set the caching headers for the resource response. Caching can be disabled by adding and init-param * of 'caching' with value 'false' to web.xml * * @param request the http servlet request * @param response the http servlet response *//* w w w. j a v a2 s . c o m*/ protected void setCaching(HttpServletRequest request, HttpServletResponse response) { long now = System.currentTimeMillis(); if (caching) { response.setHeader("Cache-Control", "max-age=3600, public"); response.setDateHeader("Date", now); response.setDateHeader("Expires", now + this.oneYear); response.setDateHeader("Last-Modified", this.getLastModifiedValue()); } else { // Set to expire far in the past. response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT"); // Set standard HTTP/1.1 no-cache headers. response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // Set IE extended HTTP/1.1 no-cache headers (use addHeader). response.addHeader("Cache-Control", "post-check=0, pre-check=0"); // Set standard HTTP/1.0 no-cache header. response.setHeader("Pragma", "no-cache"); } }
From source file:org.apache.struts2.rest.RestActionInvocation.java
private void disableCatching(HttpServletResponse response) { // No cache/*from ww w . ja va 2 s. co m*/ response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Last-Modified", 0); response.setHeader("ETag", "-1"); }
From source file:io.lightlink.servlet.JsMethodsDefinitionServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/javascript"); resp.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); resp.setHeader("Pragma", "no-cache"); resp.setDateHeader("Expires", 0); Cookie[] cookies = req.getCookies(); String debugMethods = ""; for (int i = 0; cookies != null && i < cookies.length; i++) { Cookie cookie = cookies[i];//from w ww . ja v a2s . c o m if ("lightlink.debug".equalsIgnoreCase(cookie.getName())) debugMethods = cookie.getValue(); } PrintWriter writer = resp.getWriter(); writer.print(getDeclarationScript(debugMethods, req)); if (StringUtils.isNotEmpty(debugMethods) && ConfigManager.isInDebugMode()) { writer.print("\n// DEBUG PART \n"); writer.print("\n\n /***** io/lightlink/core/sqlFunctions.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/sqlFunctions.js")); writer.print("\n\n /***** io/lightlink/core/debugProxy.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/debugProxy.js")); writer.print("\n\n /***** io/lightlink/core/LightLinkDebugSession.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/LightLinkDebugSession.js")); } if (ConfigManager.isInDebugMode()) { writer.print("\n\n /***** io/lightlink/core/IDDQD.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/IDDQD.js")); } writer.print("\n" + "LL.JsApi.CSRF_Token = '" + CSRFTokensContainer.getInstance(req.getSession()).createNewToken() + "'\n"); writer.close(); resp.flushBuffer(); }
From source file:com.impala.paga.all.RouteRemit1.java
/** * // w ww .j a v a 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 try { // that the // message was // sent out.write(moneytransfer(request).getBytes()); } catch (JSONException ex) { Logger.getLogger(RouteRemit1.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(RouteRemit1.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }