cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1508512 - in /cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client: JaxrsClientCallback.java WebClient.java
Date Tue, 30 Jul 2013 16:30:18 GMT
Author: sergeyb
Date: Tue Jul 30 16:30:17 2013
New Revision: 1508512

URL: http://svn.apache.org/r1508512
Log:
[CXF-5144] Closing async Response objects when possible too

Modified:
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java?rev=1508512&r1=1508511&r2=1508512&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JaxrsClientCallback.java
Tue Jul 30 16:30:17 2013
@@ -44,6 +44,10 @@ class JaxrsClientCallback<T> extends Cli
         this.responseClass = responseClass;
     }
     
+    public InvocationCallback<T> getHandler() {
+        return handler;
+    }
+    
     public Type getOutGenericType() {
         return outType;
     }
@@ -63,6 +67,36 @@ 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(exception);
+        }
+        done = true;
+        synchronized (this) {
+            notifyAll();
+        }
+    }
+    
+    
+    
     static class JaxrsResponseCallback<T> implements Future<T> {
         JaxrsClientCallback<T> callback;
         public JaxrsResponseCallback(JaxrsClientCallback<T> cb) {
@@ -114,31 +148,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(exception);
-        }
-        done = true;
-        synchronized (this) {
-            notifyAll();
-        }
-    }
 }
\ No newline at end of file

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1508512&r1=1508511&r2=1508512&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Tue Jul
30 16:30:17 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.client;
 
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
@@ -993,11 +994,19 @@ public class WebClient extends AbstractC
             cb.handleResponse(message, new Object[] {r});
         } else if (r.getStatus() >= 300) {
             cb.handleException(message, convertToWebApplicationException(r));
+            closeResponseIfPossible(r);
         } else {
             cb.handleResponse(message, new Object[] {r.getEntity()});
+            closeResponseIfPossible(r);
         }
-        
     }
+    
+    private void closeResponseIfPossible(Response r) {
+        if (!(r.getEntity() instanceof InputStream)) {
+            r.close();
+        }
+    }
+    
     private void handleAsyncFault(Message message) {
     }
 



Mime
View raw message