public static void addCacheDirective(Response response, CacheDirective cacheDirective) { List<CacheDirective> cacheDirectives = response.getCacheDirectives(); if (cacheDirectives == null) { cacheDirectives = new ArrayList<CacheDirective>(); response.setCacheDirectives(cacheDirectives); } cacheDirectives.add(cacheDirective); } }
/** * Returns the response cache directives. Note that when used with HTTP * connectors, this property maps to the "Cache-Control" header. * * @return The cache directives. */ public List<CacheDirective> getResponseCacheDirectives() { return getResponse() == null ? null : getResponse() .getCacheDirectives(); }
@Get public Representation represent() { // Modification date (Fri, 17 Apr 2012 10:10:10 GMT) unchanged. Calendar cal = new GregorianCalendar(2012, 4, 17, 10, 10, 10); Representation result = new StringRepresentation("<a href=" + getReference() + ">" + System.currentTimeMillis() + "</a>"); result.setMediaType(MediaType.TEXT_HTML); result.setModificationDate(cal.getTime()); // Expiration date (Fri, 17 Apr 2012 13:10:10 GMT) unchanged. cal.roll(Calendar.HOUR, 3); result.setExpirationDate(cal.getTime()); // Setting E-Tag result.setTag(new Tag("xyz123")); // Setting a cache directive getResponse().getCacheDirectives().add(CacheDirective.publicInfo()); return result; }
/** * GET request. Returns all configuration states under a particular layer, including default. */ @Get public Representation getStates() { try { String version = (String) getRequest().getAttributes().get("version"); if ( version == null ) { version = LayerConfiguration.DEFAULT_VERSION; } String layerId = (String) getRequest().getAttributes().get("layer"); String stateId = (String) getRequest().getAttributes().get("state"); JSONObject result = new JSONObject(); if ( stateId != null ) { result.put( "state", _service.getLayerState( layerId, stateId ) ); } else { result.put( "states", _service.getLayerStates( layerId ) ); } result.put( "version", version ); setStatus( Status.SUCCESS_OK ); getResponse().getCacheDirectives().add( CacheDirective.noCache() ); return new JsonRepresentation( result ); } catch ( Exception e ) { LOGGER.warn("Bad layer states request: ", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Unable to recognize layer id", e); } }
getResponse().getCacheDirectives().add( CacheDirective.noCache() ); return new JsonRepresentation( result );
WarningReader.addValues(header, response.getWarnings()); } else if (HEADER_CACHE_CONTROL.equalsIgnoreCase(header.getName())) { CacheDirectiveReader.addValues(header, response.getCacheDirectives()); } else if (HEADER_ACCEPT_RANGES.equalsIgnoreCase(header.getName())) { TokenReader tr = new TokenReader(header.getValue());