Java Code Examples for javax.ws.rs.core.EntityTag#valueOf()
The following examples show how to use
javax.ws.rs.core.EntityTag#valueOf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestImpl.java From cxf with Apache License 2.0 | 6 votes |
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); }
Example 2
Source File: ContainerRequest.java From everrest with Eclipse Public License 2.0 | 6 votes |
/** * Comparison for If-None-Match header and ETag. * * @param etag * the ETag * @return ResponseBuilder with status 412 (precondition failed) if If-None-Match header is MATCH to ETag and HTTP method is not GET or * HEAD. If method is GET or HEAD and If-None-Match is MATCH to ETag then ResponseBuilder with status 304 (not modified) will be * returned. */ private ResponseBuilder evaluateIfNoneMatch(EntityTag etag) { String ifNoneMatch = getRequestHeaders().getFirst(IF_NONE_MATCH); if (Strings.isNullOrEmpty(ifNoneMatch)) { return null; } EntityTag otherEtag = EntityTag.valueOf(ifNoneMatch); String httpMethod = getMethod(); if (httpMethod.equals(GET) || httpMethod.equals(HEAD)) { if (eTagsWeakEqual(etag, otherEtag)) { return Response.notModified(etag); } } else { if (eTagsStrongEqual(etag, otherEtag)) { return Response.status(PRECONDITION_FAILED); } } return null; }
Example 3
Source File: RequestImpl.java From cxf with Apache License 2.0 | 5 votes |
private ResponseBuilder evaluateIfNonMatch(EntityTag eTag, Date lastModified) { List<String> ifNonMatch = headers.getRequestHeader(HttpHeaders.IF_NONE_MATCH); if (ifNonMatch == null || ifNonMatch.isEmpty()) { return lastModified == null ? null : evaluateIfModifiedSince(lastModified); } String method = getMethod(); 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); } } } catch (IllegalArgumentException ex) { // ignore } return null; }
Example 4
Source File: EntityTagHeaderProviderTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testFromString() { EntityTag tag = EntityTag.valueOf("\"\""); assertFalse(tag.isWeak() && "".equals(tag.getValue())); tag = EntityTag.valueOf("W/"); assertTrue(tag.isWeak() && "".equals(tag.getValue())); tag = EntityTag.valueOf("W/\"12345\""); assertTrue(tag.isWeak() && "12345".equals(tag.getValue())); tag = EntityTag.valueOf("\"12345\""); assertFalse(tag.isWeak() && "12345".equals(tag.getValue())); }
Example 5
Source File: ResponseImpl.java From everrest with Eclipse Public License 2.0 | 5 votes |
@Override public EntityTag getEntityTag() { Object value = getMetadata().getFirst(ETAG); if (value == null) { return null; } if (value instanceof EntityTag) { return (EntityTag)value; } return EntityTag.valueOf(value instanceof String ? (String)value : getHeaderAsString(value)); }
Example 6
Source File: ContainerRequest.java From everrest with Eclipse Public License 2.0 | 5 votes |
/** * Comparison for If-Match header and ETag. * * @param etag * the ETag * @return ResponseBuilder with status 412 (precondition failed) if If-Match header does NOT MATCH to ETag or null otherwise */ private ResponseBuilder evaluateIfMatch(EntityTag etag) { String ifMatch = getRequestHeaders().getFirst(IF_MATCH); if (isNullOrEmpty(ifMatch)) { return null; } EntityTag otherEtag = EntityTag.valueOf(ifMatch); if (eTagsStrongEqual(etag, otherEtag)) { return null; } return Response.status(PRECONDITION_FAILED); }
Example 7
Source File: ResponseImpl.java From cxf with Apache License 2.0 | 4 votes |
public EntityTag getEntityTag() { Object header = metadata.getFirst(HttpHeaders.ETAG); return header == null || header instanceof EntityTag ? (EntityTag)header : EntityTag.valueOf(header.toString()); }
Example 8
Source File: EntityTagHeaderProviderTest.java From cxf with Apache License 2.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void testNullValue() throws Exception { EntityTag.valueOf(null); }