@Path("discrete") @GET public Response discrete( @DefaultValue("2") @QueryParam("width") final int width, @DefaultValue("50") @QueryParam("upper") final int upper, @DefaultValue("red") @QueryParam("upper-color") final ColorParam upperColor, @DefaultValue("gray") @QueryParam("lower-color") final ColorParam lowerColor ) { final BufferedImage image = new BufferedImage( data.size() * width - 1, imageHeight, BufferedImage.TYPE_INT_RGB); final Graphics2D g = image.createGraphics(); g.setBackground(Color.WHITE); g.clearRect(0, 0, image.getWidth(), image.getHeight()); final int gap = 4; final float d = (limits.width() + 1) / (float) (imageHeight - gap); for (int i = 0, x = 0, y; i < data.size(); i++, x += width) { final int v = data.get(i); g.setColor((v >= upper) ? upperColor : lowerColor); y = imageHeight - (int) ((v - limits.lower()) / d); g.drawRect(x, y - gap, width - 2, gap); } return Response.ok(image).tag(tag).build(); }
return Response.ok(image).tag(tag).build();
.tag(entityTag) .cacheControl(cacheControl) .lastModified(lastModified)
public ResponseBuilder evaluatePreconditions() { List<String> ifMatch = headers.getRequestHeader(HttpHeaders.IF_MATCH); if (ifMatch != null) { for (String value : ifMatch) { if (!"*".equals(value)) { return Response.status(Response.Status.PRECONDITION_FAILED).tag(EntityTag.valueOf(value)); } } } return null; }
/** * Create a new ResponseBuilder with a not-modified status. * * @param tag a tag for the unmodified entity. * @return a new response builder. * @throws java.lang.IllegalArgumentException * if tag is {@code null}. */ public static ResponseBuilder notModified(EntityTag tag) { return notModified().tag(tag); }
@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(); }
r = evaluateIfModifiedSince(lastModifiedTime, ifModifiedSinceHeader); if (r != null) { r.tag(eTag);
public Response.ResponseBuilder evaluatePreconditions(EntityTag eTag) { if (eTag == null) throw new IllegalArgumentException(MESSAGES.eTagParamNull()); Response.ResponseBuilder builder = null; List<String> ifMatch = headers.getRequestHeaders().get(IF_MATCH); if (ifMatch != null && ifMatch.size() > 0) { builder = ifMatch(convertEtag(ifMatch), eTag); } if (builder == null) { List<String> ifNoneMatch = headers.getRequestHeaders().get(IF_NONE_MATCH); if (ifNoneMatch != null && ifNoneMatch.size() > 0) { builder = ifNoneMatch(convertEtag(ifNoneMatch), eTag); } } if (builder != null) { builder.tag(eTag); } if (builder != null && varyHeader != null) builder.header(VARY, varyHeader); return builder; }
public Response.ResponseBuilder ifNoneMatch(List<EntityTag> ifMatch, EntityTag eTag) { boolean match = false; for (EntityTag tag : ifMatch) { if (tag.equals(eTag) || tag.getValue().equals("*")) { match = true; break; } } if (match) { if ("GET".equals(httpMethod) || "HEAD".equals(httpMethod)) { return Response.notModified(eTag); } return Response.status(SC_PRECONDITION_FAILED).tag(eTag); } return null; }
public Response.ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) { if (lastModified == null) throw new IllegalArgumentException(MESSAGES.lastModifiedParamNull()); if (eTag == null) throw new IllegalArgumentException(MESSAGES.eTagParamNull()); Response.ResponseBuilder rtn = null; Response.ResponseBuilder lastModifiedBuilder = evaluatePreconditions(lastModified); Response.ResponseBuilder etagBuilder = evaluatePreconditions(eTag); if (lastModifiedBuilder == null && etagBuilder == null) rtn = null; else if (lastModifiedBuilder != null && etagBuilder == null) rtn = lastModifiedBuilder; else if (lastModifiedBuilder == null && etagBuilder != null) rtn = etagBuilder; else { rtn = lastModifiedBuilder; rtn.tag(eTag); } if (rtn != null && varyHeader != null) rtn.header(VARY, varyHeader); return rtn; }
public Response.ResponseBuilder ifMatch(List<EntityTag> ifMatch, EntityTag eTag) { boolean match = false; for (EntityTag tag : ifMatch) { if (tag.equals(eTag) || tag.getValue().equals("*")) { match = true; break; } } if (match) return null; return Response.status(SC_PRECONDITION_FAILED).tag(eTag); }
public Response.ResponseBuilder responseBuilder() { final Response.ResponseBuilder builder = Response.status(status).cacheControl(cacheControl).tag(eTag).entity(build()).type(APPLICATION_XML); final List<Link> c = getCreated(); final List<Link> u = getUpdated(); if (c.size() == 1 && u.isEmpty()) { builder.location(c.get(0).getHref()); } else if (u.size() == 1 && c.isEmpty()) { builder.location(u.get(0).getHref()); } return builder; }
if ( builder == null ) builder = Response.ok(json).tag(tag);
r = evaluateIfModifiedSince(lastModifiedTime, ifModifiedSinceHeader); if (r != null) r.tag(eTag);
r = evaluateIfModifiedSince(lastModifiedTime, ifModifiedSinceHeader); if (r != null) { r.tag(eTag);
r = evaluateIfModifiedSince(lastModifiedTime, ifModifiedSinceHeader); if (r != null) { r.tag(eTag);
public static ResponseBuilder notModified(String tag) { ResponseBuilder b = notModified(); b.tag(tag); return b; }
public static ResponseBuilder notModified(EntityTag tag) { ResponseBuilder b = notModified(); b.tag(tag); return b; }