本文整理汇总了Java中javax.ws.rs.core.CacheControl类的典型用法代码示例。如果您正苦于以下问题:Java CacheControl类的具体用法?Java CacheControl怎么用?Java CacheControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheControl类属于javax.ws.rs.core包,在下文中一共展示了CacheControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cacheAwareResponse
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
private Response cacheAwareResponse(
Request request, String entity, EntityTag etag, Date lastModified, int maxAge
) {
final Response.ResponseBuilder builderLastMod = request.evaluatePreconditions(lastModified);
if (builderLastMod != null) {
return builderLastMod.build();
}
final Response.ResponseBuilder builderEtag = request.evaluatePreconditions(etag);
if (builderEtag != null) {
return builderEtag.build();
}
final CacheControl cc = new CacheControl();
cc.setMaxAge(maxAge);
return Response.ok(entity)
.tag(etag)
.lastModified(lastModified)
.cacheControl(cc)
.build();
}
示例2: createHeaderDelegate
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> HeaderDelegate<T> createHeaderDelegate(final Class<T> type) {
if (type == MediaType.class) {
return (HeaderDelegate<T>) MEDIA_TYPE_DELEGATE;
}
if (type == Cookie.class) {
return (HeaderDelegate<T>) COOKIE_DELEGATE;
}
if (type == NewCookie.class) {
return (HeaderDelegate<T>) NEW_COOKIE_DELEGATE;
}
if (type == CacheControl.class) {
return (HeaderDelegate<T>) CACHE_CONTROL_DELEGATE;
}
throw new IllegalArgumentException("Unrecognized header delegate: " + type);
}
示例3: show
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@GET
@Path("{derivate}{path: (/[^?#]*)?}")
public Response show(@Context HttpServletRequest request, @Context Request jaxReq,
@Context ServletContext context, @Context ServletConfig config) 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();
}
示例4: testCustomerResource
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@Test
public void testCustomerResource() throws Exception
{
System.out.println("*** Create a new Customer ***");
Customer newCustomer = new Customer();
newCustomer.setFirstName("Bill");
newCustomer.setLastName("Burke");
newCustomer.setStreet("256 Clarendon Street");
newCustomer.setCity("Boston");
newCustomer.setState("MA");
newCustomer.setZip("02115");
newCustomer.setCountry("USA");
Response response = client.target("http://localhost:8080/services/customers")
.request().post(Entity.xml(newCustomer));
if (response.getStatus() != 201) throw new RuntimeException("Failed to create");
String location = response.getLocation().toString();
System.out.println("Location: " + location);
response.close();
System.out.println("*** GET Created Customer **");
response = client.target(location).request().get();
CacheControl cc = CacheControl.valueOf(response.getHeaderString(HttpHeaders.CACHE_CONTROL));
System.out.println("Max age: " + cc.getMaxAge());
}
示例5: DefaultSmartcommitsService
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@Autowired
public DefaultSmartcommitsService(@ComponentImport IssueManager issueManager,
@Qualifier ("smartcommitsTransitionsHandler") TransitionHandler transitionHandler,
@Qualifier ("smartcommitsCommentHandler") CommentHandler commentHandler,
@Qualifier ("smartcommitsWorklogHandler") WorkLogHandler workLogHandler,
@ComponentImport JiraAuthenticationContext jiraAuthenticationContext,
@ComponentImport CrowdService crowdService)
{
this.crowdService = checkNotNull(crowdService);
NO_CACHE = new CacheControl();
NO_CACHE.setNoCache(true);
this.issueManager = checkNotNull(issueManager);
this.transitionHandler = transitionHandler;
this.commentHandler = commentHandler;
this.workLogHandler = workLogHandler;
this.jiraAuthenticationContext = checkNotNull(jiraAuthenticationContext);
}
示例6: testGetNoStoreCacheControl_1
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
/**
* Run the CacheControl getNoStoreCacheControl() method test.
*
* @throws Exception
*
* @generatedBy CodePro at 12/16/14 4:40 PM
*/
@Test
public void testGetNoStoreCacheControl_1()
throws Exception {
CacheControl result = ResponseUtil.getNoStoreCacheControl();
assertNotNull(result);
assertEquals("private, no-cache, no-store, no-transform, max-age=0, s-maxage=0", result.toString());
assertEquals(true, result.isPrivate());
assertEquals(true, result.isNoTransform());
assertEquals(true, result.isNoCache());
assertEquals(true, result.isNoStore());
assertEquals(0, result.getSMaxAge());
assertEquals(false, result.isProxyRevalidate());
assertEquals(false, result.isMustRevalidate());
assertEquals(0, result.getMaxAge());
}
示例7: method
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@javax.ws.rs.GET public Response method() {
Response.ResponseBuilder responseBuilder = Response.ok();
responseBuilder.header("X-Test", "Hello");
responseBuilder.cacheControl(CacheControl.valueOf(""));
responseBuilder.contentLocation(URI.create(""));
responseBuilder.cookie();
responseBuilder.entity(12d);
responseBuilder.expires(new Date());
responseBuilder.language(Locale.ENGLISH);
responseBuilder.encoding("UTF-8");
responseBuilder.lastModified(new Date());
responseBuilder.link(URI.create(""), "rel");
responseBuilder.location(URI.create(""));
responseBuilder.status(433);
responseBuilder.tag(new EntityTag(""));
responseBuilder.type(MediaType.APPLICATION_JSON_TYPE);
responseBuilder.variants(new LinkedList<>());
return responseBuilder.build();
}
示例8: newResponseBuilder
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
final ResponseBuilder newResponseBuilder(final Status status, @Nullable final Object entity,
@Nullable final GenericType<?> type) {
Preconditions.checkState(this.context.variant != null);
final ResponseBuilder builder = Response.status(status);
if (entity != null) {
builder.entity(type == null ? entity : new GenericEntity<Object>(entity, type
.getType()));
builder.variant(this.context.variant);
final CacheControl cacheControl = new CacheControl();
cacheControl.setNoStore(true);
if ("GET".equalsIgnoreCase(this.request.getMethod())
|| "HEAD".equalsIgnoreCase(this.request.getMethod())) {
builder.lastModified(this.context.lastModified);
builder.tag(this.context.etag);
if (isCachingEnabled()) {
cacheControl.setNoStore(false);
cacheControl.setMaxAge(0); // always stale, must revalidate each time
cacheControl.setMustRevalidate(true);
cacheControl.setPrivate(getUsername() != null);
cacheControl.setNoTransform(true);
}
}
builder.cacheControl(cacheControl);
}
return builder;
}
示例9: retrieveSomeSamples
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@Override
public Response retrieveSomeSamples(final String ids) throws Exception {
Integer[] keys = Util.parseAsLongArray(ids);
List<SampleBean> data = new ArrayList<SampleBean>();
SampleBean one = null;
for (int i = 0; i < keys.length; i++)
{
one = new SampleBean(keys[i], 4, "test1", "test1");
data.add(one);
}
CacheControl cc = new CacheControl();
cc.setMaxAge(30000);
GenericEntity<List<SampleBean>> entity =
new GenericEntity<List<SampleBean>>(data) {
};
ResponseBuilder builder = Response.ok(entity);
builder.cacheControl(cc);
return builder.build();
}
示例10: getCacheControl
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
/**
* Get the {@link HttpHeaders#CACHE_CONTROL} header, if set.
*
* @return cache-control header or absent if cache-control header is not set
*/
public Optional<CacheControl> getCacheControl() {
if (_cacheControl == null) {
List<String> headerValues = _responseHeaders.get(CACHE_CONTROL);
_cacheControl = Optional.absent();
if (headerValues != null) {
try {
_cacheControl = Optional.of(CacheControl.valueOf(HttpHeaderUtils.join(headerValues)));
} catch (Exception ex) {
LOG.debug("Failed to parse cache-control header: value='{}'", headerValues, ex);
}
}
}
return _cacheControl;
}
示例11: build
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@Override
public Matcher<CacheControl> build() {
return new TypeSafeMatcher<CacheControl>() {
@Override
public void describeTo(Description description) {
description.appendText("is a CacheControl header ");
if(noCache != null) {
description.appendText("with " + (noCache?"no":"") + " cache");
}
}
@Override
protected boolean matchesSafely(CacheControl item) {
if(noCache != null) {
if(item.isNoCache() != noCache) {
return false;
}
}
return true;
}
};
}
示例12: index
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
/**
* Show a photo.
* @param num ID of the user
* @return PNG
* @throws IOException If fails
*/
@GET
@Path("/{id : \\d+}.png")
@Produces("image/png")
public Response index(@PathParam("id") final String num)
throws IOException {
final URN urn = URN.create(String.format("urn:aintshy:%s", num));
final byte[] png = this.base().human(urn).profile().photo();
if (png == null) {
throw new WebApplicationException(
Response.seeOther(
URI.create("http://img.aintshy.com/no-photo.png")
).build()
);
}
final CacheControl cache = new CacheControl();
cache.setMaxAge((int) TimeUnit.HOURS.toSeconds(1L));
cache.setPrivate(false);
return Response.ok(new ByteArrayInputStream(png))
.cacheControl(cache)
.type("image/png")
.build();
}
示例13: createCacheControl
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
/**
* Converts a {@code Cache-Control} annotation to a {@code Cache-Control}
* Jersey API object.
*
* @param annotation the annotation
*
* @return the Jersey API object
*
* @see javax.ws.rs.core.CacheControl
* @see com.github.autermann.jersey.cache.CacheControl
*/
private CacheControl createCacheControl(
com.github.autermann.jersey.cache.CacheControl annotation) {
CacheControl cacheControl = new CacheControl();
cacheControl.setPrivate(annotation._private() ||
annotation.privateFields().length > 0);
cacheControl.getPrivateFields()
.addAll(Arrays.asList(annotation.privateFields()));
cacheControl.setMustRevalidate(annotation.mustRevalidate());
cacheControl.setNoCache(annotation.noCache() ||
annotation.noCacheFields().length > 0);
cacheControl.getNoCacheFields()
.addAll(Arrays.asList(annotation.noCacheFields()));
cacheControl.setNoStore(annotation.noStore());
cacheControl.setNoTransform(annotation.noTransform());
cacheControl.setProxyRevalidate(annotation.proxyRevalidate());
cacheControl.setMaxAge(annotation.maxAge());
cacheControl.setSMaxAge(annotation.sMaxAge());
for (CacheControlExtension e : annotation.extensions()) {
cacheControl.getCacheExtension().put(e.key(), e.value());
}
return cacheControl;
}
示例14: getImage
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@GET
public Response getImage(@PathParam("vreName") String vreName) {
return transactionEnforcer.executeAndReturn(timbuctooActions -> {
final Vre vre = timbuctooActions.getVre(vreName);
if (vre == null) {
return TransactionStateAndResult.commitAndReturn(Response.status(Response.Status.NOT_FOUND).build());
}
final byte[] imageBlob = timbuctooActions.getVreImageBlob(vreName);
final MediaType mediaType = vre.getMetadata().getImageMediaType();
if (imageBlob != null && mediaType != null) {
final CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(604800);
cacheControl.setPrivate(false);
return TransactionStateAndResult.commitAndReturn(Response
.ok(imageBlob).type(mediaType).cacheControl(cacheControl).build());
} else {
return TransactionStateAndResult.commitAndReturn(Response.status(Response.Status.NOT_FOUND).build());
}
});
}
示例15: filter
import javax.ws.rs.core.CacheControl; //导入依赖的package包/类
@Override
public void filter(final ContainerRequestContext req, final ContainerResponseContext res) throws IOException {
if (req.getMethod().equals(GET)) {
final CacheControl cc = new CacheControl();
cc.setMaxAge(cacheAge);
res.getHeaders().add(CACHE_CONTROL, cc);
}
}