cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1471321 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Date Wed, 24 Apr 2013 09:28:09 GMT
Author: sergeyb
Date: Wed Apr 24 09:28:09 2013
New Revision: 1471321

URL: http://svn.apache.org/r1471321
Log:
[CXF-4983] Updating ResponseImpl.getStatusInfo to deal with status codes which have no matching
Status enums

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1471321&r1=1471320&r2=1471321&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Wed Apr 24 09:28:09 2013
@@ -106,19 +106,19 @@ public final class ResponseImpl extends 
     }
 
     public StatusType getStatusInfo() {
-        final Response.Status responseStatus = Response.Status.fromStatusCode(status);
         return new Response.StatusType() {
 
             public Family getFamily() {
-                return responseStatus.getFamily();
+                return Response.Status.Family.familyOf(ResponseImpl.this.status);
             }
 
             public String getReasonPhrase() {
-                return responseStatus.getReasonPhrase();
+                Response.Status statusEnum = Response.Status.fromStatusCode(ResponseImpl.this.status);

+                return statusEnum != null ? statusEnum.getReasonPhrase() : "";
             }
 
             public int getStatusCode() {
-                return responseStatus.getStatusCode();
+                return ResponseImpl.this.status;
             } 
             
         };

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java?rev=1471321&r1=1471320&r2=1471321&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Wed Apr 24 09:28:09 2013
@@ -28,6 +28,8 @@ import javax.ws.rs.core.Link;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.Response.StatusType;
 
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 
@@ -58,6 +60,33 @@ public class ResponseImplTest extends As
     }
     
     @Test
+    public void testStatuInfoForOKStatus() {
+        StatusType si = new ResponseImpl(200, "").getStatusInfo();
+        assertNotNull(si);
+        assertEquals(200, si.getStatusCode());
+        assertEquals(Status.Family.SUCCESSFUL, si.getFamily());
+        assertEquals("OK", si.getReasonPhrase());
+    }
+    
+    @Test
+    public void testStatuInfoForClientErrorStatus() {
+        StatusType si = new ResponseImpl(400, "").getStatusInfo();
+        assertNotNull(si);
+        assertEquals(400, si.getStatusCode());
+        assertEquals(Status.Family.CLIENT_ERROR, si.getFamily());
+        assertEquals("Bad Request", si.getReasonPhrase());
+    }
+    
+    @Test
+    public void testStatuInfoForClientErrorStatus2() {
+        StatusType si = new ResponseImpl(499, "").getStatusInfo();
+        assertNotNull(si);
+        assertEquals(499, si.getStatusCode());
+        assertEquals(Status.Family.CLIENT_ERROR, si.getFamily());
+        assertEquals("", si.getReasonPhrase());
+    }
+    
+    @Test
     public void testHasEntityAfterClose() {
         Response r = new ResponseImpl(200, new ByteArrayInputStream("data".getBytes()));

         assertTrue(r.hasEntity());



Mime
View raw message