List of usage examples for org.springframework.http HttpStatus NOT_MODIFIED
HttpStatus NOT_MODIFIED
To view the source code for org.springframework.http HttpStatus NOT_MODIFIED.
Click Source Link
From source file:com.appglu.impl.StorageTemplateTest.java
@Test @SuppressWarnings("unchecked") public void streamStorageFileIfModifiedSince_notModified() { downloadMockServer.expect(requestTo(URL)).andExpect(header("If-Modified-Since", notNullValue())) .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_MODIFIED)); StorageFile storageFile = new StorageFile(URL); storageFile.setLastModified(new Date(LAST_MODIFIED_DATE)); boolean wasModified = this.storageOperations.streamStorageFileIfModifiedSince(storageFile, new InputStreamCallback() { public void doWithInputStream(InputStream inputStream) throws IOException { Assert.fail("Should not stream the file because it was not modified"); }/* w ww .ja v a2s. co m*/ }); Assert.assertFalse(wasModified); downloadMockServer.verify(); }
From source file:org.focusns.web.modules.profile.ProjectUserWidget.java
@RequestMapping("/user-avatar/download") public ResponseEntity<byte[]> doAvatar(@RequestParam Long userId, @RequestParam(required = false) Boolean temp, @RequestParam(required = false) Integer width, @RequestParam(required = false) Integer height, WebRequest webRequest) throws IOException { ///*ww w .j a v a 2s. c om*/ boolean notModified = false; InputStream inputStream = null; // ProjectUser projectUser = projectUserService.getProjectUser(userId); Object[] avatarCoordinates = CoordinateHelper.getAvatarCoordinates(projectUser); if (temp != null && temp.booleanValue()) { long lastModified = storageService.checkTempResource(avatarCoordinates); if (lastModified > 0 && webRequest.checkNotModified(lastModified)) { notModified = true; } else { inputStream = storageService.loadTempResource(avatarCoordinates); } } else if (width == null || height == null) { long lastModified = storageService.checkResource(avatarCoordinates); if (lastModified > 0 && webRequest.checkNotModified(lastModified)) { notModified = true; } else { inputStream = storageService.loadResource(avatarCoordinates); } } else { Object size = width + "x" + height; long lastModified = storageService.checkSizedResource(size, avatarCoordinates); if (lastModified > 0 && webRequest.checkNotModified(lastModified)) { notModified = true; } else { inputStream = storageService.loadSizedResource(size, avatarCoordinates); } } // if (notModified) { return new ResponseEntity<byte[]>(HttpStatus.NOT_MODIFIED); } // return WebUtils.getResponseEntity(FileCopyUtils.copyToByteArray(inputStream), MediaType.IMAGE_PNG); }
From source file:org.mythtv.service.guide.v25.ProgramGuideHelperV25.java
private static void downloadProgramGuide(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadProgramGuide : enter"); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ProgramHelperV25.getInstance().deletePrograms(context, locationProfile, ops, ProgramConstants.CONTENT_URI_GUIDE, ProgramConstants.TABLE_NAME_GUIDE); RecordingHelperV25.getInstance().deleteRecordings(context, locationProfile, ops, ContentDetails.GUIDE); DateTime startDownloading = new DateTime(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); int downloadDays = Integer.parseInt(sp.getString("preference_program_guide_days", "14")); Log.v(TAG, "downloadProgramGuide : downloadDays=" + downloadDays); DateTime start = new DateTime(DateTimeZone.getDefault()).withTimeAtStartOfDay(); DateTime end = start.plusHours(3);/*from w w w.j a va2 s .co m*/ for (int i = 0; i < ((downloadDays * 24) / 3); i++) { Log.i(TAG, "downloadProgramGuide : starting download for [" + (i + 1) + " of " + ((downloadDays * 24) / 3) + "] " + DateUtils.getDateTimeUsingLocaleFormattingPretty(start, mMainApplication.getDateFormat(), mMainApplication.getClockType()) + ", end time=" + DateUtils.getDateTimeUsingLocaleFormattingPretty(end, mMainApplication.getDateFormat(), mMainApplication.getClockType())); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetProgramGuide", String.valueOf(i)); Log.d(TAG, "downloadProgramGuide : etag=" + etag.getValue()); if (null == etag.getDate() || start.isAfter(etag.getDate())) { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has passed"); ResponseEntity<ProgramGuide> responseEntity = mMythServicesTemplate.guideOperations() .getProgramGuide(start, end, 1, null, false, etag); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 200 OK"); ProgramGuide programGuide = responseEntity.getBody(); if (null != programGuide) { if (null != programGuide) { load(context, locationProfile, programGuide); } } if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setEndpoint("GetProgramGuide"); etag.setDataId(i); etag.setDate(locationProfile.getNextMythFillDatabase()); etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } start = end; end = end.plusHours(3); } else { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has NOT passed!"); } } Log.i(TAG, "downloadProgramGuide : interval=" + new Interval(startDownloading, new DateTime()).toString()); Log.v(TAG, "downloadProgramGuide : exit"); }
From source file:org.mythtv.service.guide.v26.ProgramGuideHelperV26.java
private static void downloadProgramGuide(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadProgramGuide : enter"); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ProgramHelperV26.getInstance().deletePrograms(context, locationProfile, ops, ProgramConstants.CONTENT_URI_GUIDE, ProgramConstants.TABLE_NAME_GUIDE); RecordingHelperV26.getInstance().deleteRecordings(context, locationProfile, ops, ContentDetails.GUIDE); DateTime startDownloading = new DateTime(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); int downloadDays = Integer.parseInt(sp.getString("preference_program_guide_days", "14")); Log.v(TAG, "downloadProgramGuide : downloadDays=" + downloadDays); DateTime start = new DateTime(DateTimeZone.getDefault()).withTimeAtStartOfDay(); DateTime end = start.plusHours(3);/*from ww w .j a v a 2 s .c o m*/ for (int i = 0; i < ((downloadDays * 24) / 3); i++) { Log.i(TAG, "downloadProgramGuide : starting download for [" + (i + 1) + " of " + ((downloadDays * 24) / 3) + "] " + DateUtils.getDateTimeUsingLocaleFormattingPretty(start, mMainApplication.getDateFormat(), mMainApplication.getClockType()) + ", end time=" + DateUtils.getDateTimeUsingLocaleFormattingPretty(end, mMainApplication.getDateFormat(), mMainApplication.getClockType())); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetProgramGuide", String.valueOf(i)); Log.d(TAG, "downloadProgramGuide : etag=" + etag.getValue()); if (null == etag.getDate() || start.isAfter(etag.getDate())) { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has passed"); ResponseEntity<ProgramGuide> responseEntity = mMythServicesTemplate.guideOperations() .getProgramGuide(start, end, 1, null, false, etag); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 200 OK"); ProgramGuide programGuide = responseEntity.getBody(); if (null != programGuide) { if (null != programGuide) { load(context, locationProfile, programGuide); } } if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setEndpoint("GetProgramGuide"); etag.setDataId(i); etag.setDate(locationProfile.getNextMythFillDatabase()); etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } start = end; end = end.plusHours(3); } else { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has NOT passed!"); } } Log.i(TAG, "downloadProgramGuide : interval=" + new Interval(startDownloading, new DateTime()).toString()); Log.v(TAG, "downloadProgramGuide : exit"); }
From source file:org.mythtv.service.guide.v27.ProgramGuideHelperV27.java
private static void downloadProgramGuide(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadProgramGuide : enter"); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ProgramHelperV27.getInstance().deletePrograms(context, locationProfile, ops, ProgramConstants.CONTENT_URI_GUIDE, ProgramConstants.TABLE_NAME_GUIDE); RecordingHelperV27.getInstance().deleteRecordings(context, locationProfile, ops, ContentDetails.GUIDE); DateTime startDownloading = new DateTime(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); int downloadDays = Integer.parseInt(sp.getString("preference_program_guide_days", "14")); Log.v(TAG, "downloadProgramGuide : downloadDays=" + downloadDays); DateTime start = new DateTime(DateTimeZone.getDefault()).withTimeAtStartOfDay(); DateTime end = start.plusHours(3);/*from ww w . j av a 2 s . co m*/ for (int i = 0; i < ((downloadDays * 24) / 3); i++) { Log.i(TAG, "downloadProgramGuide : starting download for [" + (i + 1) + " of " + ((downloadDays * 24) / 3) + "] " + DateUtils.getDateTimeUsingLocaleFormattingPretty(start, mMainApplication.getDateFormat(), mMainApplication.getClockType()) + ", end time=" + DateUtils.getDateTimeUsingLocaleFormattingPretty(end, mMainApplication.getDateFormat(), mMainApplication.getClockType())); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetProgramGuide", String.valueOf(i)); Log.d(TAG, "downloadProgramGuide : etag=" + etag.getValue()); if (null == etag.getDate() || start.isAfter(etag.getDate())) { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has passed"); ResponseEntity<ProgramGuide> responseEntity = mMythServicesTemplate.guideOperations() .getProgramGuide(start, end, 1, null, false, etag); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 200 OK"); ProgramGuide programGuide = responseEntity.getBody(); if (null != programGuide) { if (null != programGuide) { load(context, locationProfile, programGuide); } } if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setEndpoint("GetProgramGuide"); etag.setDataId(i); etag.setDate(locationProfile.getNextMythFillDatabase()); etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadProgramGuide : GetProgramGuide returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadProgramGuide : saving etag: " + etag.getValue()); etag.setLastModified(new DateTime(DateTimeZone.UTC)); mEtagDaoHelper.save(context, locationProfile, etag); } } start = end; end = end.plusHours(3); } else { Log.v(TAG, "downloadProgramGuide : next mythfilldatabase has NOT passed!"); } } Log.i(TAG, "downloadProgramGuide : interval=" + new Interval(startDownloading, new DateTime()).toString()); Log.v(TAG, "downloadProgramGuide : exit"); }
From source file:org.mythtv.android.db.dvr.RecordedHelperV27.java
private void downloadRecorded(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadRecorded : enter"); // EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId( context, locationProfile, "GetRecordedList", "" ); // Log.d( TAG, "downloadRecorded : etag=" + etag.getValue() ); ResponseEntity<ProgramList> responseEntity = mMythServicesTemplate.dvrOperations() .getRecordedList(Boolean.FALSE, null, null, null, null, null, ETagInfo.createEmptyETag()); DateTime date = new DateTime(DateTimeZone.UTC); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "download : GetRecordedList returned 200 OK"); ProgramList programList = responseEntity.getBody(); if (null != programList.getPrograms()) { load(context, locationProfile, programList.getPrograms()); // if( null != etag.getValue() ) { // Log.i( TAG, "download : saving etag: " + etag.getValue() ); ////from w w w . j av a 2 s. c o m // etag.setEndpoint( "GetRecordedList" ); // 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, "download : GetRecordedList returned 304 Not Modified"); // if( null != etag.getValue() ) { // Log.i( TAG, "download : saving etag: " + etag.getValue() ); // // etag.setLastModified( date ); // mEtagDaoHelper.save( context, locationProfile, etag ); // } } Log.v(TAG, "downloadRecorded : exit"); }
From source file:org.mythtv.service.dvr.v25.RecordingRuleHelperV25.java
private void downloadRecordinRules(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadRecordinRules : enter"); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetRecordScheduleList", ""); Log.d(TAG, "downloadRecordinRules : etag=" + etag.getValue()); ResponseEntity<org.mythtv.services.api.v025.beans.RecRuleList> responseEntity = mMythServicesTemplate .dvrOperations().getRecordScheduleList(null, null, etag); DateTime date = new DateTime(DateTimeZone.UTC); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadRecordinRules : GetRecordScheduleList returned 200 OK"); org.mythtv.services.api.v025.beans.RecRuleList recRuleList = responseEntity.getBody(); if (null != recRuleList.getRecRules()) { load(context, locationProfile, recRuleList.getRecRules()); if (null != etag.getValue()) { Log.i(TAG, "downloadRecordinRules : saving etag: " + etag.getValue()); etag.setEndpoint("GetRecordScheduleList"); etag.setDate(date);/*from ww w . j av a 2s . c om*/ etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(date); mEtagDaoHelper.save(context, locationProfile, etag); } } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadRecordinRules : GetRecordScheduleList returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadRecordinRules : saving etag: " + etag.getValue()); etag.setLastModified(date); mEtagDaoHelper.save(context, locationProfile, etag); } } Log.v(TAG, "downloadRecordinRules : exit"); }
From source file:org.mythtv.service.dvr.v26.RecordingRuleHelperV26.java
private void downloadRecordinRules(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadRecordinRules : enter"); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetRecordScheduleList", ""); Log.d(TAG, "downloadRecordinRules : etag=" + etag.getValue()); ResponseEntity<org.mythtv.services.api.v026.beans.RecRuleList> responseEntity = mMythServicesTemplate .dvrOperations().getRecordScheduleList(null, null, etag); DateTime date = new DateTime(DateTimeZone.UTC); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadRecordinRules : GetRecordScheduleList returned 200 OK"); org.mythtv.services.api.v026.beans.RecRuleList recRuleList = responseEntity.getBody(); if (null != recRuleList.getRecRules()) { load(context, locationProfile, recRuleList.getRecRules()); if (null != etag.getValue()) { Log.i(TAG, "downloadRecordinRules : saving etag: " + etag.getValue()); etag.setEndpoint("GetRecordScheduleList"); etag.setDate(date);// w ww .j a v a2 s. c o m etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(date); mEtagDaoHelper.save(context, locationProfile, etag); } } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadRecordinRules : GetRecordScheduleList returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadRecordinRules : saving etag: " + etag.getValue()); etag.setLastModified(date); mEtagDaoHelper.save(context, locationProfile, etag); } } Log.v(TAG, "downloadRecordinRules : exit"); }
From source file:com.appglu.impl.StorageTemplateTest.java
@Test public void streamStorageFileIfNoneMatch_notModified() { downloadMockServer.expect(requestTo(URL)).andExpect(header("If-None-Match", ETAG)) .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_MODIFIED)); StorageFile storageFile = new StorageFile(URL); storageFile.setETag(StringUtils.removeDoubleQuotes(ETAG)); boolean wasModified = this.storageOperations.streamStorageFileIfNoneMatch(storageFile, new InputStreamCallback() { public void doWithInputStream(InputStream inputStream) throws IOException { Assert.fail("Should not stream the file because it was not modified"); }/* ww w . j a v a2 s . c om*/ }); Assert.assertFalse(wasModified); downloadMockServer.verify(); }
From source file:org.mythtv.service.dvr.v27.RecordingRuleHelperV27.java
private void downloadRecordinRules(final Context context, final LocationProfile locationProfile) throws MythServiceApiRuntimeException, RemoteException, OperationApplicationException { Log.v(TAG, "downloadRecordinRules : enter"); EtagInfoDelegate etag = mEtagDaoHelper.findByEndpointAndDataId(context, locationProfile, "GetRecordScheduleList", ""); Log.d(TAG, "downloadRecordinRules : etag=" + etag.getValue()); ResponseEntity<org.mythtv.services.api.v027.beans.RecRuleList> responseEntity = mMythServicesTemplate .dvrOperations().getRecordScheduleList(null, null, etag); DateTime date = new DateTime(DateTimeZone.UTC); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Log.i(TAG, "downloadRecordinRules : GetRecordScheduleList returned 200 OK"); org.mythtv.services.api.v027.beans.RecRuleList recRuleList = responseEntity.getBody(); if (null != recRuleList.getRecRules()) { load(context, locationProfile, recRuleList.getRecRules()); if (null != etag.getValue()) { Log.i(TAG, "downloadRecordinRules : saving etag: " + etag.getValue()); etag.setEndpoint("GetRecordScheduleList"); etag.setDate(date);//from ww w . ja v a2 s . c o m etag.setMasterHostname(locationProfile.getHostname()); etag.setLastModified(date); mEtagDaoHelper.save(context, locationProfile, etag); } } } if (responseEntity.getStatusCode().equals(HttpStatus.NOT_MODIFIED)) { Log.i(TAG, "downloadRecordinRules : GetRecordScheduleList returned 304 Not Modified"); if (null != etag.getValue()) { Log.i(TAG, "downloadRecordinRules : saving etag: " + etag.getValue()); etag.setLastModified(date); mEtagDaoHelper.save(context, locationProfile, etag); } } Log.v(TAG, "downloadRecordinRules : exit"); }