Skip to content

RESTEASY-1019: Parsing weak EntityTags #455

Merged
merged 2 commits into from Mar 19, 2014
View
12 .../resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/delegates/EntityTagDelegate.java
@@ -12,6 +12,12 @@
public EntityTag fromString(String value) throws IllegalArgumentException
{
if (value == null) throw new IllegalArgumentException("value of EntityTag is null");
+ boolean weakTag = false;
+ if (value.startsWith("W/"))
+ {
+ weakTag = true;
+ value = value.substring(2);
+ }
if (value.startsWith("\""))
{
value = value.substring(1);
@@ -20,11 +26,7 @@ public EntityTag fromString(String value) throws IllegalArgumentException
{
value = value.substring(0, value.length() - 1);
}
- if (value.startsWith("W/"))
- {
- return new EntityTag(value.substring(2), true);
- }
- return new EntityTag(value);
+ return new EntityTag(value, weakTag);
}
public String toString(EntityTag value)
View
44 ...easy-jaxrs/src/test/java/org/jboss/resteasy/test/finegrain/resource/PreconditionTest.java
@@ -229,6 +229,16 @@ public Response doGet()
return Response.ok("foo", "text/plain").build();
}
+ @GET
+ @Path("/weak")
+ public Response GetWeak() {
+ Response.ResponseBuilder rb = myRequest.evaluatePreconditions(new EntityTag("1", true));
+ if (rb != null)
+ return rb.build();
+
+ return Response.ok("foo", "text/plain").build();
+ }
+
}
@Test
@@ -302,6 +312,40 @@ public void testIfMatchWithoutMatchingETag_IfNonMatchWithoutMatchingETag()
testIfMatchWithoutMatchingETag_IfNonMatchWithoutMatchingETag("/fromField");
}
+ @Test
+ public void testIfMatchWithMatchingWeakETag()
+ {
+ ClientRequest request = new ClientRequest(generateURL("/etag/weak"));
+ request.header(HttpHeaderNames.IF_MATCH, "W/\"1\"");
+ try
+ {
+ ClientResponse<?> response = request.get();
+ Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
+ shutdownConnections(request);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Test
+ public void testIfMatchWithNonMatchingWeakEtag()
+ {
+ ClientRequest request = new ClientRequest(generateURL("/etag/weak"));
+ request.header(HttpHeaderNames.IF_MATCH, "W/\"2\"");
+ try
+ {
+ ClientResponse<?> response = request.get();
+ Assert.assertEquals(HttpResponseCodes.SC_PRECONDITION_FAILED, response.getStatus());
+ shutdownConnections(request);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
////////////
public void testIfMatchWithMatchingETag(String fromField)
Something went wrong with that request. Please try again.