cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1148962 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Date Wed, 20 Jul 2011 22:56:13 GMT
Author: sergeyb
Date: Wed Jul 20 22:56:12 2011
New Revision: 1148962

URL: http://svn.apache.org/viewvc?rev=1148962&view=rev
Log:
[CXF-3673] Make ResponseBuilder.tag methods produce consistent header values

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java?rev=1148962&r1=1148961&r2=1148962&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
Wed Jul 20 22:56:12 2011
@@ -50,6 +50,9 @@ public class EntityTagHeaderProvider imp
         }  else {
             tag = header;
         }
+        if (tag.length() > 0 && !tag.startsWith("\"") && !tag.endsWith("\""))
{
+            return new EntityTag(tag, weak);
+        }
         if (tag.length() < 2 || !tag.startsWith("\"") || !tag.endsWith("\"")) {
             throw new IllegalArgumentException("Misformatted ETag : " + header);
         }
@@ -62,7 +65,12 @@ public class EntityTagHeaderProvider imp
         if (tag.isWeak()) {
             sb.append(WEAK_PREFIX);
         }
-        sb.append("\"").append(tag.getValue()).append("\"");
+        String tagValue = tag.getValue();
+        if (!tagValue.startsWith("\"")) {
+            sb.append("\"").append(tagValue).append("\"");
+        } else {
+            sb.append(tagValue);
+        }
         return sb.toString();
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1148962&r1=1148961&r2=1148962&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Wed Jul 20 22:56:12 2011
@@ -113,11 +113,13 @@ public final class ResponseBuilderImpl e
     }
 
     public ResponseBuilder tag(EntityTag tag) {
-        return tag(tag == null ? null : tag.toString());
+        return setHeader(HttpHeaders.ETAG, tag == null ? null : tag.toString());
     }
 
     public ResponseBuilder tag(String tag) {
-        return setHeader(HttpHeaders.ETAG, tag);
+        // String tag value needs to be parsed as it may 
+        // contain parameters indicating it's a weak tag, etc
+        return tag(tag == null ? null : EntityTag.valueOf(tag));
     }
 
     public ResponseBuilder lastModified(Date date) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1148962&r1=1148961&r2=1148962&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Wed Jul 20 22:56:12 2011
@@ -25,6 +25,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 
+import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.NewCookie;
@@ -83,6 +84,34 @@ public class ResponseBuilderImplTest ext
     }
     
     @Test
+    public void testTagString() {
+        Response r = Response.ok().tag("foo").build();
+        String eTag = r.getMetadata().getFirst("ETag").toString();
+        assertEquals("\"foo\"", eTag);
+    }
+    
+    @Test
+    public void testTagStringWithQuotes() {
+        Response r = Response.ok().tag("\"foo\"").build();
+        String eTag = r.getMetadata().getFirst("ETag").toString();
+        assertEquals("\"foo\"", eTag);
+    }
+    
+    @Test
+    public void testEntityTag() {
+        Response r = Response.ok().tag(new EntityTag("foo")).build();
+        String eTag = r.getMetadata().getFirst("ETag").toString();
+        assertEquals("\"foo\"", eTag);
+    }
+    
+    @Test
+    public void testEntityTag2() {
+        Response r = Response.ok().tag(new EntityTag("\"foo\"")).build();
+        String eTag = r.getMetadata().getFirst("ETag").toString();
+        assertEquals("\"foo\"", eTag);
+    }
+    
+    @Test
     public void testExpires() throws Exception {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         m.putSingle("Expires", "Tue, 21 Oct 2008 17:00:00 GMT");



Mime
View raw message