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 2011/07/21 01:06:56 UTC

svn commit: r1148967 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/

Author: sergeyb
Date: Wed Jul 20 23:06:55 2011
New Revision: 1148967

URL: http://svn.apache.org/viewvc?rev=1148967&view=rev
Log:
Merged revisions 1148964 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.4.x-fixes

................
  r1148964 | sergeyb | 2011-07-21 00:01:47 +0100 (Thu, 21 Jul 2011) | 9 lines
  
  Merged revisions 1148962 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1148962 | sergeyb | 2011-07-20 23:56:12 +0100 (Wed, 20 Jul 2011) | 1 line
    
    [CXF-3673] Make ResponseBuilder.tag methods produce consistent header values
  ........
................

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 20 23:06:55 2011
@@ -1,2 +1,2 @@
-/cxf/branches/2.4.x-fixes:1144979,1147505
-/cxf/trunk:1144977,1147504
+/cxf/branches/2.4.x-fixes:1144979,1147505,1148964
+/cxf/trunk:1144977,1147504,1148962

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java?rev=1148967&r1=1148966&r2=1148967&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java (original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/EntityTagHeaderProvider.java Wed Jul 20 23:06:55 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/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1148967&r1=1148966&r2=1148967&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java (original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java Wed Jul 20 23:06:55 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/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1148967&r1=1148966&r2=1148967&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java (original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java Wed Jul 20 23:06:55 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");