本文整理匯總了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());
}
}
}
}