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:org.kuali.mobility.configparams.controllers.ConfigParamController.java

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

From source file:com.appglu.impl.StorageTemplate.java

protected boolean streamStorageFile(StorageFile file, final InputStreamCallback inputStreamCallback,
        RequestCallback requestCallback) throws AppGluRestClientException {
    URI uri = this.getStorageFileURI(file);

    try {/*from  w  w  w . j av a 2  s.c  o m*/
        ResponseExtractor<Boolean> responseExtractor = new ResponseExtractor<Boolean>() {
            public Boolean extractData(ClientHttpResponse response) throws IOException {
                if (response.getStatusCode() == HttpStatus.NOT_MODIFIED) {
                    return false;
                }

                Md5DigestCalculatingInputStream inputStream = new Md5DigestCalculatingInputStream(
                        response.getBody());
                inputStreamCallback.doWithInputStream(inputStream);

                String eTagHeader = response.getHeaders().getETag();

                if (StringUtils.isNotEmpty(eTagHeader)) {
                    String eTag = StringUtils.removeDoubleQuotes(eTagHeader);

                    byte[] contentMd5 = inputStream.getMd5Digest();
                    if (!HashUtils.md5MatchesWithETag(contentMd5, eTag)) {
                        throw new AppGluRestClientException("Unable to verify integrity of downloaded file. "
                                + "Client calculated content hash didn't match hash calculated by server");
                    }
                }

                return true;
            }
        };

        return this.downloadRestOperations.execute(uri, HttpMethod.GET, requestCallback, responseExtractor);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

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

@RequestMapping(value = "/collection", method = RequestMethod.PUT, headers = "Accept=application/json")
public ResponseEntity<String> putAll(@RequestBody String json) {
    for (EmergencyInfo emergencyInfo : emergencyInfoService.fromJsonToCollection(json)) {
        if (emergencyInfoService.findEmergencyInfoById(emergencyInfo.getEmergencyInfoId()) == null) {
            return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
        } else {//www .  j a  va2 s .  c o m
            if (emergencyInfoService.saveEmergencyInfo(emergencyInfo) == null) {
                return new ResponseEntity<String>(HttpStatus.NOT_MODIFIED);
            }
        }
    }
    return new ResponseEntity<String>(HttpStatus.OK);
}

From source file:org.mythtv.service.dvr.v25.UpcomingHelperV25.java

private void downloadUpcoming(final Context context, final LocationProfile locationProfile)
        throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException {
    Log.v(TAG, "downloadUpcoming : enter");

    EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetUpcomingList",
            "");//from w  w w .j av  a 2s.c  o  m
    Log.d(TAG, "downloadUpcoming : etag=" + etag.getValue());

    ResponseEntity<ProgramList> responseEntity = mMythServicesTemplate.dvrOperations().getUpcomingList(null,
            null, Boolean.FALSE, etag);

    DateTime date = new DateTime(DateTimeZone.UTC);
    if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
        Log.i(TAG, "downloadUpcoming : GetUpcomingList returned 200 OK");
        ProgramList programList = responseEntity.getBody();

        if (null != programList.getPrograms()) {

            load(context, locationProfile, programList.getPrograms());

            if (null != etag.getValue()) {
                Log.i(TAG, "downloadUpcoming : saving etag: " + etag.getValue());

                etag.setEndpoint("GetUpcomingList");
                etag.setDate(date);
                etag.setMasterHostname(locationProfile.getHostname());
                etag.setLastModified(date);
                mEtagDaoHelper.save(context, locationProfile, etag);
            }

        }

    }

    if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) {
        Log.i(TAG, "downloadUpcoming : GetUpcomingList returned 304 Not Modified");

        if (null != etag.getValue()) {
            Log.i(TAG, "downloadUpcoming : saving etag: " + etag.getValue());

            etag.setLastModified(date);
            mEtagDaoHelper.save(context, locationProfile, etag);
        }

    }

    Log.v(TAG, "downloadUpcoming : exit");
}

From source file:su90.mybatisdemo.web.endpoints.EmployeesEndpoints.java

@RequestMapping(value = { "/delete/{id}" }, method = RequestMethod.DELETE, produces = {
        MediaType.TEXT_PLAIN_VALUE })//from   ww w  .ja va 2 s.c  o  m
public ResponseEntity<String> deleteUser(@PathVariable("id") Long id) {
    try {
        employeesService.deleteEntryById(id);
    } catch (BeanAbsent e) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } catch (Exception e) {
        return new ResponseEntity<>(HttpStatus.NOT_MODIFIED);
    }
    return new ResponseEntity<>(HttpStatus.OK);

}

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

@Test
public void testConditionalHead() throws Exception {

    // Set up request with If-None-Match
    request = new MockHttpServletRequest("HEAD", "http://localhost/resource/1");
    request.addHeader("If-None-Match", "W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"");
    builder = new EntityResponseBuilderImpl<Entity>(request);

    // Set up response with ETag matching If-None-Match
    Entity entity = new Entity("foo");
    ResponseEntity<Entity> response = builder.entity(entity).etag().build();
    Assert.assertNotNull(response);//from  www. j a va2  s . c  om
    Assert.assertNull(response.getBody());
    Assert.assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
    Assert.assertNotNull(response.getHeaders().getETag());
    Assert.assertEquals("W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"", response.getHeaders().getETag());
}

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

@Test
public void testConditionalGet() throws Exception {

    // Set up request with If-None-Match
    request = new MockHttpServletRequest("GET", "http://localhost/resource/1");
    request.addHeader("If-None-Match", "W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"");
    builder = new EntityResponseBuilderImpl<Entity>(request);

    // Set up response with ETag matching If-None-Match
    Entity entity = new Entity("foo");
    ResponseEntity<Entity> response = builder.entity(entity).etag().build();
    Assert.assertNotNull(response);//from   w  w w  .j  a  v a2s  .c o m
    Assert.assertNull(response.getBody());
    Assert.assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
    Assert.assertNotNull(response.getHeaders().getETag());
    Assert.assertEquals("W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"", response.getHeaders().getETag());
}

From source file:com.auditbucket.engine.endpoint.TrackEP.java

@ResponseBody
@RequestMapping(value = "/log/", consumes = "application/json", produces = "application/json", method = RequestMethod.POST)
public ResponseEntity<LogResultBean> trackLog(@RequestBody LogInputBean input, String apiKey,
        @RequestHeader(value = "Api-Key", required = false) String apiHeaderKey) throws DatagioException {

    // If we have a valid company we are good to go.
    Company company = getCompany(apiHeaderKey, apiKey);

    LogResultBean resultBean = mediationFacade.processLogForCompany(company, input);
    LogInputBean.LogStatus ls = resultBean.getStatus();
    if (ls.equals(LogInputBean.LogStatus.FORBIDDEN))
        return new ResponseEntity<>(resultBean, HttpStatus.FORBIDDEN);
    else if (ls.equals(LogInputBean.LogStatus.NOT_FOUND)) {
        input.setAbMessage("Illegal meta key");
        return new ResponseEntity<>(resultBean, HttpStatus.NOT_FOUND);
    } else if (ls.equals(LogInputBean.LogStatus.IGNORE)) {
        input.setAbMessage("Ignoring request to change as the 'what' has not changed");
        return new ResponseEntity<>(resultBean, HttpStatus.NOT_MODIFIED);
    } else if (ls.equals(LogInputBean.LogStatus.ILLEGAL_ARGUMENT)) {
        return new ResponseEntity<>(resultBean, HttpStatus.NO_CONTENT);
    }/*from   w  ww  . j av a2  s .c  o  m*/

    return new ResponseEntity<>(resultBean, HttpStatus.OK);
}