wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r903953 - in /incubator/wink/trunk/wink-server/src: main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java test/java/org/apache/wink/server/internal/CommonAcceptHeaderTest.java
Date Thu, 28 Jan 2010 04:07:53 GMT
Author: bluk
Date: Thu Jan 28 04:07:51 2010
New Revision: 903953

URL: http://svn.apache.org/viewvc?rev=903953&view=rev
Log:
Use correct response class when populating Content-Type

See [WINK-247]

Modified:
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/CommonAcceptHeaderTest.java

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java?rev=903953&r1=903952&r2=903953&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/PopulateResponseMediaTypeHandler.java
Thu Jan 28 04:07:51 2010
@@ -59,6 +59,10 @@
 
         if (result instanceof Response) {
             Response response = (Response)result;
+            if (response.getEntity() == null) {
+                // no entity so no need to set Content-Type
+                return;
+            }
 
             Object first = response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE);
 
@@ -81,9 +85,16 @@
                 logger.debug("Determining Content-Type from @Produces on method: {}", producedMime);
             }
             if (producedMime == null || producedMime.isEmpty()) {
-                producedMime =
-                    context.getAttribute(ProvidersRegistry.class)
-                        .getMessageBodyWriterMediaTypes(result.getClass());
+                if (result instanceof Response) {
+                    Response response = (Response)result;
+                    producedMime =
+                        context.getAttribute(ProvidersRegistry.class)
+                            .getMessageBodyWriterMediaTypes(response.getEntity().getClass());
+                } else {
+                    producedMime =
+                        context.getAttribute(ProvidersRegistry.class)
+                            .getMessageBodyWriterMediaTypes(result.getClass());
+                }
                 /*
                  * This is to inform the application developer that they should
                  * specify the Content-Type.

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/CommonAcceptHeaderTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/CommonAcceptHeaderTest.java?rev=903953&r1=903952&r2=903953&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/CommonAcceptHeaderTest.java
(original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/CommonAcceptHeaderTest.java
Thu Jan 28 04:07:51 2010
@@ -92,47 +92,28 @@
     public void testEmptyStringAcceptHeader() throws Exception {
         MockHttpServletRequest request =
             MockRequestConstructor.constructMockRequest("GET", "/countaccepttypes", "");
-        try {
-            invoke(request);
-            fail();
-        } catch (WebApplicationException e) {
-            assertEquals(400, e.getResponse().getStatus());
-        }
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(400, response.getStatus());
+        
         request = MockRequestConstructor.constructMockRequest("GET", "/countaccepttypes",
"      ");
-        try {
-            invoke(request);
-            fail();
-        } catch (WebApplicationException e) {
-            assertEquals(400, e.getResponse().getStatus());
-        }
+        response = invoke(request);
+        assertEquals(400, response.getStatus());
     }
 
     public void testIllegalStringAcceptHeader() throws Exception {
         MockHttpServletRequest request =
             MockRequestConstructor.constructMockRequest("GET", "/countaccepttypes", "text/");
-        try {
-            invoke(request);
-            fail();
-        } catch (WebApplicationException e) {
-            assertEquals(400, e.getResponse().getStatus());
-        }
+        MockHttpServletResponse response = invoke(request);
+        assertEquals(400, response.getStatus());
 
         request =
             MockRequestConstructor.constructMockRequest("GET", "/countaccepttypes", "application/");
-        try {
-            invoke(request);
-            fail();
-        } catch (WebApplicationException e) {
-            assertEquals(400, e.getResponse().getStatus());
-        }
-
-        try {
-            request =
-                MockRequestConstructor.constructMockRequest("GET", "/countaccepttypes", "/xml");
-            invoke(request);
-        } catch (WebApplicationException e) {
-            assertEquals(400, e.getResponse().getStatus());
-        }
+        response = invoke(request);
+        assertEquals(400, response.getStatus());
+
+        request = MockRequestConstructor.constructMockRequest("GET", "/countaccepttypes",
"/xml");
+        response = invoke(request);
+        assertEquals(400, response.getStatus());
 
         /*
          * while the response type isn't there
@@ -142,7 +123,7 @@
                 .constructMockRequest("GET",
                                       "/onlytext",
                                       "         text              / plain               
   ");
-        MockHttpServletResponse response = invoke(request);
+        response = invoke(request);
         assertEquals(406, response.getStatus());
         assertEquals("", response.getContentAsString());
 



Mime
View raw message