Examples of EntityTag


Examples of javax.ws.rs.core.EntityTag

    @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()));
        return Response.ok().tag(etag).entity(entity).build();
    }
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

      // NOT be weak.

      if (ifMatch == null)
         return null;

      EntityTag otherEtag = EntityTag.valueOf(ifMatch);

      // TODO check is status 412 valid if one of tag is weak
      if ((etag.isWeak() || otherEtag.isWeak()) // one of tag is weak
         || (!"*".equals(otherEtag.getValue()) && !etag.getValue().equals(otherEtag.getValue())))
         return Response.status(Response.Status.PRECONDITION_FAILED);

      // if tags are not matched then do as tag 'if-match' is absent
      return null;

View Full Code Here

Examples of javax.ws.rs.core.EntityTag

      String ifNoneMatch = getRequestHeaders().getFirst(IF_NONE_MATCH);

      if (ifNoneMatch == null)
         return null;

      EntityTag otherEtag = EntityTag.valueOf(ifNoneMatch);
      String httpMethod = getMethod();
      // The weak comparison function can only be used with GET or HEAD requests.
      if (httpMethod.equals(HttpMethod.GET) || httpMethod.equals(HttpMethod.HEAD))
      {

         if ("*".equals(otherEtag.getValue()) || etag.getValue().equals(otherEtag.getValue()))
            return Response.notModified(etag);

      }
      else
      {
         // Use strong comparison (ignore weak tags) because HTTP method is not GET
         // or HEAD. If one of tag is weak then tags are not identical.
         if (!etag.isWeak() && !otherEtag.isWeak()
            && ("*".equals(otherEtag.getValue()) || etag.getValue().equals(otherEtag.getValue())))
            return Response.status(Response.Status.PRECONDITION_FAILED);

      }

      // if tags are matched then do as tag 'if-none-match' is absent
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

    @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()));
        return Response.ok().tag(etag).entity(entity).build();
    }
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

        try {
            for (String value : ifMatch) {
                if ("*".equals(value)) {
                    return null;
                }
                EntityTag requestTag = EntityTag.valueOf(value);
                // must be a strong comparison
                if (!requestTag.isWeak() && !eTag.isWeak() && requestTag.equals(eTag)) {
                    return null;
                }
            }
        } catch (IllegalArgumentException ex) {
            // ignore
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

        boolean getOrHead = HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method);
        try {
            for (String value : ifNonMatch) {
                boolean result = "*".equals(value);
                if (!result) {
                    EntityTag requestTag = EntityTag.valueOf(value);
                    result = getOrHead ? requestTag.equals(eTag)
                        : !requestTag.isWeak() && !eTag.isWeak() && requestTag.equals(eTag);
                }
                if (result) {
                    Response.Status status = getOrHead ? Response.Status.NOT_MODIFIED
                        : Response.Status.PRECONDITION_FAILED;
                    return Response.status(status).tag(eTag);
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

        assertEquals("\"foo\"", eTag);
    }
   
    @Test
    public void testEntityTag() {
        Response r = Response.ok().tag(new EntityTag("foo")).build();
        String eTag = r.getMetadata().getFirst("ETag").toString();
        assertEquals("\"foo\"", eTag);
    }
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

        assertEquals("\"foo\"", eTag);
    }
   
    @Test
    public void testEntityTag2() {
        Response r = Response.ok().tag(new EntityTag("\"foo\"")).build();
        String eTag = r.getMetadata().getFirst("ETag").toString();
        assertEquals("\"foo\"", eTag);
    }
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

    private EntityTag tag;
    private Date modified;

    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
View Full Code Here

Examples of javax.ws.rs.core.EntityTag

        assertSame(var, new RequestImpl(m).selectVariant(list));   
    }
   
    @Test
    public void testWeakEtags() {
        metadata.putSingle("If-Match", new EntityTag("123", true).toString());
       
        ResponseBuilder rb =
            new RequestImpl(m).evaluatePreconditions(new EntityTag("123"));
        assertNotNull("Strict compararison is required", rb);
        Response r = rb.build();
        assertEquals("If-Match precondition was not met", 412, r.getStatus());
        assertEquals("Response should include ETag",
                     "\"123\"", r.getMetadata().getFirst("ETag"));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.