本文整理汇总了Java中javax.ws.rs.core.CacheControl.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java CacheControl.valueOf方法的具体用法?Java CacheControl.valueOf怎么用?Java CacheControl.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.CacheControl
的用法示例。
在下文中一共展示了CacheControl.valueOf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
示例2: testEntityTagSupport
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Test
public void testEntityTagSupport() {
final Response response = createWebTarget().path("name").path("etag").request(MediaType.TEXT_PLAIN).get();
CacheControl cacheControl = CacheControl.valueOf(response.getHeaderString(HttpHeaders.CACHE_CONTROL));
assertEquals(600, cacheControl.getMaxAge());
assertTrue(cacheControl.isNoTransform());
assertFalse(cacheControl.isMustRevalidate());
final EntityTag entityTag = response.getEntityTag();
assertNotNull(entityTag);
assertEquals("12345", entityTag.getValue());
}
示例3: testLastUpdatedAndEtagSupport
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Test
public void testLastUpdatedAndEtagSupport() {
final Response response = createWebTarget().path("name").path("lastModifiedAndEtag").request(MediaType.TEXT_PLAIN).get();
CacheControl cacheControl = CacheControl.valueOf(response.getHeaderString(HttpHeaders.CACHE_CONTROL));
assertEquals(600, cacheControl.getMaxAge());
assertTrue(cacheControl.isNoTransform());
assertFalse(cacheControl.isMustRevalidate());
Date lastModified = response.getLastModified();
assertEquals(CacheResource.LAST_MODIFIED, lastModified);
final EntityTag entityTag = response.getEntityTag();
assertNotNull(entityTag);
assertEquals("12345", entityTag.getValue());
}
示例4: testLastUpdatedSupport
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Test
public void testLastUpdatedSupport() {
final Response response = createWebTarget().path("name").path("lastModified").request(MediaType.TEXT_PLAIN).get();
CacheControl cacheControl = CacheControl.valueOf(response.getHeaderString(HttpHeaders.CACHE_CONTROL));
assertEquals(600, cacheControl.getMaxAge());
assertTrue(cacheControl.isNoTransform());
assertFalse(cacheControl.isMustRevalidate());
Date lastModified = response.getLastModified();
assertEquals(CacheResource.LAST_MODIFIED, lastModified);
}
示例5: testWithNoState
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Test
public void testWithNoState() {
final Response response = createWebTarget().path("name").path("noState").request(MediaType.TEXT_PLAIN).get();
CacheControl cacheControl = CacheControl.valueOf(response.getHeaderString(HttpHeaders.CACHE_CONTROL));
assertEquals(600, cacheControl.getMaxAge());
assertTrue(cacheControl.isNoTransform());
assertFalse(cacheControl.isMustRevalidate());
assertNull(response.getLastModified());
assertNull(response.getEntityTag());
}
示例6: testWithResponse
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Test
public void testWithResponse() {
final Response response = createProxy().createResponse();
CacheControl cacheControl = CacheControl.valueOf(response.getHeaderString(HttpHeaders.CACHE_CONTROL));
assertEquals(600, cacheControl.getMaxAge());
assertTrue(cacheControl.isNoTransform());
assertFalse(cacheControl.isMustRevalidate());
Date lastModified = response.getLastModified();
assertEquals(CacheResource.LAST_MODIFIED, lastModified);
final EntityTag entityTag = response.getEntityTag();
assertNotNull(entityTag);
assertEquals("12345", entityTag.getValue());
}
示例7: getCacheControl
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
/**
* Returns <code>Cache-Control</code> HTTP header value, specified on an ontology class with given property.
*
* @return CacheControl instance or null
*/
@Override
public CacheControl getCacheControl()
{
if (hasProperty(LDT.cacheControl))
return CacheControl.valueOf(getPropertyValue(LDT.cacheControl).asLiteral().getString()); // will fail on bad config
return null;
}
示例8: filter
import javax.ws.rs.core.CacheControl; //导入方法依赖的package包/类
@Override
public void filter(final ClientRequestContext req,
final ClientResponseContext responseContext)
throws IOException {
if (req.getMethod().equals(HttpMethod.GET)) {
String cacheControl = responseContext.getHeaderString(HttpHeaders.CACHE_CONTROL);
EntityTag etag = responseContext.getEntityTag();
//If some caching headers exist in server response
if ((cacheControl != null && !cacheControl.isEmpty())
|| (etag != null && etag.getValue() != null))
{
CacheEntry entry = new CacheEntry();
boolean cacheControlEnable = false;
boolean etagEnable = false;
if ((cacheControl != null && !cacheControl.isEmpty()))
{
CacheControl control = CacheControl.valueOf(cacheControl);
if (logger.isDebugEnabled())
logger.debug("Cache-Control header::" + cacheControl);
if (!control.isNoCache() && control.getMaxAge() != -1)
{
if (logger.isDebugEnabled())
logger.debug("Max-age::" + control.getMaxAge());
cacheControlEnable = true;
entry.setMaxAge(new Long(control.getMaxAge()));
}
}
if (etag != null && etag.getValue() != null)
{
etagEnable = true;
if (logger.isDebugEnabled())
logger.debug("etag header::" + etag.getValue());
entry.setEtag(etag);
}
String path = req.getUri().getPath();
String query = req.getUri().getQuery();
if (query != null && !query.isEmpty())
path += query;
//Data is new, modified or expired
if ((cacheControlEnable
|| etagEnable) && responseContext.getStatus() == Status.OK.getStatusCode())
{
if (logger.isDebugEnabled())
logger.debug("Insert in cache with key::"
+ path
+ ". current object value is null, since will be inserted in RestCachingManagerImpl");
entry.setStatus(Status.OK.getStatusCode());
Element el = new Element(path, entry);
cache.put(el);
}
//If status is 304 (not modified) data is not returned by server
else if (etagEnable
&& responseContext.getStatus() == Status.NOT_MODIFIED.getStatusCode())
{
//update existing reference with cacheControl info and status
Element wrap = cache.get(path);
CacheEntry existingEntry = (CacheEntry) wrap.getObjectValue();
existingEntry.setStatus(responseContext.getStatus());
existingEntry.setExpiration(entry.getExpiration());
}
}
}
}