Author: sergeyb
Date: Fri Dec 24 15:03:01 2010
New Revision: 1052518
URL: http://svn.apache.org/viewvc?rev=1052518&view=rev
Log:
Merged revisions 1052516 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1052516 | sergeyb | 2010-12-24 14:49:04 +0000 (Fri, 24 Dec 2010) | 1 line
[JAX-RS] Ensuring custom response code is not lost in case of CXF
interceptors initiating an early copying of headers
........
Modified:
cxf/branches/2.3.x-fixes/ (props changed)
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec 24 15:03:01 2010
@@ -1 +1 @@
-/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724,1042805,1042821,1043225,1043229,1043902,1043907,1043954,1044085,1044238-1044305,1045024,1048915,1048919,1048930,1049078,1049426,1049937,1050005,1050021,1050095,1050102,1050113,1050156,1050165,1050280,1051115,1051613,1051790,1051792,1052338
+/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724,1042805,1042821,1043225,1043229,1043902,1043907,1043954,1044085,1044238-1044305,1045024,1048915,1048919,1048930,1049078,1049426,1049937,1050005,1050021,1050095,1050102,1050113,1050156,1050165,1050280,1051115,1051613,1051790,1051792,1052338,1052516
Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1052518&r1=1052517&r2=1052518&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++
cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Fri Dec 24 15:03:01 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/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1052518&r1=1052517&r2=1052518&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++
cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Fri Dec 24 15:03:01 2010
@@ -91,7 +91,7 @@ public abstract class AbstractHTTPDestin
public static final String HTTP_CONTEXT = "HTTP.CONTEXT";
public static final String HTTP_CONFIG = "HTTP.CONFIG";
public static final String PROTOCOL_HEADERS_CONTENT_TYPE =
Message.CONTENT_TYPE.toLowerCase();
-
+ public static final String RESPONSE_HEADERS_COPIED =
"http.headers.copied";
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";
Modified:
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1052518&r1=1052517&r2=1052518&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Fri Dec 24 15:03:01 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/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java?rev=1052518&r1=1052517&r2=1052518&view=diff
==============================================================================
---
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
(original)
+++
cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestFastInfoset.java
Fri Dec 24 15:03:01 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