Search in sources :

Example 61 with EntityTag

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());
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Date(java.util.Date) Test(org.junit.Test)

Example 62 with EntityTag

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);
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 63 with EntityTag

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();
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Date(java.util.Date)

Example 64 with EntityTag

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();
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 65 with EntityTag

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();
    }
}
Also used : EntityTag(javax.ws.rs.core.EntityTag) CacheControl(javax.ws.rs.core.CacheControl) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

EntityTag (javax.ws.rs.core.EntityTag)73 GET (javax.ws.rs.GET)24 Response (javax.ws.rs.core.Response)24 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)23 Path (javax.ws.rs.Path)21 CacheControl (javax.ws.rs.core.CacheControl)20 Test (org.junit.Test)18 Produces (javax.ws.rs.Produces)13 Date (java.util.Date)10 Test (org.testng.annotations.Test)9 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)8 Timestamp (com.yahoo.rdl.Timestamp)5 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)5 RESTPermitUnimplemented (fi.otavanopisto.muikku.rest.RESTPermitUnimplemented)5 List (java.util.List)5 ContainerResponse (org.everrest.core.impl.ContainerResponse)5 Principal (com.yahoo.athenz.auth.Principal)4 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)4 ArrayList (java.util.ArrayList)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4