cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1052516 - 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/ systests/jaxrs/src/test/j...
Date Fri, 24 Dec 2010 14:49:05 GMT
Author: sergeyb
Date: Fri Dec 24 14:49:04 2010
New Revision: 1052516

URL: http://svn.apache.org/viewvc?rev=1052516&view=rev
Log:
[JAX-RS] Ensuring custom response code is not lost in case of CXF interceptors initiating
an early copying of headers

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/AbstractHTTPDestination.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.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=1052516&r1=1052515&r2=1052516&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
Fri Dec 24 14:49:04 2010
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -59,6 +60,7 @@ import org.apache.cxf.jaxrs.utils.JAXRSU
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.CachingXmlEventWriter;
 import org.apache.cxf.staxutils.StaxUtils;
@@ -161,7 +163,9 @@ public class JAXRSOutInterceptor extends
             status = isResponseNull(responseObj) ? 204 : 200;
         }
         
-        message.put(Message.RESPONSE_CODE, status);
+        boolean responseHeadersCopied = isResponseHeadersCopied(message);
+        setResponseStatus(message, status, responseHeadersCopied);
+        
         Map<String, List<String>> theHeaders = 
             (Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS);
         if (firstTry && theHeaders != null) {
@@ -454,4 +458,25 @@ public class JAXRSOutInterceptor extends
             throw new RuntimeException(ex);
         }
     }
+   
+    private void setResponseStatus(Message message, int status, boolean responseHeadersCopied)
{
+        message.put(Message.RESPONSE_CODE, status);   
+        if (responseHeadersCopied) {
+            HttpServletResponse response = 
+                (HttpServletResponse)message.get(AbstractHTTPDestination.HTTP_RESPONSE);
+            response.setStatus(status);
+        }
+    }
+    
+    // Some CXF interceptors such as FIStaxOutInterceptor will indirectly initiate
+    // an early copying of response code and headers into the HttpServletResponse
+    // TODO : Pushing the filter processing and copying response headers into say
+    // PRE-LOGICAl and PREPARE_SEND interceptors will most likely be a good thing
+    // however JAX-RS MessageBodyWriters are also allowed to add response headers
+    // which is reason why a MultipartMap parameter in MessageBodyWriter.writeTo 
+    // method is modifiable. Thus we do need to know if the initial copy has already
+    // occurred: for now we will just use to ensure the correct status is set
+    private boolean isResponseHeadersCopied(Message message) {
+        return MessageUtils.isTrue(message.get(AbstractHTTPDestination.RESPONSE_HEADERS_COPIED));
+    }
 }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1052516&r1=1052515&r2=1052516&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Fri Dec 24 14:49:04 2010
@@ -85,7 +85,8 @@ public abstract class AbstractHTTPDestin
     public static final String HTTP_RESPONSE = "HTTP.RESPONSE";
     public static final String HTTP_CONTEXT = "HTTP.CONTEXT";
     public static final String HTTP_CONFIG = "HTTP.CONFIG";
-        
+    
+    public static final String RESPONSE_HEADERS_COPIED = "http.response.done";
     public static final String RESPONSE_COMMITED = "http.response.done";
     public static final String REQUEST_REDIRECTED = "http.request.redirected";
     public static final String CXF_CONTINUATION_MESSAGE = "cxf.continuation.message";
@@ -431,6 +432,8 @@ public abstract class AbstractHTTPDestin
         }
         new Headers(outMessage).copyToResponse(response);
 
+        outMessage.put(RESPONSE_HEADERS_COPIED, "true");
+        
         if (oneWay && !MessageUtils.isPartialResponse(outMessage)) {
             response.setContentLength(0);
             response.flushBuffer();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1052516&r1=1052515&r2=1052516&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Fri Dec 24 14:49:04 2010
@@ -626,12 +626,12 @@ public class JAXRSSoapBookTest extends A
         assertEquals(200, WebClient.create(
             "http://localhost:" + PORT + "/test/services/rest2?_wadl&type=xml").get().getStatus());
         assertFalse(listings.contains("http://localhost:" + PORT + "/test/services/rest3?_wadl&type=xml"));
-        assertEquals(401, WebClient.create(
-            "http://localhost:" + PORT + "/test/services/rest3?_wadl&type=xml").get().getStatus());
-        
-         
-        
-        //assertFalse(listings.contains("Atom Log Feed"));
+        assertFalse(listings.contains("Atom Log Feed"));
+    
+        WebClient webClient = 
+            WebClient.create("http://localhost:" + PORT + "/test/services/rest3?_wadl&type=xml");
+        WebClient.getConfig(webClient).getHttpConduit().getClient().setReceiveTimeout(1000000);
+        assertEquals(401, webClient.get().getStatus());
     }
     
     @Test

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java?rev=1052516&r1=1052515&r2=1052516&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
Fri Dec 24 14:49:04 2010
@@ -19,12 +19,14 @@
 
 package org.apache.cxf.systest.jaxrs.jaxws;
 
+import org.apache.cxf.annotations.EndpointProperty;
 import org.apache.cxf.interceptor.InInterceptors;
 import org.apache.cxf.interceptor.OutInterceptors;
 import org.apache.cxf.systest.jaxrs.Book;
 
 @InInterceptors(interceptors = "org.apache.cxf.interceptor.FIStaxInInterceptor")
 @OutInterceptors(interceptors = "org.apache.cxf.interceptor.FIStaxOutInterceptor")
+@EndpointProperty(key = "org.apache.cxf.fastinfoset.enabled", value = "true")
 public class BookStoreSoapRestFastInfoset extends BookStoreSoapRestImpl {
 
     @Override



Mime
View raw message