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

The following examples show how to use javax.ws.rs.core.CacheControl#valueOf() . 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: CustomerResourceTest.java    From resteasy-examples with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: TemplateImpl.java    From Processor with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: CacheControlHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromSimpleString() {
    CacheControl c = CacheControl.valueOf(
        "public,must-revalidate");
    assertFalse(c.isPrivate() && !c.isNoStore()
               && c.isMustRevalidate() && !c.isProxyRevalidate());
    assertFalse(c.isNoCache()
               && !c.isNoTransform() && c.getNoCacheFields().isEmpty()
               && c.getPrivateFields().isEmpty());
}
 
Example 4
Source File: CacheControlHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromComplexString() {
    CacheControl c = CacheControl.valueOf(
        "private=\"foo\",no-cache=\"bar\",no-store,no-transform,"
        + "must-revalidate,proxy-revalidate,max-age=2,s-maxage=3");
    assertTrue(c.isPrivate() && c.isNoStore()
               && c.isMustRevalidate() && c.isProxyRevalidate() && c.isNoCache());
    assertTrue(c.isNoTransform() && c.getNoCacheFields().size() == 1
               && c.getPrivateFields().size() == 1);
    assertEquals("foo", c.getPrivateFields().get(0));
    assertEquals("bar", c.getNoCacheFields().get(0));

}
 
Example 5
Source File: CacheControlHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadMultiplePrivateAndNoCacheFields() {
    String s = "private=\"foo1,foo2\",no-store,no-transform,"
        + "must-revalidate,proxy-revalidate,max-age=2,s-maxage=3,no-cache=\"bar1,bar2\","
        + "ext=1";
    CacheControl cc = CacheControl.valueOf(s);

    assertTrue(cc.isPrivate());
    List<String> privateFields = cc.getPrivateFields();
    assertEquals(2, privateFields.size());
    assertEquals("foo1", privateFields.get(0));
    assertEquals("foo2", privateFields.get(1));
    assertTrue(cc.isNoCache());
    List<String> noCacheFields = cc.getNoCacheFields();
    assertEquals(2, noCacheFields.size());
    assertEquals("bar1", noCacheFields.get(0));
    assertEquals("bar2", noCacheFields.get(1));

    assertTrue(cc.isNoStore());
    assertTrue(cc.isNoTransform());
    assertTrue(cc.isMustRevalidate());
    assertTrue(cc.isProxyRevalidate());
    assertEquals(2, cc.getMaxAge());
    assertEquals(3, cc.getSMaxAge());

    Map<String, String> exts = cc.getCacheExtension();
    assertEquals(1, exts.size());
    assertEquals("1", exts.get("ext"));
}
 
Example 6
Source File: CacheControlClientReaderInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean isCacheControlValid(final ReaderInterceptorContext context,
                                      final CacheControl responseControl) {

    boolean valid =
        responseControl != null && !responseControl.isNoCache() && !responseControl.isNoStore();
    if (valid) {
        String clientHeader =
            (String)context.getProperty(CacheControlClientRequestFilter.CLIENT_CACHE_CONTROL);
        CacheControl clientControl = clientHeader == null ? null : CacheControl.valueOf(clientHeader);
        if (clientControl != null && clientControl.isPrivate() != responseControl.isPrivate()) {
            valid = false;
        }
    }
    return valid;
}
 
Example 7
Source File: CacheControlHeaderProviderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testValueOfNull() {
    CacheControl.valueOf(null);
}