incubator-wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r931188 - in /incubator/wink/trunk/wink-client/src: main/java/org/apache/wink/client/ClientResponse.java main/java/org/apache/wink/client/internal/handlers/ClientResponseImpl.java test/java/org/apache/wink/client/ClientTest.java
Date Tue, 06 Apr 2010 15:41:26 GMT
Author: bluk
Date: Tue Apr  6 15:41:26 2010
New Revision: 931188

URL: http://svn.apache.org/viewvc?rev=931188&view=rev
Log:
Add ClientResponse.getStatusType()

Modified:
    incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/ClientResponse.java
    incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/internal/handlers/ClientResponseImpl.java
    incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ClientTest.java

Modified: incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/ClientResponse.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/ClientResponse.java?rev=931188&r1=931187&r2=931188&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/ClientResponse.java
(original)
+++ incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/ClientResponse.java
Tue Apr  6 15:41:26 2010
@@ -20,6 +20,8 @@
 
 package org.apache.wink.client;
 
+import javax.ws.rs.core.Response.StatusType;
+
 import org.apache.wink.client.internal.BaseRequestResponse;
 
 /**
@@ -31,6 +33,13 @@ import org.apache.wink.client.internal.B
 public interface ClientResponse extends BaseRequestResponse {
 
     /**
+     * Gets the response status as a status type
+     * 
+     * @return the response status
+     */
+    public StatusType getStatusType();
+
+    /**
      * Get the response status code
      * 
      * @return response status code

Modified: incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/internal/handlers/ClientResponseImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/internal/handlers/ClientResponseImpl.java?rev=931188&r1=931187&r2=931188&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/internal/handlers/ClientResponseImpl.java
(original)
+++ incubator/wink/trunk/wink-client/src/main/java/org/apache/wink/client/internal/handlers/ClientResponseImpl.java
Tue Apr  6 15:41:26 2010
@@ -27,6 +27,8 @@ import java.lang.reflect.Type;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response.StatusType;
+import javax.ws.rs.core.Response.Status.Family;
 import javax.ws.rs.ext.MessageBodyReader;
 
 import org.apache.wink.client.ClientResponse;
@@ -147,4 +149,34 @@ public class ClientResponseImpl extends 
         return contentConsumer;
     }
 
+    public StatusType getStatusType() {
+        final int statusCode = status;
+        final String reasonPhrase = message;
+        return new StatusType() {
+
+            public int getStatusCode() {
+                return statusCode;
+            }
+
+            public String getReasonPhrase() {
+                return reasonPhrase;
+            }
+
+            public Family getFamily() {
+                int family = statusCode / 100;
+                if(family == 1) {
+                    return Family.INFORMATIONAL;
+                } else if (family == 2) {
+                    return Family.SUCCESSFUL;
+                } else if (family == 3) {
+                    return Family.REDIRECTION;
+                } else if (family == 4) {
+                    return Family.CLIENT_ERROR;
+                } else if (family == 5) {
+                    return Family.SERVER_ERROR;
+                }
+                return Family.OTHER;
+            }
+        };
+    }
 }

Modified: incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ClientTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ClientTest.java?rev=931188&r1=931187&r2=931188&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ClientTest.java
(original)
+++ incubator/wink/trunk/wink-client/src/test/java/org/apache/wink/client/ClientTest.java
Tue Apr  6 15:41:26 2010
@@ -34,6 +34,7 @@ import javax.ws.rs.WebApplicationExcepti
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response.Status.Family;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
@@ -148,6 +149,9 @@ public class ClientTest extends BaseTest
         TestGenerics<String> tg = resource.get(new EntityType<TestGenerics<String>>()
{
         });
         assertEquals(RECEIVED_MESSAGE, tg.getT());
+        assertEquals(200, clientResponse.getStatusType().getStatusCode());
+        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
+        assertEquals("OK", clientResponse.getStatusType().getReasonPhrase());
     }
 
     public void testResourcePut() throws IOException {
@@ -168,6 +172,9 @@ public class ClientTest extends BaseTest
         }, SENT_MESSAGE);
         assertEquals(RECEIVED_MESSAGE, tg.getT());
 
+        assertEquals(200, clientResponse.getStatusType().getStatusCode());
+        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
+        assertEquals("OK", clientResponse.getStatusType().getReasonPhrase());
     }
 
     public void testResourcePost() throws IOException {
@@ -188,6 +195,10 @@ public class ClientTest extends BaseTest
         TestGenerics<String> tg = resource.post(new EntityType<TestGenerics<String>>()
{
         }, SENT_MESSAGE);
         assertEquals(RECEIVED_MESSAGE, tg.getT());
+
+        assertEquals(200, clientResponse.getStatusType().getStatusCode());
+        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
+        assertEquals("OK", clientResponse.getStatusType().getReasonPhrase());
     }
 
     public void testResourceDelete() {
@@ -205,6 +216,10 @@ public class ClientTest extends BaseTest
         TestGenerics<String> tg = resource.delete(new EntityType<TestGenerics<String>>()
{
         });
         assertEquals(RECEIVED_MESSAGE, tg.getT());
+
+        assertEquals(200, clientResponse.getStatusType().getStatusCode());
+        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
+        assertEquals("OK", clientResponse.getStatusType().getReasonPhrase());
     }
 
     public void testInvoke() {
@@ -240,6 +255,10 @@ public class ClientTest extends BaseTest
         try {
             ClientResponse res = resource.accept("text/plain").get();
             assertTrue(res.getStatusCode() == 400);
+
+            assertEquals(400, res.getStatusType().getStatusCode());
+            assertEquals(Family.CLIENT_ERROR, res.getStatusType().getFamily());
+            assertEquals("Bad Request", res.getStatusType().getReasonPhrase());
         } catch (Exception e) {
             fail("Exception must not be thrown");
         }



Mime
View raw message