@Test public void whenNotExplicitlyRestfulEntityUseDefaultEtagAndLastModified() { CacheableOrder cacheable = new CacheableOrder(); Calendar date = Calendar.getInstance(); when(defaults.getLastModifiedFor(cacheable)).thenReturn(date); when(defaults.getEtagFor(cacheable)).thenReturn("custom etag"); handler.handle(cacheable); verify(response).addHeader("ETag", "custom etag"); verify(response).setDateHeader("Last-modified", date.getTimeInMillis()); }
public void handle(HypermediaResource resource) { if(Cacheable.class.isAssignableFrom(resource.getClass())) { Cacheable cache = (Cacheable) resource; response.addHeader("Cache-control","max-age=" + cache.getMaximumAge()); } if(RestfulEntity.class.isInstance(resource)) { RestfulEntity entity = (RestfulEntity) resource; restfulHeadersFor(entity.getEtag(), entity.getLastModified()); } else { restfulHeadersFor(defaults.getEtagFor(resource), defaults.getLastModifiedFor(resource)); } }
DefaultRestHeadersHandler implements RestHeadersHandler { public void handle(HypermediaResource resource) { if(Cacheable.class.isAssignableFrom(resource.getClass())) { Cacheable cache = (Cacheable) resource; response.addHeader("Cache-control","max-age=" + cache.getMaximumAge()); } if(RestfulEntity.class.isInstance(resource)) { RestfulEntity entity = (RestfulEntity) resource; restfulHeadersFor(entity.getEtag(), entity.getLastModified()); } else { restfulHeadersFor(defaults.getEtagFor(resource), defaults.getLastModifiedFor(resource)); } } }
DefaultRestHeadersHandler implements RestHeadersHandler { public void handle(HypermediaResource resource) { if(Cacheable.class.isAssignableFrom(resource.getClass())) { Cacheable cache = (Cacheable) resource; response.addHeader("Cache-control","max-age=" + cache.getMaximumAge()); } if(RestfulEntity.class.isInstance(resource)) { RestfulEntity entity = (RestfulEntity) resource; restfulHeadersFor(entity.getEtag(), entity.getLastModified()); } else { restfulHeadersFor(defaults.getEtagFor(resource), defaults.getLastModifiedFor(resource)); } } DefaultRestHeadersHandler(HttpServletResponse response, RestDefaults defaults); }
DefaultRestHeadersHandler implements RestHeadersHandler { public void handle(HypermediaResource resource) { if(Cacheable.class.isAssignableFrom(resource.getClass())) { Cacheable cache = (Cacheable) resource; response.addHeader("Cache-control","max-age=" + cache.getMaximumAge()); } if(RestfulEntity.class.isInstance(resource)) { RestfulEntity entity = (RestfulEntity) resource; restfulHeadersFor(entity.getEtag(), entity.getLastModified()); } else { restfulHeadersFor(defaults.getEtagFor(resource), defaults.getLastModifiedFor(resource)); } } DefaultRestHeadersHandler(HttpServletResponse response, RestDefaults defaults); void handle(HypermediaResource resource); }
DefaultRestHeadersHandler implements RestHeadersHandler { public void handle(HypermediaResource resource) { if(Cacheable.class.isAssignableFrom(resource.getClass())) { Cacheable cache = (Cacheable) resource; response.addHeader("Cache-control","max-age=" + cache.getMaximumAge()); } if(RestfulEntity.class.isInstance(resource)) { RestfulEntity entity = (RestfulEntity) resource; restfulHeadersFor(entity.getEtag(), entity.getLastModified()); } else { restfulHeadersFor(defaults.getEtagFor(resource), defaults.getLastModifiedFor(resource)); } } DefaultRestHeadersHandler(HttpServletResponse response, RestDefaults defaults); void handle(HypermediaResource resource);  }