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 2013/07/16 13:15:41 UTC

svn commit: r1503661 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java

Author: sergeyb
Date: Tue Jul 16 11:15:41 2013
New Revision: 1503661

URL: http://svn.apache.org/r1503661
Log:
Merged revisions 1471394,1471499 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1471394 | sergeyb | 2013-04-24 14:04:33 +0100 (Wed, 24 Apr 2013) | 1 line
  
  [CXF-4985] If response entity is null and the status has not ben explicitly set - report 204
........
  r1471499 | sergeyb | 2013-04-24 17:09:54 +0100 (Wed, 24 Apr 2013) | 1 line
  
  [CXF-4985] Copying statusSet field when cloning RB
........

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/ResponseBuilderImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java

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

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

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/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1503661&r1=1503660&r2=1503661&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java Tue Jul 16 11:15:41 2013
@@ -47,6 +47,7 @@ import org.apache.cxf.phase.PhaseInterce
 
 public final class ResponseBuilderImpl extends ResponseBuilder implements Cloneable {
     private int status = 200;
+    private boolean statusSet;
     private Object entity;
     private MultivaluedMap<String, Object> metadata = new MetadataMap<String, Object>();
     private Annotation[] annotations;
@@ -56,11 +57,15 @@ public final class ResponseBuilderImpl e
 
     private ResponseBuilderImpl(ResponseBuilderImpl copy) {
         status = copy.status;
+        statusSet = copy.statusSet;
         metadata.putAll(copy.metadata);
         entity = copy.entity;
     }
        
     public Response build() {
+        if (entity == null && !statusSet) {
+            status = 204;
+        }
         ResponseImpl r = new ResponseImpl(status);
         MetadataMap<String, Object> m = 
             new MetadataMap<String, Object>(metadata, false, true);
@@ -75,6 +80,7 @@ public final class ResponseBuilderImpl e
             throw new IllegalArgumentException("Illegal status value : " + s);
         }
         status = s;
+        statusSet = true;
         return this;
     }
 

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1503661&r1=1503660&r2=1503661&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java Tue Jul 16 11:15:41 2013
@@ -45,6 +45,22 @@ import org.junit.Test;
 public class ResponseBuilderImplTest extends Assert {
 
     @Test
+    public void testStatusSet() throws Exception {
+        assertEquals(200, Response.ok().build().getStatus());
+        assertEquals(200, new ResponseBuilderImpl().status(200).build().getStatus());
+    }
+    
+    @Test
+    public void testStatusNotSetNoEntity() throws Exception {
+        assertEquals(204, new ResponseBuilderImpl().build().getStatus());
+    }
+    
+    @Test
+    public void testStatusNotSetEntitySet() throws Exception {
+        assertEquals(200, new ResponseBuilderImpl().entity("").build().getStatus());
+    }
+    
+    @Test
     public void testAllow() throws Exception {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         m.add("Allow", "HEAD");