Example usage for org.springframework.http HttpStatus NOT_MODIFIED

List of usage examples for org.springframework.http HttpStatus NOT_MODIFIED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus NOT_MODIFIED.

Prototype

HttpStatus NOT_MODIFIED

To view the source code for org.springframework.http HttpStatus NOT_MODIFIED.

Click Source Link

Document

304 Not Modified .

Usage

From source file:net.eusashead.hateoas.response.impl.AbstractEntityResponseBuilder.java

protected ResponseEntity<V> buildResponseEntity(V body) {

    // ResponseEntity to return
    ResponseEntity<V> responseEntity;

    // Check ETag against request value
    if (headers.getETag() != null && compareEtagWithIfNoneMatch(headers.getETag())) {
        // Return 304 Not Modified
        responseEntity = new ResponseEntity<V>(headers, HttpStatus.NOT_MODIFIED);
    } else {/*from w  w w. j  av a2 s. c o  m*/
        // Is it a HEAD or a GET
        if (request.getMethod().equals("HEAD")) {
            // Return 204 and the headers
            responseEntity = new ResponseEntity<V>(headers, HttpStatus.NO_CONTENT);
        } else if (request.getMethod().equals("GET")) {
            // Return 200 and the entity
            responseEntity = new ResponseEntity<V>(body, headers, HttpStatus.OK);
        } else {
            throw new RuntimeException(String
                    .format("esponseBuilder does not handle verb %s, only GET or HEAD.", request.getMethod()));
        }
    }

    // Return the ResponseEntity
    return responseEntity;
}

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

ResponseEntity<byte[]> creteHttpResponse(long ifModifiedSince, UploadFileSummary summary,
        HttpHeaders responseHeaders) {/*from  ww w . j  a v a  2s  . c o m*/
    if (summary.getLastModifiedDate().isAfter(ifModifiedSince)) {
        UploadFile uploadFile = uploadFileService.findOne(summary.getFileId());
        return new ResponseEntity<>(uploadFile.getFileContent(), responseHeaders, HttpStatus.OK);
    } else {
        return new ResponseEntity<>(responseHeaders, HttpStatus.NOT_MODIFIED);
    }
}

From source file:org.ff4j.spring.boot.exceptions.FF4jExceptionHandler.java

@ExceptionHandler(value = RoleExistsException.class)
@ResponseStatus(value = HttpStatus.NOT_MODIFIED, reason = "role already exists")
public void roleExistsException() {
    // Not necessary to handle this exception
}

From source file:com.alehuo.wepas2016projekti.controller.ImageController.java

/**
 * Hakee tietokannasta kuvan. Kuvan hakemisessa hydynnetn ETag
 * -otsaketta./*from w w  w.ja va2  s . c om*/
 *
 * @param a Autentikointi
 * @param imageUuid Kuvan UUID
 * @param ifNoneMatch If-None-Match -headeri vlimuistia varten
 * @return Kuva
 */
@RequestMapping(value = "/{imageUuid}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<byte[]> getImage(Authentication a, @PathVariable String imageUuid,
        @RequestHeader(required = false, value = "If-None-Match") String ifNoneMatch) {
    if (ifNoneMatch != null) {
        //            LOG.log(Level.INFO, "Kuva ''{0}'' loytyy kayttajan selaimen valimuistista eika sita tarvitse ladata. Kuvaa pyysi kayttaja ''{1}''", new Object[]{imageUuid, a.getName()});
        //Jos If-None-Match -headeri lytyy, niin lhet NOT MODIFIED vastaus
        return new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
    }
    Image i = imageService.findOneImageByUuid(imageUuid);
    if (i != null && i.isVisible()) {
        //Luodaan ETag kuvalle
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.parseMediaType(i.getContentType()));
        headers.setContentLength(i.getImageData().length);
        headers.setCacheControl("public");
        headers.setExpires(Long.MAX_VALUE);
        headers.setETag("\"" + imageUuid + "\"");
        //            LOG.log(Level.INFO, "Kuva ''{0}'' loytyi tietokannasta, ja sita pyysi kayttaja ''{1}''", new Object[]{imageUuid, a.getName()});
        //Palautetaan kuva uutena resurssina
        return new ResponseEntity<>(i.getImageData(), headers, HttpStatus.CREATED);
    } else {
        //Jos kuvaa ei lydy tietokannasta
        LOG.log(Level.WARNING, "Kuvaa ''{0}'' ei loytynyt tietokannasta, ja sita pyysi kayttaja ''{1}''",
                new Object[] { imageUuid, a.getName() });
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:com.surevine.alfresco.repo.ldap.GroupSyncJob.java

/**
 * Execution frequency defined in scheduled-jobs-context.xml
 *///from  w w w.  j  a va  2 s .  co m
@Override
public void execute(final JobExecutionContext ctx) throws JobExecutionException {
    PropertyWrapper wrapper;
    CasAuthenticator authenticator;
    try {
        wrapper = new PropertyWrapper(SYNC_PROPERTIES);
        authenticator = new CasAuthenticator(wrapper);
    } catch (final PropertyException e) {
        LOG.error(e);
        throw new JobExecutionException("Configuration error when checking for security model updates.", e);
    }

    SecurityModelConnector connector;
    AlfrescoHttpResponse securityModel;
    try {
        connector = new SecurityModelConnector(wrapper, authenticator);
        securityModel = connector.getSecurityModel();
    } catch (final AlfrescoException e) {
        LOG.error(e);
        throw new JobExecutionException("Failure while checking for updates to the security model.", e);
    }

    if (securityModel.getStatusCode() != HttpStatus.NOT_MODIFIED.value()) {
        LOG.info("The security model has been modified in LDAP. Attempting to update...");

        try {
            final String securityModelXML = securityModel.asString();

            if (LOG.isDebugEnabled()) {
                LOG.debug(securityModelXML);
            }

            connector.setSecurityModel(securityModelXML);
        } catch (final AlfrescoException e) {
            LOG.error("SEVERE ERROR UPDATING SECURITY MODEL", e);
            throw new JobExecutionException(
                    "The model has been updated in LDAP but failed updating the model in Alfresco.", e);
        }

        LOG.info("...security model has been updated successfully.");
    } else {
        LOG.info("The security model has not been modified in LDAP. Skipping update to Alfresco.");
    }
}

From source file:org.ff4j.spring.boot.exceptions.FF4jExceptionHandler.java

@ExceptionHandler(value = GroupExistsException.class)
@ResponseStatus(value = HttpStatus.NOT_MODIFIED, reason = "group already exists")
public void groupExistsException() {
    // Not necessary to handle this exception
}

From source file:org.kuali.mobility.configparams.controllers.ConfigParamController.java

@RequestMapping(method = RequestMethod.POST, headers = "Accept=application/json")
public ResponseEntity<String> post(@RequestBody String json) {
    ConfigParam cp = configParamService.fromJsonToEntity(json);
    if (cp.getName() != null && cp.getValue() != null && cp.getName().length() > 0
            && cp.getValue().length() > 0) {
        Long id = configParamService.saveConfigParam(cp);
        if (id == null) {
            return new ResponseEntity<String>(HttpStatus.NOT_MODIFIED);
        }/*  ww w . j  a v a2s . c o m*/
        return new ResponseEntity<String>(HttpStatus.CREATED);
    }
    return new ResponseEntity<String>(HttpStatus.NOT_MODIFIED);
}

From source file:ca.intelliware.ihtsdo.mlds.web.rest.MemberResource.java

private ResponseEntity<?> downloadFile(HttpServletRequest request, File file) throws SQLException, IOException {
    if (file == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    } else if (file.getLastUpdated() != null) {
        long ifModifiedSince = request.getDateHeader("If-Modified-Since");
        long lastUpdatedSecondsFloor = file.getLastUpdated().getMillis() / 1000 * 1000;
        if (ifModifiedSince != -1 && lastUpdatedSecondsFloor <= ifModifiedSince) {
            return new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
        }/*from   w  ww.  j  ava2  s  . c om*/
    }

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.valueOf(file.getMimetype()));
    httpHeaders.setContentLength(file.getContent().length());
    httpHeaders.setContentDispositionFormData("file", file.getFilename());
    if (file.getLastUpdated() != null) {
        httpHeaders.setLastModified(file.getLastUpdated().getMillis());
    }

    byte[] byteArray = IOUtils.toByteArray(file.getContent().getBinaryStream());
    org.springframework.core.io.Resource contents = new ByteArrayResource(byteArray);
    return new ResponseEntity<org.springframework.core.io.Resource>(contents, httpHeaders, HttpStatus.OK);
}

From source file:edu.eci.cosw.restcontrollers.RestControladorRegistrarReserva.java

@RequestMapping(value = "/pagoalquiler", method = RequestMethod.POST)
public ResponseEntity<?> pagarAlquiler(@RequestBody Pago p) {
    HttpStatus status = HttpStatus.NOT_MODIFIED;
    String message = "";
    //logica.realizarPago(p.getIdAlquiler(), p.getMonto(), p.getNumtarjeta(), p.getTipoP());
    if (logica.realizarPago(p.getIdAlquiler(), p.getMonto(), p.getNumtarjeta(), p.getTipoP())) {
        status = HttpStatus.ACCEPTED;/*from   w  w w.j  a va2s  .  co m*/
        message = "Solicitud de pago aceptada";
    } else {
        status = HttpStatus.CONFLICT;
        message = "Solicitud de pago rechazada, error de tarjeta o insuficiencia de pago";
    }
    return new ResponseEntity<>(message, status);
}

From source file:org.kuali.mobility.emergencyinfo.controllers.EmergencyInfoController.java

@RequestMapping(method = RequestMethod.PUT, headers = "Accept=application/json")
public ResponseEntity<String> put(@RequestBody String json) {
    if (emergencyInfoService
            .findEmergencyInfoById(emergencyInfoService.fromJsonToEntity(json).getEmergencyInfoId()) == null) {
        return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
    } else {/*from  w  w  w .j av a  2  s.c  o m*/
        if (emergencyInfoService.saveEmergencyInfo(emergencyInfoService.fromJsonToEntity(json)) == null) {
            return new ResponseEntity<String>(HttpStatus.NOT_MODIFIED);
        }
    }
    return new ResponseEntity<String>(HttpStatus.OK);
}