List of usage examples for com.google.common.net HttpHeaders IF_MODIFIED_SINCE
String IF_MODIFIED_SINCE
To view the source code for com.google.common.net HttpHeaders IF_MODIFIED_SINCE.
Click Source Link
From source file:org.jclouds.openstack.swift.v1.options.CopyOptions.java
public CopyOptions ifModifiedSince(Date ifModifiedSince) { this.headers.put(HttpHeaders.IF_MODIFIED_SINCE, dateService.rfc822DateFormat(ifModifiedSince)); return this; }
From source file:com.cnksi.core.web.utils.Servlets.java
/** * ??If-Modified-Since Header, ?./*from w ww . j ava 2 s . c om*/ * * , checkIfModifyfalse ,304 not modify status. * * @param lastModified ?. */ public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastModified) { long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return false; } return true; }
From source file:cn.martin.sys.utils.Servlets.java
/** * ??If-Modified-Since Header, ?./*from www . j av a2 s .c om*/ * * , checkIfModifyfalse ,304 not modify status. * * @param lastModified ?. */ public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastModified) { long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if ((ifModifiedSince != -1) && (lastModified < (ifModifiedSince + 1000))) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return false; } return true; }
From source file:com.google.gerrit.httpd.plugins.SmallResource.java
@Override void send(HttpServletRequest req, HttpServletResponse res) throws IOException { if (0 < lastModified) { long ifModifiedSince = req.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if (ifModifiedSince > 0 && ifModifiedSince == lastModified) { res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } else {/*from w ww. j a va2 s .c o m*/ res.setDateHeader("Last-Modified", lastModified); } } res.setContentType(contentType); if (characterEncoding != null) { res.setCharacterEncoding(characterEncoding); } res.setContentLength(data.length); res.getOutputStream().write(data); }
From source file:com.google.gerrit.httpd.resources.SmallResource.java
@Override public void send(HttpServletRequest req, HttpServletResponse res) throws IOException { if (0 < lastModified) { long ifModifiedSince = req.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if (ifModifiedSince > 0 && ifModifiedSince == lastModified) { res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; }/*from ww w . j ava 2s. c o m*/ res.setDateHeader("Last-Modified", lastModified); } res.setContentType(contentType); if (characterEncoding != null) { res.setCharacterEncoding(characterEncoding); } res.setContentLength(data.length); res.getOutputStream().write(data); }
From source file:com.trc.core2.web.Servlets.java
/** * ??If-Modified-Since Header, ?./*from ww w . j av a 2 s. c o m*/ * * , checkIfModifyfalse ,304 not modify status. * * @param lastModified ?. */ public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response, long lastModified) { long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE); if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return false; } return true; }
From source file:org.haiku.haikudepotserver.pkg.controller.PkgController.java
/** * <p>This streams back a redirect to report data that contains a JSON stream gzip-compressed * that describes all of the packages for a repository source. This is used by clients to get * deep(ish) data on all pkgs without having to query each one.</p> * * <p>The primary client for this is the Haiku desktop application "Haiku Depot". * This API deprecates and older JSON-RPC API for obtaining bulk data.</p> *//*from ww w . ja v a 2 s . co m*/ // TODO; observe the natural language code @RequestMapping(value = "/all-{repositorySourceCode}-{naturalLanguageCode}.json.gz", method = RequestMethod.GET) public void getAllAsJson(HttpServletResponse response, @PathVariable(value = KEY_NATURALLANGUAGECODE) String naturalLanguageCode, @PathVariable(value = KEY_REPOSITORYSOURCECODE) String repositorySourceCode, @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) String ifModifiedSinceHeader) throws IOException { ObjectContext objectContext = serverRuntime.newContext(); Optional<RepositorySource> repositorySourceOptional = RepositorySource.tryGetByCode(objectContext, repositorySourceCode); if (!repositorySourceOptional.isPresent()) { LOGGER.info("repository source [" + repositorySourceCode + "] not found"); response.setStatus(HttpStatus.NOT_FOUND.value()); } else { Date lastModifiedTimestamp = pkgService.getLastModifyTimestampSecondAccuracy(objectContext, repositorySourceOptional.get()); PkgDumpExportJobSpecification specification = new PkgDumpExportJobSpecification(); specification.setNaturalLanguageCode(naturalLanguageCode); specification.setRepositorySourceCode(repositorySourceCode); JobController.handleRedirectToJobData(response, jobService, ifModifiedSinceHeader, lastModifiedTimestamp, specification); } }
From source file:org.ardverk.dropwizard.assets.AssetsDirectoryServlet.java
/** * Returns {@code true} if the client has an up-to-date version of the asset. *///from w w w . j a v a 2 s . c o m private static boolean isCurrent(HttpServletRequest request, AssetsDirectory.Entry entry) { String etag = entry.getETag(); long lastModified = entry.getLastModified(); return etag.equals(request.getHeader(HttpHeaders.IF_NONE_MATCH)) || (request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE) >= lastModified); }
From source file:org.haiku.haikudepotserver.repository.controller.RepositoryController.java
/** * <p>This streams back a redirect to report data that contains a JSON stream gzip-compressed * that describes all of the repositories. This is used by clients to get deep(ish) data on all * repositories without having to query each one.</p> *///from w w w . ja v a 2 s . com // TODO; observe the natural language code @RequestMapping(value = { "/all_{naturalLanguageCode}.json.gz", // deprecated "/all-{naturalLanguageCode}.json.gz" }, method = RequestMethod.GET) public void getAllAsJson(HttpServletResponse response, @PathVariable(value = KEY_NATURALLANGUAGECODE) String naturalLanguageCode, @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) String ifModifiedSinceHeader) throws IOException { JobController.handleRedirectToJobData(response, jobService, ifModifiedSinceHeader, repositoryService.getLastRepositoryModifyTimestampSecondAccuracy(serverRuntime.newContext()), new RepositoryDumpExportJobSpecification()); }
From source file:org.haiku.haikudepotserver.job.controller.JobController.java
/** * <p>This is helper-code that can be used to check to see if the data is stale and * will then enqueue the job, run it and then redirect the user to the data * download.</p>/*www . ja va2s.c om*/ * @param response is the HTTP response to send the redirect to. * @param ifModifiedSinceHeader is the inbound header from the client. * @param lastModifyTimestamp is the actual last modified date for the data. * @param jobSpecification is the job that would be run if the data is newer than in the * inbound header. */ public static void handleRedirectToJobData(HttpServletResponse response, JobService jobService, String ifModifiedSinceHeader, Date lastModifyTimestamp, JobSpecification jobSpecification) throws IOException { if (!Strings.isNullOrEmpty(ifModifiedSinceHeader)) { try { Date requestModifyTimestamp = new Date(Instant .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifModifiedSinceHeader)).toEpochMilli()); if (requestModifyTimestamp.getTime() >= lastModifyTimestamp.getTime()) { response.setStatus(HttpStatus.NOT_MODIFIED.value()); return; } } catch (DateTimeParseException dtpe) { LOGGER.warn("bad [{}] header on request; [{}] -- will ignore", HttpHeaders.IF_MODIFIED_SINCE, StringUtils.abbreviate(ifModifiedSinceHeader, 128)); } } // what happens here is that we get the report and if it is too old, delete it and try again. JobSnapshot jobSnapshot = getJobSnapshotStartedAfter(jobService, lastModifyTimestamp, jobSpecification); Set<String> jobDataGuids = jobSnapshot.getDataGuids(); if (1 != jobDataGuids.size()) { throw new IllegalStateException("found [" + jobDataGuids.size() + "] job data guids related to the job [" + jobSnapshot.getGuid() + "] - was expecting 1"); } String lastModifiedValue = DateTimeFormatter.RFC_1123_DATE_TIME .format(ZonedDateTime.ofInstant(lastModifyTimestamp.toInstant(), ZoneOffset.UTC)); String destinationLocationUrl = UriComponentsBuilder.newInstance() .pathSegment(AuthenticationFilter.SEGMENT_SECURED).pathSegment(JobController.SEGMENT_JOBDATA) .pathSegment(jobDataGuids.iterator().next()).pathSegment(JobController.SEGMENT_DOWNLOAD) .toUriString(); response.addHeader(HttpHeaders.LAST_MODIFIED, lastModifiedValue); response.sendRedirect(destinationLocationUrl); }