cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1510586 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Date Mon, 05 Aug 2013 16:08:23 GMT
Author: sergeyb
Date: Mon Aug  5 16:08:22 2013
New Revision: 1510586

URL: http://svn.apache.org/r1510586
Log:
[CXF-5167] Fixing a regression to do with affecting Content-Type and Content-Length of HEAD
responses

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.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=1510586&r1=1510585&r2=1510586&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
Mon Aug  5 16:08:22 2013
@@ -33,6 +33,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.Produces;
 import javax.ws.rs.container.AsyncResponse;
@@ -157,10 +158,10 @@ public class JAXRSOutInterceptor extends
         
         final Exchange exchange = message.getExchange();
         
+        boolean headResponse = response.getStatus() == 200 && firstTry 
+            && ori != null && HttpMethod.HEAD.equals(ori.getHttpMethod());
         Object entity = response.getActualEntity();
-        if (response.getStatus() == 200 && entity != null && firstTry 
-            && ori != null && JAXRSUtils.headMethodPossible(ori.getHttpMethod(),

-                (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD))) {
+        if (headResponse && entity != null) {
             LOG.info(new org.apache.cxf.common.i18n.Message("HEAD_WITHOUT_ENTITY", BUNDLE).toString());
             entity = null;
         }
@@ -218,9 +219,11 @@ public class JAXRSOutInterceptor extends
         entity = InjectionUtils.getEntity(response.getActualEntity());
         setResponseStatus(message, getActualStatus(response.getStatus(), entity));
         if (entity == null) {
-            responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, "0");
-            responseHeaders.remove(HttpHeaders.CONTENT_TYPE);
-            message.remove(Message.CONTENT_TYPE);
+            if (!headResponse) {
+                responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, "0");
+                responseHeaders.remove(HttpHeaders.CONTENT_TYPE);
+                message.remove(Message.CONTENT_TYPE);
+            }
             HttpUtils.convertHeaderValuesToStringIfNeeded(responseHeaders);
             return;
         }
@@ -233,14 +236,8 @@ public class JAXRSOutInterceptor extends
             return;
         }
         
-        Object mediaTypeHeader = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
-        MediaType responseMediaType;
-        if (mediaTypeHeader instanceof MediaType) {
-            responseMediaType = (MediaType)mediaTypeHeader;
-        } else {
-            responseMediaType = mediaTypeHeader == null ? MediaType.WILDCARD_TYPE
-                : JAXRSUtils.toMediaType(mediaTypeHeader.toString());
-        }
+        MediaType responseMediaType = 
+            getResponseMediaType(responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE));
         
         Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
         Type genericType = 
@@ -297,6 +294,17 @@ public class JAXRSOutInterceptor extends
         }
     }
     
+    private MediaType getResponseMediaType(Object mediaTypeHeader) {
+        MediaType responseMediaType;
+        if (mediaTypeHeader instanceof MediaType) {
+            responseMediaType = (MediaType)mediaTypeHeader;
+        } else {
+            responseMediaType = mediaTypeHeader == null ? MediaType.WILDCARD_TYPE
+                : JAXRSUtils.toMediaType(mediaTypeHeader.toString());
+        }
+        return responseMediaType;
+    }
+    
     private int getActualStatus(int status, Object responseObj) {
         if (status == -1) {
             return responseObj == null ? 204 : 200;



Mime
View raw message