Refine search
private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags, final boolean isGetOrHead) { if (isGetOrHead) { if (matchingTags == MatchingEntityTag.ANY_MATCH) { // 304 Not modified return Response.notModified(eTag); } // The weak comparison function may be used to compare entity tags if (matchingTags.contains(eTag) || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) { // 304 Not modified return Response.notModified(eTag); } } else { // The strong comparison function must be used to compare the entity // tags. Thus if the entity tag of the entity is weak then matching // of entity tags in the If-None-Match header should fail if the // HTTP method is not GET or not HEAD. if (eTag.isWeak()) { return null; } if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) { // 412 Precondition Failed return Response.status(Response.Status.PRECONDITION_FAILED); } } return null; }
@Override public EntityTag apply(String value) { return EntityTag.valueOf(value); } }, false);
String ifNoneMatch = httpHeaders.getHeaderString("If-None-Match"); Boolean etagCached = false; Response.ResponseBuilder builder = Response.noContent(); EntityTag etag = new EntityTag(ifNoneMatch.replaceAll("\"", "")); if (etagService.isPresent(etag.toString())) { etagCached = true; builder = Response.notModified(); builder.tag(etag); EntityTag collectorsEtag = new EntityTag(etagString); builder = Response.ok(collectorListResponse); builder.tag(collectorsEtag); etagService.put(collectorsEtag.toString()); cacheControl.setNoTransform(true); cacheControl.setPrivate(true); builder.cacheControl(cacheControl); return builder.build();
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 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); }
final Date lastModified = Date.from(lastModifiedTime.toInstant()); final HashCode hashCode = Hashing.sha256().hashBytes(fileContents); final EntityTag entityTag = new EntityTag(hashCode.toString()); return response.build(); .ok(fileContents, contentType) .tag(entityTag) .cacheControl(cacheControl) .lastModified(lastModified) .build();
private ResponseBuilder evaluateIfMatch(EntityTag eTag, Date date) { List<String> ifMatch = headers.getRequestHeader(HttpHeaders.IF_MATCH); if (ifMatch == null || ifMatch.isEmpty()) { return date == null ? null : evaluateIfNotModifiedSince(date); } 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 } return Response.status(Response.Status.PRECONDITION_FAILED).tag(eTag); }
private Response.ResponseBuilder evaluateIfMatch(final EntityTag eTag) { final Set<? extends EntityTag> matchingTags = getIfMatch(); if (matchingTags == null) { return null; } // The strong comparison function must be used to compare the entity // tags. Thus if the entity tag of the entity is weak then matching // of entity tags in the If-Match header should fail. if (eTag.isWeak()) { return Response.status(Response.Status.PRECONDITION_FAILED); } if (matchingTags != MatchingEntityTag.ANY_MATCH && !matchingTags.contains(eTag)) { // 412 Precondition Failed return Response.status(Response.Status.PRECONDITION_FAILED); } return null; }
private ResponseBuilder evaluateIfMatch(EntityTag eTag) { // if request ifMatch is not set, process the request if (ifMatch == null) { return null; } // if-match is not allowed with weak eTags if (eTag.isWeak()) { return Response.status(Response.Status.PRECONDITION_FAILED).tag(eTag); } // if the request ifMatch eTag matches the supplied eTag, process the request if ("*".equals(ifMatch.getValue()) || eTag.getValue().equals(ifMatch.getValue())) { return null; } return Response.status(Response.Status.PRECONDITION_FAILED).tag(eTag); }
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; }
childResource = res.getLocation().toString(); await().until(() -> !initialETag.equals(getETag(getContainerLocation()))); assertAll("Check for an LDP-BC", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE)); final IRI identifier = rdf.createIRI(getContainerLocation()); final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE); assertAll("Verify the resulting graph", checkRdfGraph(g, identifier)); assertTrue(g.contains(identifier, LDP.contains, rdf.createIRI(childResource)), "Check for the presence of an ldp:contains triple"); etag = res.getEntityTag(); assertTrue(etag.isWeak(), "Verify that the ETag is weak"); assertFalse(g.contains(rdf.createIRI(getContainerLocation()), LDP.contains, rdf.createIRI(childResource)), "Check the graph doesn't contain the deleted resource"); assertTrue(res.getEntityTag().isWeak(), "Check that the ETag is weak"); assertNotEquals(etag, res.getEntityTag(), "Verify that the ETag value is different");
@GET public Response get(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch, @HeaderParam(HttpHeaders.IF_MODIFIED_SINCE) Date ifModifiedSince) { // Check the ETags to see if the resource has changed... if (ifNoneMatch != null) { for (String eTag : ETAG_SPLITTER.split(ifNoneMatch)) { if ("*".equals(eTag) || ETAG.equals(EntityTag.valueOf(eTag))) { return NOT_MODIFIED; } } } // Check the last modification time if (ifModifiedSince != null && ifModifiedSince.after(LAST_MODIFIED)) { return NOT_MODIFIED; } return Response.ok().lastModified(LAST_MODIFIED).tag(ETAG).type(CONTENT_TYPE).entity(FAVICON).build(); } }
@Test public void testPutIfMatch() { final String etag = target(BINARY_PATH).request().get().getEntityTag().getValue(); final Response res = target(BINARY_PATH).request().header("If-Match", "\"" + etag + "\"") .put(entity("some different data.", TEXT_PLAIN_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); }
@Override public javax.ws.rs.core.Response.ResponseBuilder tag(String tag) { return tag(tag == null ? null : new EntityTag(tag)); }
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { response.getHttpHeaders().add(HttpHeaders.VARY, HttpHeaders.ACCEPT_ENCODING); // add vary header String acceptEncoding = request.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING); String contentEncoding = (String) response.getHttpHeaders().getFirst(HttpHeaders.CONTENT_ENCODING); if (acceptEncoding != null && contentEncoding == null && acceptEncoding.contains("gzip")) { // Check EntityTag header if (response.getHttpHeaders().containsKey(HttpHeaders.ETAG)) { EntityTag entityTag = (EntityTag) response.getHttpHeaders().getFirst(HttpHeaders.ETAG); if (entityTag != null) { response.getHttpHeaders().putSingle(HttpHeaders.ETAG, new EntityTag(entityTag.getValue() + ENTITY_TAG_GZIP_SUFFIX_VALUE, entityTag.isWeak())); } } // wrap entity with gzip if (response.getEntity() != null) { response.getHttpHeaders().add(HttpHeaders.CONTENT_ENCODING, "gzip"); response.setContainerResponseWriter(new Adapter(response.getContainerResponseWriter())); } } return response; } }
private ResponseBuilder evaluateIfMatch(EntityTag eTag) { Set<MatchingEntityTag> matchingTags = HttpHelper.getIfMatch(this); if (matchingTags == null) { return null; } // The strong comparison function must be used to compare the entity // tags. Thus if the entity tag of the entity is weak then matching // of entity tags in the If-Match header should fail. if (eTag.isWeak()) { return Responses.preconditionFailed(); } if (matchingTags != MatchingEntityTag.ANY_MATCH && !matchingTags.contains(eTag)) { // 412 Precondition Failed return Responses.preconditionFailed(); } return null; }
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(HttpResponseCodes.SC_PRECONDITION_FAILED).tag(eTag); } return null; }
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(HttpResponseCodes.SC_PRECONDITION_FAILED).tag(eTag); }