Package javax.ws.rs.core

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


    }

    // Check that e-tag is quoted-string
    if (!eTag.startsWith("\"") || !eTag.endsWith("\"")) {
      if ("*".equals(eTag)) {
        return new EntityTag("*");
      }
      throw new IllegalArgumentException("Entity Tag " + eTag + " is not quoted properly");
    }

    // Remove quotes
    eTag = eTag.substring(1, eTag.length() - 1);

    // Un-escape the e-tag
    StringBuilder builder = null;

    for (int i = 0; i < eTag.length(); i++) {

      if (eTag.charAt(i) == '\\' && i + 1 < eTag.length()) {

        // each '\' (which is not the last one) escapes the next
        // character
        if (builder == null) {
          builder = new StringBuilder(eTag.length());
          builder.append(eTag, 0, i);
        }
        // don't append the '\'

      } else {
        // append the character

        if (builder != null) {
          builder.append(eTag.charAt(i));
        }
      }
    }

    if (builder != null) {
      eTag = builder.toString();
    }

    return new EntityTag(eTag, weak);
  }
View Full Code Here

    @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

    @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

    @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

    @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

    @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

        if (header == null) {
            throw new IllegalArgumentException("ETag value can not be null");
        }
       
        if ("*".equals(header)) {
            return new EntityTag("*");
        }
       
        String tag = null;
        boolean weak =  false;
        int i = header.indexOf(WEAK_PREFIX);
        if (i != -1) {
            weak = true;
            if (i + 2 < header.length()) {
                tag = header.substring(i + 2);
            } else {
                return new EntityTag("", weak);
            }
        }  else {
            tag = header;
        }
        if (tag.length() < 2 || !tag.startsWith("\"") || !tag.endsWith("\"")) {
            throw new IllegalArgumentException("Misformatted ETag : " + header);
        }
        tag = tag.length() == 2 ? "" : tag.substring(1, tag.length() - 1);
        return new EntityTag(tag, weak);
    }
View Full Code Here

        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

        boolean getOrHead = "GET".equals(method) || "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

TOP

Related Classes of javax.ws.rs.core.EntityTag

Copyright © 2018 www.massapicom. 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.