Java Code Examples for javax.ws.rs.core.CacheControl#setNoTransform()

The following examples show how to use javax.ws.rs.core.CacheControl#setNoTransform() . 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: BinaryResourceDownloadResponseBuilder.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Apply cache policy to a response.
 *
 * @param response     The response builder.
 * @param eTag         The ETag of the resource.
 * @param lastModified The last modified date of the resource.
 * @param isToBeCached     Boolean to set whether we should define maxage of cache control
 * @return The response builder with the cache policy.
 */
private static Response.ResponseBuilder applyCachePolicyToResponse(Response.ResponseBuilder response, EntityTag eTag, Date lastModified, boolean isToBeCached) {

    if (isToBeCached) {
        CacheControl cc = new CacheControl();
        cc.setMaxAge(CACHE_SECOND);
        cc.setNoTransform(false);
        cc.setPrivate(false);

        Calendar expirationDate = Calendar.getInstance();
        expirationDate.add(Calendar.SECOND, CACHE_SECOND);
        response.cacheControl(cc)
                .expires(expirationDate.getTime());

    }

    return response.lastModified(lastModified)
            .tag(eTag);
}
 
Example 2
Source File: CacheControlBuilder.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
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 vote down vote up
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 vote down vote up
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 vote down vote up
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: MCRCacheFilter.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: CacheControlUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static CacheControl getDefaultCacheControl() {
    CacheControl cacheControl = new CacheControl();
    cacheControl.setNoTransform(false);
    Integer maxAge = Config.scope("theme").getInt("staticMaxAge", 2592000);
    if (maxAge != null && maxAge > 0) {
        cacheControl.setMaxAge(maxAge);
    } else {
        cacheControl.setNoCache(true);
    }
    return cacheControl;
}
 
Example 8
Source File: FramedCollectionResource.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
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 9
Source File: ReferenceResource.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
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 10
Source File: CacheControlHeaderProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
}