You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/01/29 17:33:22 UTC

svn commit: r1562504 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java

Author: sergeyb
Date: Wed Jan 29 16:33:21 2014
New Revision: 1562504

URL: http://svn.apache.org/r1562504
Log:
Merged revisions 1562501 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1562501 | sergeyb | 2014-01-29 16:29:37 +0000 (Wed, 29 Jan 2014) | 1 line
  
  [CXF-5508] More fixes based on the feedback from Jan Engehausen
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1562501

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java?rev=1562504&r1=1562503&r2=1562504&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java Wed Jan 29 16:33:21 2014
@@ -28,6 +28,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -165,18 +166,28 @@ public class RequestImpl implements Requ
         if (eTag == null) {
             throw new IllegalArgumentException("ETag is null");
         }
-        ResponseBuilder rb = evaluateIfMatch(eTag);
+        return evaluateAll(eTag, null);
+    }
+    
+    private ResponseBuilder evaluateAll(EntityTag eTag, Date lastModified) {
+        // http://tools.ietf.org/search/draft-ietf-httpbis-p4-conditional-25#section-5
+        // Check If-Match. If it is not available proceed to checking If-Not-Modified-Since
+        // if it is available and the preconditions are not met - return, otherwise:
+        // Check If-Not-Match. If it is not available proceed to checking If-Modified-Since
+        // otherwise return the evaluation result
+        
+        ResponseBuilder rb = evaluateIfMatch(eTag, lastModified);
         if (rb == null) {
-            rb = evaluateIfNonMatch(eTag);
+            rb = evaluateIfNonMatch(eTag, lastModified);
         }
         return rb;
     }
 
-    private ResponseBuilder evaluateIfMatch(EntityTag eTag) {
+    private ResponseBuilder evaluateIfMatch(EntityTag eTag, Date date) {
         List<String> ifMatch = headers.getRequestHeader(HttpHeaders.IF_MATCH);
         
         if (ifMatch == null || ifMatch.size() == 0) {
-            return null;
+            return date == null ? null : evaluateIfNotModifiedSince(date);
         }
         
         try {
@@ -196,15 +207,15 @@ public class RequestImpl implements Requ
         return Response.status(Response.Status.PRECONDITION_FAILED).tag(eTag);
     }
 
-    private ResponseBuilder evaluateIfNonMatch(EntityTag eTag) {
+    private ResponseBuilder evaluateIfNonMatch(EntityTag eTag, Date lastModified) {
         List<String> ifNonMatch = headers.getRequestHeader(HttpHeaders.IF_NONE_MATCH);
         
         if (ifNonMatch == null || ifNonMatch.size() == 0) {
-            return null;
+            return lastModified == null ? null : evaluateIfModifiedSince(lastModified);
         }
         
         String method = getMethod();
-        boolean getOrHead = "GET".equals(method) || "HEAD".equals(method);
+        boolean getOrHead = HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method);
         try {
             for (String value : ifNonMatch) {
                 boolean result = "*".equals(value);
@@ -229,10 +240,18 @@ public class RequestImpl implements Requ
         if (lastModified == null) {
             throw new IllegalArgumentException("Date is null");
         }
+        ResponseBuilder rb = evaluateIfNotModifiedSince(lastModified);
+        if (rb == null) {
+            rb = evaluateIfModifiedSince(lastModified);
+        }
+        return rb;
+    }
+    
+    private ResponseBuilder evaluateIfModifiedSince(Date lastModified) {
         List<String> ifModifiedSince = headers.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE);
         
         if (ifModifiedSince == null || ifModifiedSince.size() == 0) {
-            return evaluateIfNotModifiedSince(lastModified);
+            return null;
         }
         
         SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat();
@@ -254,7 +273,7 @@ public class RequestImpl implements Requ
         return Response.status(Response.Status.NOT_MODIFIED);
     }
     
-    public ResponseBuilder evaluateIfNotModifiedSince(Date lastModified) {
+    private ResponseBuilder evaluateIfNotModifiedSince(Date lastModified) {
         List<String> ifNotModifiedSince = headers.getRequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE);
         
         if (ifNotModifiedSince == null || ifNotModifiedSince.size() == 0) {
@@ -282,16 +301,10 @@ public class RequestImpl implements Requ
 
 
     public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
-        final ResponseBuilder rb = evaluatePreconditions(eTag);
-        if (rb == null) {
-            // the ETag conditions match; so now conditions for last modified must match
-            return evaluatePreconditions(lastModified);
-        } else {
-            // the ETag conditions do not match, so last modified should be ignored
-            // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html (section 14.26 for
-            // "If-None-Match", behaviour not specified for "If-Match", section 14.24)
-            return rb;
+        if (eTag == null || lastModified == null) {
+            throw new IllegalArgumentException("ETag or Date is null");
         }
+        return evaluateAll(eTag, lastModified);
     }
     
     public String getMethod() {

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java?rev=1562504&r1=1562503&r2=1562504&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java Wed Jan 29 16:33:21 2014
@@ -294,14 +294,14 @@ public class RequestImplTest extends Ass
     @Test
     public void testIfNoneMatchAndDateWithNonMatchingTags() throws Exception {
         metadata.putSingle(HttpHeaders.IF_NONE_MATCH, "\"123\"");
-        metadata.putSingle("If-Modified-Since", "Tue, 21 Oct 2008 14:00:00 GMT");
+        metadata.putSingle("If-Modified-Since", "Tue, 20 Oct 2008 14:00:00 GMT");
         
         Date lastModified = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH)
-            .parse("Mon, 20 Oct 2008 14:00:00 GMT");
+            .parse("Mon, 21 Oct 2008 14:00:00 GMT");
         
         ResponseBuilder rb = 
             new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("124"));
-        assertNotNull("Dates must not be checked if tags do not match", rb);
+        assertNull("Dates must not be checked if tags do not match", rb);
     }
    
 }