use of javax.ws.rs.core.EntityTag in project cxf by apache.
the class RequestImplTest method testIfNotMatchAndLastModified.
@Test
public void testIfNotMatchAndLastModified() {
metadata.putSingle(HttpHeaders.IF_NONE_MATCH, "1");
ResponseBuilder rb = new RequestImpl(m).evaluatePreconditions(new Date(), new EntityTag("1"));
assertEquals("Precondition must not be met", 304, rb.build().getStatus());
}
use of javax.ws.rs.core.EntityTag in project cxf by apache.
the class RequestImplTest method testIfNoneMatchAndDateWithNonMatchingTags.
@Test
public void testIfNoneMatchAndDateWithNonMatchingTags() throws Exception {
metadata.putSingle(HttpHeaders.IF_NONE_MATCH, "\"123\"");
metadata.putSingle("If-Modified-Since", "Tue, 20 Oct 2008 14:00:00 GMT");
Date lastModified = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH).parse("Mon, 21 Oct 2008 14:00:00 GMT");
ResponseBuilder rb = new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("124"));
assertNull("Dates must not be checked if tags do not match", rb);
}
use of javax.ws.rs.core.EntityTag in project cxf by apache.
the class SimpleService method perform.
public Response perform(final Request request) {
final Date lastModified = getLastModified();
final EntityTag entityTag = getEntityTag();
ResponseBuilder rb = request.evaluatePreconditions(lastModified, entityTag);
if (rb == null) {
rb = Response.ok();
} else {
// okay
}
return rb.build();
}
use of javax.ws.rs.core.EntityTag in project cxf by apache.
the class BookStore method getBookAsResponse.
@GET
@Path("/books/response/{bookId}/")
@Produces("application/xml")
public Response getBookAsResponse(@PathParam("bookId") String id) throws BookNotFoundFault {
Book entity = doGetBook(id);
EntityTag etag = new EntityTag(Integer.toString(entity.hashCode()));
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(100000);
cacheControl.setPrivate(true);
return Response.ok().tag(etag).entity(entity).cacheControl(cacheControl).build();
}
use of javax.ws.rs.core.EntityTag in project cxf by apache.
the class BookStore method getBookAsResponse3.
@GET
@Path("/books/response3/{bookId}/")
@Produces("application/xml")
public Response getBookAsResponse3(@PathParam("bookId") String id, @HeaderParam("If-Modified-Since") String modifiedSince) throws BookNotFoundFault {
Book entity = doGetBook(id);
EntityTag etag = new EntityTag(Integer.toString(entity.hashCode()));
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(1);
cacheControl.setPrivate(true);
if (modifiedSince != null) {
return Response.status(304).tag(etag).cacheControl(cacheControl).lastModified(new Date()).build();
} else {
return Response.ok().tag(etag).entity(entity).cacheControl(cacheControl).lastModified(new Date()).build();
}
}
Aggregations