Java Code Examples for javax.ws.rs.core.CacheControl#setMustRevalidate()
The following examples show how to use
javax.ws.rs.core.CacheControl#setMustRevalidate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCRViewerResource.java From mycore with GNU General Public License v3.0 | 6 votes |
private Response showViewer(HttpServletRequest request, Request jaxReq) throws Exception { MCRContent content = getContent(request); String contentETag = content.getETag(); Response.ResponseBuilder responseBuilder = null; EntityTag eTag = contentETag == null ? null : new EntityTag(contentETag); if (eTag != null) { responseBuilder = jaxReq.evaluatePreconditions(eTag); } if (responseBuilder == null) { responseBuilder = Response.ok(content.asByteArray(), MediaType.valueOf(content.getMimeType())); } if (eTag != null) { responseBuilder.tag(eTag); } if (content.isUsingSession()) { CacheControl cc = new CacheControl(); cc.setPrivate(true); cc.setMaxAge(0); cc.setMustRevalidate(true); responseBuilder.cacheControl(cc); } return responseBuilder.build(); }
Example 2
Source File: CacheControlBuilder.java From everrest with Eclipse Public License 2.0 | 6 votes |
public CacheControl build() { CacheControl cacheControl = new CacheControl(); cacheControl.setMustRevalidate(mustRevalidate); cacheControl.setProxyRevalidate(proxyRevalidate); cacheControl.setMaxAge(maxAge); cacheControl.setSMaxAge(sMaxAge); cacheControl.setNoCache(noCache); cacheControl.setPrivate(privateFlag); cacheControl.setNoTransform(noTransform); cacheControl.setNoStore(noStore); if (privateFields != null) { cacheControl.getPrivateFields().addAll(privateFields); } if (noCacheFields != null) { cacheControl.getNoCacheFields().addAll(noCacheFields); } if (cacheExtension != null) { cacheControl.getCacheExtension().putAll(cacheExtension); } return cacheControl; }
Example 3
Source File: SearchResource.java From org.openntf.domino with Apache License 2.0 | 6 votes |
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) { String etagSource = DominoUtils.md5(jsonEntity); EntityTag etag = new EntityTag(etagSource); ResponseBuilder berg = null; if (request != null) { berg = request.evaluatePreconditions(etag); } if (berg == null) { berg = Response.ok(); if (includeEtag) { berg.tag(etag); } berg.type(MediaType.APPLICATION_JSON_TYPE); berg.entity(jsonEntity); berg.lastModified(lastMod); CacheControl cc = new CacheControl(); cc.setMustRevalidate(true); cc.setPrivate(true); cc.setMaxAge(86400); cc.setNoTransform(true); berg.cacheControl(cc); } return berg; }
Example 4
Source File: TermsResource.java From org.openntf.domino with Apache License 2.0 | 6 votes |
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) { String etagSource = DominoUtils.md5(jsonEntity); EntityTag etag = new EntityTag(etagSource); ResponseBuilder berg = null; if (request != null) { berg = request.evaluatePreconditions(etag); } if (berg == null) { berg = Response.ok(); if (includeEtag) { berg.tag(etag); } berg.type(MediaType.APPLICATION_JSON_TYPE); berg.entity(jsonEntity); berg.lastModified(lastMod); CacheControl cc = new CacheControl(); cc.setMustRevalidate(true); cc.setPrivate(true); cc.setMaxAge(86400); cc.setNoTransform(true); berg.cacheControl(cc); } return berg; }
Example 5
Source File: FramedResource.java From org.openntf.domino with Apache License 2.0 | 6 votes |
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) { String etagSource = DominoUtils.md5(jsonEntity); EntityTag etag = new EntityTag(etagSource); ResponseBuilder berg = null; if (request != null) { berg = request.evaluatePreconditions(etag); } if (berg == null) { // System.out.println("TEMP DEBUG creating a new builder"); berg = Response.ok(); if (includeEtag) { berg.tag(etag); } berg.type(MediaType.APPLICATION_JSON_TYPE); berg.entity(jsonEntity); berg.lastModified(lastMod); CacheControl cc = new CacheControl(); cc.setMustRevalidate(true); cc.setPrivate(true); cc.setMaxAge(86400); cc.setNoTransform(true); berg.cacheControl(cc); } return berg; }
Example 6
Source File: AdminStaticResourceController.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
@Path("/{s:.+}") @GET @Consumes public Response get(@Context UriInfo uriInfo, @Context Request request) throws IOException { String path = uriInfo.getPath(); Optional<ConsoleBundle> consoleBundleOptional = console.findByScriptFile(path); Resource resource; if (consoleBundleOptional.isPresent()) { ConsoleBundle consoleBundle = consoleBundleOptional.get(); resource = new CombinedResource(path, resourcePaths(consoleBundle), webRoot); } else { Optional<Resource> optional = webRoot.get(path); if (!optional.isPresent()) { throw new NotFoundException(String.format("missing resource, path=%s", path)); } resource = optional.get(); } EntityTag eTag = new EntityTag(resource.hash()); Response.ResponseBuilder builder = request.evaluatePreconditions(eTag); if (builder != null) { return builder.build(); } builder = Response.ok(resource).type(MediaTypes.getMediaType(Files.getFileExtension(path))); builder.tag(eTag); CacheControl cacheControl = new CacheControl(); cacheControl.setMustRevalidate(true); builder.cacheControl(cacheControl); return builder.build(); }
Example 7
Source File: CacheControlFilter.java From trellis with Apache License 2.0 | 5 votes |
@Override public void filter(final ContainerRequestContext req, final ContainerResponseContext res) { if ((GET.equals(req.getMethod()) || HEAD.equals(req.getMethod())) && SUCCESSFUL.equals(res.getStatusInfo().getFamily()) && maxAge > 0) { final CacheControl cc = new CacheControl(); cc.setMaxAge(maxAge); cc.setMustRevalidate(mustRevalidate); cc.setNoCache(noCache); res.getHeaders().add(CACHE_CONTROL, cc); } }
Example 8
Source File: MCRCacheFilter.java From mycore with GNU General Public License v3.0 | 5 votes |
private CacheControl getCacheConrol(MCRCacheControl cacheControlAnnotation) { CacheControl cc = new CacheControl(); if (cacheControlAnnotation != null) { cc.setMaxAge( (int) cacheControlAnnotation.maxAge().unit().toSeconds(cacheControlAnnotation.maxAge().time())); cc.setSMaxAge( (int) cacheControlAnnotation.sMaxAge().unit().toSeconds(cacheControlAnnotation.sMaxAge().time())); Optional.ofNullable(cacheControlAnnotation.private_()) .filter(MCRCacheControl.FieldArgument::active) .map(MCRCacheControl.FieldArgument::fields) .map(Stream::of) .ifPresent(s -> { cc.setPrivate(true); cc.getPrivateFields().addAll(s.collect(Collectors.toList())); }); if (cacheControlAnnotation.public_()) { cc.getCacheExtension().put("public", null); } cc.setNoTransform(cacheControlAnnotation.noTransform()); cc.setNoStore(cacheControlAnnotation.noStore()); Optional.ofNullable(cacheControlAnnotation.noCache()) .filter(MCRCacheControl.FieldArgument::active) .map(MCRCacheControl.FieldArgument::fields) .map(Stream::of) .ifPresent(s -> { cc.setNoCache(true); cc.getNoCacheFields().addAll(s.collect(Collectors.toList())); }); cc.setMustRevalidate(cacheControlAnnotation.mustRevalidate()); cc.setProxyRevalidate(cacheControlAnnotation.proxyRevalidate()); } else { cc.setNoTransform(false); //should have been default } return cc; }
Example 9
Source File: CacheControlUtil.java From keycloak with Apache License 2.0 | 5 votes |
public static CacheControl noCache() { CacheControl cacheControl = new CacheControl(); cacheControl.setMustRevalidate(true); cacheControl.setNoCache(true); cacheControl.setNoStore(true); return cacheControl; }
Example 10
Source File: FramedCollectionResource.java From org.openntf.domino with Apache License 2.0 | 5 votes |
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) { String etagSource = DominoUtils.md5(jsonEntity); EntityTag etag = new EntityTag(etagSource); ResponseBuilder berg = null; if (request != null) { berg = request.evaluatePreconditions(etag); } if (berg == null) { berg = Response.ok(); if (includeEtag) { berg.tag(etag); } berg.type(MediaType.APPLICATION_JSON_TYPE).entity(jsonEntity); berg.lastModified(lastMod); CacheControl cc = new CacheControl(); cc.setMustRevalidate(true); cc.setPrivate(true); cc.setMaxAge(86400); cc.setNoTransform(true); berg.cacheControl(cc); } else { // System.out.println("TEMP DEBUG got a hit for etag " + // etagSource); } return berg; }
Example 11
Source File: ReferenceResource.java From org.openntf.domino with Apache License 2.0 | 5 votes |
private ResponseBuilder getBuilder(String jsonEntity, Date lastMod, boolean includeEtag, Request request) { String etagSource = DominoUtils.md5(jsonEntity); EntityTag etag = new EntityTag(etagSource); ResponseBuilder berg = null; if (request != null) { berg = request.evaluatePreconditions(etag); } if (berg == null) { // System.out.println("TEMP DEBUG creating a new builder"); berg = Response.ok(); if (includeEtag) { berg.tag(etag); } berg.type(MediaType.APPLICATION_JSON_TYPE); berg.entity(jsonEntity); if (lastMod != null) { berg.lastModified(lastMod); } CacheControl cc = new CacheControl(); cc.setMustRevalidate(true); cc.setPrivate(true); cc.setMaxAge(86400); cc.setNoTransform(true); berg.cacheControl(cc); } return berg; }
Example 12
Source File: CacheControlHeaderProvider.java From cxf with Apache License 2.0 | 4 votes |
public CacheControl fromString(String c) { boolean isPrivate = false; List<String> privateFields = new ArrayList<>(); boolean noCache = false; List<String> noCacheFields = new ArrayList<>(); boolean noStore = false; boolean noTransform = false; boolean mustRevalidate = false; boolean proxyRevalidate = false; int maxAge = -1; int sMaxAge = -1; Map<String, String> extensions = new HashMap<>(); String[] tokens = getTokens(c); for (String rawToken : tokens) { String token = rawToken.trim(); if (token.startsWith(MAX_AGE)) { maxAge = Integer.parseInt(token.substring(MAX_AGE.length() + 1)); } else if (token.startsWith(SMAX_AGE)) { sMaxAge = Integer.parseInt(token.substring(SMAX_AGE.length() + 1)); } else if (token.startsWith(PUBLIC)) { // ignore } else if (token.startsWith(NO_STORE)) { noStore = true; } else if (token.startsWith(NO_TRANSFORM)) { noTransform = true; } else if (token.startsWith(MUST_REVALIDATE)) { mustRevalidate = true; } else if (token.startsWith(PROXY_REVALIDATE)) { proxyRevalidate = true; } else if (token.startsWith(PRIVATE)) { isPrivate = true; addFields(privateFields, token); } else if (token.startsWith(NO_CACHE)) { noCache = true; addFields(noCacheFields, token); } else { String[] extPair = token.split("="); String value = extPair.length == 2 ? extPair[1] : ""; extensions.put(extPair[0], value); } } CacheControl cc = new CacheControl(); cc.setMaxAge(maxAge); cc.setSMaxAge(sMaxAge); cc.setPrivate(isPrivate); cc.getPrivateFields().addAll(privateFields); cc.setMustRevalidate(mustRevalidate); cc.setProxyRevalidate(proxyRevalidate); cc.setNoCache(noCache); cc.getNoCacheFields().addAll(noCacheFields); cc.setNoStore(noStore); cc.setNoTransform(noTransform); cc.getCacheExtension().putAll(extensions); return cc; }