cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1510592 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Date Mon, 05 Aug 2013 16:20:18 GMT
Author: sergeyb
Date: Mon Aug  5 16:20:18 2013
New Revision: 1510592

URL: http://svn.apache.org/r1510592
Log:
Merged revisions 1510586 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1510586 | sergeyb | 2013-08-05 17:08:22 +0100 (Mon, 05 Aug 2013) | 1 line
  
  [CXF-5167] Fixing a regression to do with affecting Content-Type and Content-Length of HEAD
responses
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1510586

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1510592&r1=1510591&r2=1510592&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Mon Aug  5 16:20:18 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;
@@ -171,9 +172,9 @@ public class JAXRSOutInterceptor extends
         final Exchange exchange = message.getExchange();
         
         Object entity = response.getEntity();
-        if (response.getStatus() == 200 && entity != null && firstTry 
-            && ori != null && JAXRSUtils.headMethodPossible(ori.getHttpMethod(),

-                (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD))) {
+        boolean headResponse = response.getStatus() == 200 && firstTry 
+            && ori != null && HttpMethod.HEAD.equals(ori.getHttpMethod());
+        if (headResponse && entity != null) {
             LOG.info(new org.apache.cxf.common.i18n.Message("HEAD_WITHOUT_ENTITY", BUNDLE).toString());
             entity = null;
         }
@@ -229,9 +230,11 @@ public class JAXRSOutInterceptor extends
         entity = InjectionUtils.getEntity(response.getEntity());
         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);
+            }
             return;
         }
         
@@ -243,14 +246,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 = 
@@ -306,6 +303,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