cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1151235 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 26 Jul 2011 20:38:36 GMT
Author: sergeyb
Date: Tue Jul 26 20:38:35 2011
New Revision: 1151235

URL: http://svn.apache.org/viewvc?rev=1151235&view=rev
Log:
[CXF-3667] Drop Content-Type if Content-Length is available and set to 0

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1151235&r1=1151234&r2=1151235&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Tue Jul 26 20:38:35 2011
@@ -187,6 +187,7 @@ public class JAXRSOutInterceptor extends
         
         setResponseDate(responseHeaders, firstTry);
         if (isResponseNull(responseObj)) {
+            responseHeaders.putSingle("Content-Length", "0");
             return;
         }
         

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java?rev=1151235&r1=1151234&r2=1151235&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
Tue Jul 26 20:38:35 2011
@@ -358,6 +358,23 @@ public class Headers {
         }
     }
     
+    // Assumes that response body is not available only
+    // if Content-Length is available and set to 0
+    private boolean isResponseBodyAvailable() {
+        List<String> ctLen = headers.get("Content-Length");
+        if (ctLen == null || ctLen.size() != 1) {
+            return true;
+        }
+        try {
+            if (Integer.valueOf(ctLen.get(0)) == 0) {
+                return false;
+            }
+        } catch (NumberFormatException ex) {
+            // ignore
+        }
+        return true;
+    }
+    
     /**
      * Copy the response headers into the response.
      * 
@@ -367,7 +384,8 @@ public class Headers {
     protected void copyToResponse(HttpServletResponse response) {
         String contentType = getContentTypeFromMessage();
  
-        if (!headers.containsKey(Message.CONTENT_TYPE) && contentType != null) {
+        if (!headers.containsKey(Message.CONTENT_TYPE) && contentType != null 
+            && isResponseBodyAvailable()) {
             response.setContentType(contentType);
         }
 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1151235&r1=1151234&r2=1151235&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Jul 26 20:38:35 2011
@@ -591,8 +591,10 @@ public class JAXRSClientServerBookTest e
         WebClient wc = 
             WebClient.create("http://localhost:" 
                              + PORT + "/bookstore/emptypost");
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
         Response response = wc.post(null);
         assertEquals(204, response.getStatus());
+        assertNull(response.getMetadata().getFirst("Content-Type"));
     }
     
     @Test



Mime
View raw message