List of usage examples for javax.servlet.http HttpServletResponse addDateHeader
public void addDateHeader(String name, long date);
From source file:org.myjerry.util.ResponseUtil.java
public static final void setNoCache(HttpServletResponse response, boolean isHttp11) { if (isHttp11) { response.setHeader("Cache-Control", "no-cache"); } else {// ww w .j ava2 s . c om response.setHeader("Pragma", "no-cache"); response.addDateHeader("Expires", 0L); response.setHeader("Cache-Control", "no-store"); } }
From source file:org.craftercms.core.util.HttpServletUtils.java
public static void disableCaching(HttpServletResponse response) { response.addHeader(PRAGMA_HEADER_NAME, "no-cache"); response.addHeader(CACHE_CONTROL_HEADER_NAME, "no-cache, no-store, max-age=0"); response.addDateHeader(EXPIRES_HEADER_NAME, 1L); }
From source file:de.yaio.services.plantuml.server.controller.PlantumProvider.java
protected void addHeaderForCache(HttpServletResponse response) { long today = System.currentTimeMillis(); // Add http headers to force the browser to cache the image response.addDateHeader("Expires", today + 31536000000L); // today + 1 year response.addDateHeader("Last-Modified", 1261440000000L); // 2009 dec 22 constant date in the past response.addHeader("Cache-Control", "public"); }
From source file:cz.mzk.editor.server.ScanImgServiceImpl.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.addDateHeader("Last-Modified", new Date().getTime()); resp.addHeader("Cache-Control", "max-age=" + Constants.HTTP_CACHE_SECONDS); resp.addDateHeader("Expires", DateUtils.addMonths(new Date(), 1).getTime()); boolean full = ClientUtils.toBoolean(req.getParameter(Constants.URL_PARAM_FULL)); String topSpace = req.getParameter(Constants.URL_PARAM_TOP_SPACE); String urlHeight = req.getParameter(Constants.URL_PARAM_HEIGHT); String uuid = req.getParameter(Constants.URL_PARAM_UUID); if (uuid == null || "".equals(uuid)) { uuid = req.getRequestURI().substring(req.getRequestURI().indexOf(Constants.SERVLET_SCANS_PREFIX) + Constants.SERVLET_SCANS_PREFIX.length() + 1); }/* www .ja v a 2 s. c o m*/ StringBuffer baseUrl = new StringBuffer(); baseUrl.append("http://"); if (!URLS.LOCALHOST()) { baseUrl.append(req.getServerName()); } else { String hostname = config.getHostname(); if (hostname.contains("://")) { baseUrl.append(hostname.substring(hostname.indexOf("://") + "://".length())); } else { baseUrl.append(hostname); } } StringBuffer sb = new StringBuffer(); if (topSpace != null) { String metadata = IOUtils.toString(new URL(baseUrl + DJATOKA_URL_GET_METADATA + uuid), StandardCharsets.UTF_8); String height = null; height = metadata.substring(metadata.indexOf("ght\": \"") + 7, metadata.indexOf("\",\n\"dw")); String width = metadata.substring(metadata.indexOf("dth\": \"") + 7, metadata.indexOf("\",\n\"he")); int intHeight = Integer.parseInt(height); int intUrlHeight = Integer.parseInt(urlHeight); int intTopSpace = Integer.parseInt(topSpace); boolean isLower = intTopSpace > 0 && ((intHeight - intUrlHeight) < intTopSpace); String region = (isLower ? intHeight - intUrlHeight : (intTopSpace < 0 ? 0 : topSpace)) + ",1," + urlHeight + "," + width; sb.append(baseUrl.toString()).append(DJATOKA_URL_FULL_PAGE_DETAIL).append(uuid) .append(DJATOKA_URL_REGION).append(region); } else { sb.append(baseUrl.toString()) .append(full ? DJATOKA_URL_FULL_IMG : DJATOKA_URL + urlHeight + DJATOKA_URL_SUFFIX) .append(uuid); } resp.setContentType("image/jpeg"); resp.sendRedirect(resp.encodeRedirectURL(sb.toString())); }
From source file:cz.fi.muni.xkremser.editor.server.ScanImgServiceImpl.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.addDateHeader("Last-Modified", new Date().getTime()); resp.addHeader("Cache-Control", "max-age=" + Constants.HTTP_CACHE_SECONDS); resp.addDateHeader("Expires", DateUtils.addMonths(new Date(), 1).getTime()); boolean full = ClientUtils.toBoolean(req.getParameter(Constants.URL_PARAM_FULL)); String topSpace = req.getParameter(Constants.URL_PARAM_TOP_SPACE); String urlHeight = req.getParameter(Constants.URL_PARAM_HEIGHT); String uuid = req.getParameter(Constants.URL_PARAM_UUID); if (uuid == null || "".equals(uuid)) { uuid = req.getRequestURI().substring(req.getRequestURI().indexOf(Constants.SERVLET_SCANS_PREFIX) + Constants.SERVLET_SCANS_PREFIX.length() + 1); }//from w w w .ja va 2 s .com StringBuffer baseUrl = new StringBuffer(); baseUrl.append("http"); if (req.getProtocol().toLowerCase().contains("https")) { baseUrl.append('s'); } baseUrl.append("://"); if (!URLS.LOCALHOST()) { baseUrl.append(req.getServerName()); } else { String hostname = config.getHostname(); if (hostname.contains("://")) { baseUrl.append(hostname.substring(hostname.indexOf("://") + "://".length())); } else { baseUrl.append(hostname); } } StringBuffer sb = new StringBuffer(); if (topSpace != null) { String metadata = RESTHelper.convertStreamToString( RESTHelper.get(baseUrl + DJATOKA_URL_GET_METADATA + uuid, null, null, true)); String height = null; height = metadata.substring(metadata.indexOf("ght\": \"") + 7, metadata.indexOf("\",\n\"dw")); String width = metadata.substring(metadata.indexOf("dth\": \"") + 7, metadata.indexOf("\",\n\"he")); int intHeight = Integer.parseInt(height); int intUrlHeight = Integer.parseInt(urlHeight); int intTopSpace = Integer.parseInt(topSpace); boolean isLower = intTopSpace > 0 && ((intHeight - intUrlHeight) < intTopSpace); String region = (isLower ? intHeight - intUrlHeight : (intTopSpace < 0 ? 0 : topSpace)) + ",1," + urlHeight + "," + width; sb.append(baseUrl.toString()).append(DJATOKA_URL_FULL_PAGE_DETAIL).append(uuid) .append(DJATOKA_URL_REGION).append(region); } else { sb.append(baseUrl.toString()) .append(full ? DJATOKA_URL_FULL_IMG : DJATOKA_URL + urlHeight + DJATOKA_URL_SUFFIX) .append(uuid); } resp.setContentType("image/jpeg"); resp.sendRedirect(resp.encodeRedirectURL(sb.toString())); }
From source file:pl.maciejwalkowiak.plist.spring.PlistView.java
@Override protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) { response.setContentType(getContentType()); response.setCharacterEncoding(ENCODING); if (this.disableCaching) { response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-Control", "no-cache, no-store, max-age=0"); response.addDateHeader("Expires", 1L); }//from ww w. j a v a 2 s . com }
From source file:org.fcrepo.http.api.ContentExposingResource.java
/** * Add ETag and Last-Modified cache control headers to the response * @param servletResponse the servlet response * @param resource the fedora resource/* w w w .j a v a2s . com*/ * @param session the session */ protected static void addCacheControlHeaders(final HttpServletResponse servletResponse, final FedoraResource resource, final Session session) { final String txId = TransactionServiceImpl.getCurrentTransactionId(session); if (txId != null) { // Do not add caching headers if in a transaction return; } final FedoraResource mutableResource = resource instanceof NonRdfSourceDescription ? ((NonRdfSourceDescription) resource).getDescribedResource() : resource; final EntityTag etag = new EntityTag(mutableResource.getEtagValue()); final Date date = mutableResource.getLastModifiedDate(); if (!etag.getValue().isEmpty()) { servletResponse.addHeader("ETag", etag.toString()); } if (date != null) { servletResponse.addDateHeader("Last-Modified", date.getTime()); } }
From source file:net.duckling.ddl.web.controller.file.BaseAttachController.java
private void sendNotModifiedHeader(int age, MetaInfo meta, HttpServletResponse res) { res.addDateHeader("Last-Modified", meta.lastUpdate.getTime()); LOGGER.debug("?" + meta.docid); res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); }
From source file:org.unitedinternet.cosmo.dav.impl.DavCard.java
public void writeHead(final HttpServletResponse response) throws IOException { Item content = (Item) getItem();/*from w w w. ja va 2s . c o m*/ final byte[] calendar = content.getCalendar().getBytes(StandardCharsets.UTF_8); response.setContentType(content.getMimetype()); response.setContentLength(calendar.length); if (getModificationTime() >= 0) { response.addDateHeader(LAST_MODIFIED, getModificationTime()); } if (getETag() != null) { response.setHeader(ETAG, getETag()); } }
From source file:cn.featherfly.web.spring.servlet.view.json.ObjectJacksonJsonView.java
@Override protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) { setResponseContentType(request, response); response.setCharacterEncoding(this.getEncoding().getJavaName()); if (cacheExpires > 0) { response.addHeader("Cache-Control", "max-age=" + cacheExpires); } else {// www . j a v a 2 s .c o m response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-Control", "no-cache, no-store, max-age=0"); response.addDateHeader("Expires", 1L); } }