ETagFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext request, ContainerResponseContext response) { String etagStr = null; if (response.getHeaders().containsKey(HttpHeaders.ETAG)) { etagStr = (String) response.getHeaders().getFirst(HttpHeaders.ETAG); } if (etagStr == null && servletResponse != null) { etagStr = servletResponse.getHeader(HttpHeaders.ETAG); if (etagStr != null) { servletResponse.setHeader(HttpHeaders.ETAG, null); } } if (etagStr != null) { etagStr = removeLeadingAndTrailingQuotes(etagStr); response.getHeaders().putSingle("ETag", new EntityTag(etagStr)); } }  @Override void filter(ContainerRequestContext request, ContainerResponseContext response);  }
@Test public void testFilterContainerETagSet() { ContainerResponseContext containerResponse = getContext("etag"); ETagFilter eTagFilter = new ETagFilter(); eTagFilter.filter(null, containerResponse); EntityTag eTag = (EntityTag) containerResponse.getHeaders().getFirst(HttpHeaders.ETAG); assertNotNull(eTag); assertEquals(eTag.getValue(), "etag"); }
@Test public void testFilterContainerETagNotSet() { ContainerResponseContext containerResponse = getContext(null); ETagFilter eTagFilter = new ETagFilter(); eTagFilter.filter(null, containerResponse); EntityTag eTag = (EntityTag) containerResponse.getHeaders().getFirst(HttpHeaders.ETAG); assertNull(eTag); }