cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1509879 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/
Date Fri, 02 Aug 2013 21:55:15 GMT
Author: sergeyb
Date: Fri Aug  2 21:55:15 2013
New Revision: 1509879

URL: http://svn.apache.org/r1509879
Log:
Merged revisions 1508512,1509863-1509864 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1508512 | sergeyb | 2013-07-30 17:30:17 +0100 (Tue, 30 Jul 2013) | 1 line
  
  [CXF-5144] Closing async Response objects when possible too
........
  r1509863 | sergeyb | 2013-08-02 22:11:34 +0100 (Fri, 02 Aug 2013) | 1 line
  
  Protecting a bit against the spec requirement to auto-close Response original stream if
the requested entity is not InputStream
........
  r1509864 | sergeyb | 2013-08-02 22:12:34 +0100 (Fri, 02 Aug 2013) | 1 line
  
  Auto-closing async response only if a property is set
........

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/client/AbstractClient.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1508512,1509863-1509864

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/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1509879&r1=1509878&r2=1509879&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Aug  2 21:55:15 2013
@@ -523,7 +523,7 @@ public abstract class AbstractClient imp
         return null;                                                
     }
     
-    private boolean responseStreamCanBeClosed(Message outMessage, Class<?> cls) {
+    protected boolean responseStreamCanBeClosed(Message outMessage, Class<?> cls) {
         return cls != InputStream.class
             && MessageUtils.isTrue(outMessage.getContextualProperty("response.stream.auto.close"));
     }    

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java?rev=1509879&r1=1509878&r2=1509879&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
Fri Aug  2 21:55:15 2013
@@ -44,6 +44,10 @@ class JaxrsClientCallback<T> extends Cli
         this.outType = outGenericType;
         this.responseClass = responseClass;
     }
+
+    public InvocationCallback<T> getHandler() {
+        return handler;
+    }
     
     public Type getOutGenericType() {
         return outType;
@@ -64,6 +68,33 @@ class JaxrsClientCallback<T> extends Cli
     public Future<T> createFuture() {
         return new JaxrsResponseCallback<T>(this);
     }
+    
+    @SuppressWarnings("unchecked")
+    public void handleResponse(Map<String, Object> ctx, Object[] res) {
+        context = ctx;
+        result = res;
+        if (handler != null) {
+            handler.completed((T)res[0]);
+        }
+        done = true;
+        synchronized (this) {
+            notifyAll();
+        }
+    }
+
+    @Override
+    public void handleException(Map<String, Object> ctx, final Throwable ex) {
+        context = ctx;
+        exception = ex;
+        if (handler != null) {
+            handler.failed(new ClientException(exception));
+        }
+        done = true;
+        synchronized (this) {
+            notifyAll();
+        }
+    }
+
     static class JaxrsResponseCallback<T> implements Future<T> {
         JaxrsClientCallback<T> callback;
         public JaxrsResponseCallback(JaxrsClientCallback<T> cb) {
@@ -115,31 +146,4 @@ class JaxrsClientCallback<T> extends Cli
             return callback.isDone();
         }
     }
-    
-    
-    @SuppressWarnings("unchecked")
-    public void handleResponse(Map<String, Object> ctx, Object[] res) {
-        context = ctx;
-        result = res;
-        if (handler != null) {
-            handler.completed((T)res[0]);
-        }
-        done = true;
-        synchronized (this) {
-            notifyAll();
-        }
-    }
-
-    @Override
-    public void handleException(Map<String, Object> ctx, final Throwable ex) {
-        context = ctx;
-        exception = ex;
-        if (handler != null) {
-            handler.failed(new ClientException(exception));
-        }
-        done = true;
-        synchronized (this) {
-            notifyAll();
-        }
-    }
-}
\ No newline at end of file
+}

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1509879&r1=1509878&r2=1509879&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Fri Aug  2 21:55:15 2013
@@ -998,11 +998,17 @@ public class WebClient extends AbstractC
             cb.handleException(message, convertToWebApplicationException(r));
         } else {
             cb.handleResponse(message, new Object[] {r.getEntity()});
+            closeAsyncResponseIfPossible(r, message, cb);
         }
     }
     private void handleAsyncFault(Message message) {
     }
 
+    private void closeAsyncResponseIfPossible(Response r, Message outMessage, JaxrsClientCallback<?>
cb) {
+        if (responseStreamCanBeClosed(outMessage, cb.getResponseClass())) {
+            r.close();
+        }
+    } 
 
     //TODO: retry invocation will not work in case of async request failures for the moment
     @Override

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1509879&r1=1509878&r2=1509879&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Fri Aug  2 21:55:15 2013
@@ -51,6 +51,7 @@ import org.apache.cxf.jaxrs.provider.Pro
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 
 public final class ResponseImpl extends Response {
     private int status;
@@ -326,7 +327,9 @@ public final class ResponseImpl extends 
                                                                            InputStream.class.cast(entity),

                                                                            mediaType, 
                                                                            responseMessage);
-                    InputStream.class.cast(entity).close();
+                    if (responseStreamCanBeClosed(cls)) {
+                        InputStream.class.cast(entity).close();
+                    }
                     entity = newEntity;
                     entityBufferred = true;
                     
@@ -340,6 +343,10 @@ public final class ResponseImpl extends 
         
     }
     
+    protected boolean responseStreamCanBeClosed(Class<?> cls) {
+        return cls != InputStream.class
+            && MessageUtils.isTrue(responseMessage.getContextualProperty("response.stream.auto.close"));
+    }
     
     public boolean bufferEntity() throws MessageProcessingException {
         checkEntityIsClosed();



Mime
View raw message