Example usage for org.springframework.http HttpHeaders IF_MODIFIED_SINCE

List of usage examples for org.springframework.http HttpHeaders IF_MODIFIED_SINCE

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders IF_MODIFIED_SINCE.

Prototype

String IF_MODIFIED_SINCE

To view the source code for org.springframework.http HttpHeaders IF_MODIFIED_SINCE.

Click Source Link

Document

The HTTP If-Modified-Since header field name.

Usage

From source file:am.ik.categolj2.api.file.FileRestController.java

@RequestMapping(value = "{fileId}/{fileName:.+}", method = RequestMethod.GET)
public ResponseEntity<byte[]> downloadFile(@PathVariable("fileId") String fileId,
        @PathVariable("fileName") String fileName, HttpServletRequest request) {
    UploadFileSummary summary = uploadFileService.findOneSummary(fileId);
    HttpHeaders headers = new HttpHeadersBuilder(mediaTypeResolver)
            .contentTypeAttachmentIfNeccessary(summary.getFileName())
            .lastModified(summary.getLastModifiedDate()).cacheForSeconds(cacheSeconds, false).build();
    long ifModifiedSince = request.getDateHeader(com.google.common.net.HttpHeaders.IF_MODIFIED_SINCE);
    fileHelper.checkFileName(summary.getFileName(), fileName);
    return fileHelper.creteHttpResponse(ifModifiedSince, summary, headers);
}

From source file:com.github.zhanhb.ckfinder.download.PathPartial.java

/**
 * Check if the if-modified-since condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param attr File attributes/*from   w  ww. j a v a 2 s  . c  om*/
 */
@SuppressWarnings("NestedAssignment")
private void checkIfModifiedSince(HttpServletRequest request, BasicFileAttributes attr) {
    try {
        long headerValue;
        // If an If-None-Match header has been specified, if modified since
        // is ignored.
        if (request.getHeader(HttpHeaders.IF_NONE_MATCH) == null
                && (headerValue = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)) != -1
                && attr.lastModifiedTime().toMillis() < headerValue + 1000) {
            // The entity has not been modified since the date
            // specified by the client. This is not an error case.
            throw new UncheckException(HttpServletResponse.SC_NOT_MODIFIED);
        }
    } catch (IllegalArgumentException ex) {
    }
}

From source file:net.turnbig.pandora.web.Servlets.java

/**
 * ??If-Modified-Since Header, ?./*from w  ww . ja v a2 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.ambraproject.rhino.rest.controller.ArticleCrudController.java

/**
 * Read article metadata.//  ww w  .  j  a  v  a 2 s .  co m
 *
 * @throws IOException
 */
@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi}/ingestions/{number}", method = RequestMethod.GET)
public ResponseEntity<?> read(
        @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("doi") String doi, @PathVariable("number") int ingestionNumber) throws IOException {
    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(DoiEscaping.unescape(doi),
            ingestionNumber);
    return articleCrudService.serveMetadata(ingestionId).getIfModified(ifModifiedSince)
            .asJsonResponse(entityGson);
}

From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java

@Transactional()
@RequestMapping(value = "/articles/{doi}/ingestions/{number}", method = RequestMethod.POST)
public ResponseEntity<?> updatePreprintDoi(
        @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("doi") String doi, @PathVariable("number") int ingestionNumber,
        @RequestParam("preprintDoi") String preprintDoi) throws IOException {
    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(DoiEscaping.unescape(doi),
            ingestionNumber);//from   w  w w .j ava 2  s.  c o m

    articleCrudService.updatePreprintDoi(ingestionId, preprintDoi);

    return articleCrudService.serveMetadata(ingestionId).getIfModified(ifModifiedSince)
            .asJsonResponse(entityGson);
}

From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java

@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi}/revisions/{revision}", method = RequestMethod.GET)
public ResponseEntity<?> readRevision(
        @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("doi") String doi, @PathVariable(value = "revision") Integer revisionNumber)
        throws IOException {
    ArticleRevisionIdentifier id = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
    return articleCrudService.serveRevision(id).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}

From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java

@RequestMapping(value = "/articles/{doi}/ingestions/{number}/items", method = RequestMethod.GET)
public ResponseEntity<?> readItems(
        @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("doi") String doi, @PathVariable("number") int ingestionNumber) throws IOException {
    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(DoiEscaping.unescape(doi),
            ingestionNumber);/*  w  w  w  .  j a va 2 s .  c  om*/
    return articleCrudService.serveItems(ingestionId).getIfModified(ifModifiedSince).asJsonResponse(entityGson);
}

From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java

/**
 * Retrieves a list of objects representing the authors of the article. While the article metadata contains author
 * names, this list will contain more author information than the article metadata, such as author affiliations,
 * corresponding author, etc.//  w w w  . j  a  v a 2s  .c  o m
 *
 * @throws IOException
 */
@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi}/ingestions/{number}/authors", method = RequestMethod.GET)
public ResponseEntity<?> readAuthors(
        @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("doi") String doi, @PathVariable("number") int ingestionNumber) throws IOException {

    ArticleIngestionIdentifier ingestionId = ArticleIngestionIdentifier.create(DoiEscaping.unescape(doi),
            ingestionNumber);
    return articleCrudService.serveAuthors(ingestionId).getIfModified(ifModifiedSince)
            .asJsonResponse(entityGson);
}

From source file:org.ambraproject.rhino.rest.controller.IssueCrudController.java

@Transactional(readOnly = true)
@RequestMapping(value = "/issues/{issueDoi:.+}", method = RequestMethod.GET)
public ResponseEntity<?> read(
        @RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("issueDoi") String issueDoi) throws IOException {
    IssueIdentifier issueId = getIssueId(issueDoi);
    return issueCrudService.serveIssue(issueId).getIfModified(ifModifiedSince).asJsonResponse(entityGson);

    // TODO: Equivalent alias methods for other HTTP methods?
}

From source file:org.ambraproject.rhino.rest.controller.IssueCrudController.java

@Transactional(readOnly = true)
@RequestMapping(value = "/journals/{journalKey}/volumes/{volumeDoi}/issues/{issueDoi:.+}", method = RequestMethod.GET)
public void read(@RequestHeader(value = HttpHeaders.IF_MODIFIED_SINCE, required = false) Date ifModifiedSince,
        @PathVariable("journalKey") String journalKey, @PathVariable("volumeDoi") String volumeDoi,
        @PathVariable("issueDoi") String issueDoi) throws IOException {
    // TODO: Validate journalKey and volumeDoi
    read(ifModifiedSince, issueDoi);/*from   www  .  j  av  a2s . co m*/
}