當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheControl.valueOf方法代碼示例

本文整理匯總了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());
}
 
開發者ID:resteasy,項目名稱:resteasy-examples,代碼行數:26,代碼來源:CustomerResourceTest.java

示例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());
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:12,代碼來源:CacheServerDecoratorTest.java

示例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());
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:16,代碼來源:CacheServerDecoratorTest.java

示例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);
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:11,代碼來源:CacheServerDecoratorTest.java

示例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());
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:12,代碼來源:CacheServerDecoratorTest.java

示例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());
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:16,代碼來源:CacheServerDecoratorTest.java

示例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;
   }
 
開發者ID:AtomGraph,項目名稱:Processor,代碼行數:14,代碼來源:TemplateImpl.java

示例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());
			}

		}
	}
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:74,代碼來源:RestRequestCachingFilter.java


注:本文中的javax.ws.rs.core.CacheControl.valueOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。