You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/12/20 16:39:21 UTC

svn commit: r1552704 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java

Author: sergeyb
Date: Fri Dec 20 15:39:21 2013
New Revision: 1552704

URL: http://svn.apache.org/r1552704
Log:
Autoclosing Response if the exception occurred, re-enabling all the async tests

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1552704&r1=1552703&r2=1552704&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java Fri Dec 20 15:39:21 2013
@@ -371,13 +371,10 @@ public final class ResponseImpl extends 
                                                                        entityStream, 
                                                                        mediaType, 
                                                                        responseMessage);
-                if (!entityBufferred && responseStreamCanBeClosed(cls)) {
-                    InputStream.class.cast(entity).close();
-                    entity = null;
-                } 
-                
+                autoClose(cls, false); 
                 return castLastEntity();
             } catch (Exception ex) {
+                autoClose(cls, true);
                 reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, mediaType, ex);
             }
         } else if (entity != null && cls.isAssignableFrom(entity.getClass())) {
@@ -436,10 +433,11 @@ public final class ResponseImpl extends 
         throw new ResponseProcessingException(this, errorMessage, cause);
     }
     
-    protected boolean responseStreamCanBeClosed(Class<?> cls) {
-        return cls != InputStream.class
-            && entity instanceof InputStream
-            && MessageUtils.isTrue(outMessage.getContextualProperty("response.stream.auto.close"));
+    protected void autoClose(Class<?> cls, boolean exception) {
+        if (!entityBufferred && cls != InputStream.class
+            && (exception || MessageUtils.isTrue(outMessage.getContextualProperty("response.stream.auto.close")))) {
+            close();
+        }
     }
     
     public boolean bufferEntity() throws ProcessingException {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java?rev=1552704&r1=1552703&r2=1552704&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java Fri Dec 20 15:39:21 2013
@@ -48,7 +48,6 @@ import org.apache.cxf.testutil.common.Ab
 
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase {
@@ -101,16 +100,15 @@ public class JAXRSAsyncClientTest extend
     }
     
     @Test
-    @Ignore
     public void testGetBookAsyncResponse404() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
         WebClient wc = createWebClient(address);
         Future<Response> future = wc.async().get(Response.class);
         assertEquals(404, future.get().getStatus());
+        wc.close();
     }
     
     @Test
-    @Ignore
     public void testGetBookAsync404() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
         WebClient wc = createWebClient(address);
@@ -124,7 +122,6 @@ public class JAXRSAsyncClientTest extend
     }
     
     @Test
-    @Ignore
     public void testPostBookProcessingException() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/";
         List<Object> providers = new ArrayList<Object>();
@@ -141,7 +138,6 @@ public class JAXRSAsyncClientTest extend
     }
     
     @Test
-    @Ignore
     public void testGetBookResponseProcessingException() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/123";
         List<Object> providers = new ArrayList<Object>();
@@ -158,7 +154,6 @@ public class JAXRSAsyncClientTest extend
     }
     
     @Test
-    @Ignore
     public void testGetBookAsync404Callback() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
         WebClient wc = createWebClient(address);