cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1471394 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Date Wed, 24 Apr 2013 13:04:34 GMT
Author: sergeyb
Date: Wed Apr 24 13:04:33 2013
New Revision: 1471394

URL: http://svn.apache.org/r1471394
Log:
[CXF-4985] If response entity is null and the status has not ben explicitly set - report 204

Modified:
    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/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1471394&r1=1471393&r2=1471394&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 Apr 24 13:04:33 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;
@@ -61,6 +62,9 @@ public final class ResponseBuilderImpl e
     }
        
     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 +79,7 @@ public final class ResponseBuilderImpl e
             throw new IllegalArgumentException("Illegal status value : " + s);
         }
         status = s;
+        statusSet = true;
         return this;
     }
 

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=1471394&r1=1471393&r2=1471394&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 Apr 24 13:04:33 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");



Mime
View raw message