cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7277] Making it a bit easier to auto reset the thread local client state
Date Wed, 15 Mar 2017 17:02:28 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes c6b6381a2 -> fdb31a753


[CXF-7277] Making it a bit easier to auto reset the thread local client state


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fdb31a75
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fdb31a75
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fdb31a75

Branch: refs/heads/3.1.x-fixes
Commit: fdb31a753c49329b8f6c29649d6c729b1ad0320f
Parents: c6b6381
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Mar 15 16:54:13 2017 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Mar 15 17:02:11 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/cxf/jaxrs/client/AbstractClient.java |  7 +++++++
 .../org/apache/cxf/jaxrs/client/ClientConfiguration.java | 10 +++++++++-
 .../org/apache/cxf/jaxrs/client/ClientProxyImpl.java     | 11 +++++++----
 .../main/java/org/apache/cxf/jaxrs/client/WebClient.java | 11 +++++++++--
 4 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fdb31a75/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index 99e3bf9..8dfeb6e 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -1136,6 +1136,13 @@ public abstract class AbstractClient implements Client {
         }
         return respClass;
     }
+
+    protected void resetResponseStateImmediatelyIfNeeded() {
+        if (state instanceof ThreadLocalClientState
+            && cfg.isResetThreadLocalStateImmediately()) {
+            state.reset();
+        }
+    }
     
     protected abstract class AbstractBodyWriter extends AbstractOutDatabindingInterceptor
{
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/fdb31a75/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
index 0a3e0ba..77584af 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
@@ -62,7 +62,8 @@ public class ClientConfiguration implements InterceptorProvider, ConduitSelector
     private Map<String, Object> responseContext = new HashMap<String, Object>();
     private long synchronousTimeout = 60000;
     private boolean shutdownBusOnClose;
-    
+    private boolean resetThreadLocalStateImmediately;
+
     public long getSynchronousTimeout() {
         Conduit conduit = getConduit();
         if (conduit instanceof HTTPConduit) {
@@ -245,4 +246,11 @@ public class ClientConfiguration implements InterceptorProvider, ConduitSelector
     public void setShutdownBusOnClose(boolean shutdownBusOnClose) {
         this.shutdownBusOnClose = shutdownBusOnClose;
     }
+
+    public boolean isResetThreadLocalStateImmediately() {
+        return resetThreadLocalStateImmediately;
+    }
+    public void setResetThreadLocalStateImmediately(boolean reset) {
+        resetThreadLocalStateImmediately = reset;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/fdb31a75/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index 9602815..765cd27 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -230,10 +230,13 @@ public class ClientProxyImpl extends AbstractClient implements
         
         setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), 
             body == null ? null : body.getClass(), m.getReturnType());
-        
-        
-        return doChainedInvocation(uri, headers, ori, params, body, bodyIndex, null, null);
-        
+
+        try {
+            return doChainedInvocation(uri, headers, ori, params, body, bodyIndex, null,
null);
+        } finally {
+            resetResponseStateImmediatelyIfNeeded();
+        }
+
     }
 
     private void addNonEmptyPath(UriBuilder builder, String pathValue) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/fdb31a75/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
index 892ce20..16d6b2d 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
@@ -889,8 +889,15 @@ public class WebClient extends AbstractClient {
         }
         MultivaluedMap<String, String> headers = prepareHeaders(responseClass, body);
         resetResponse();
-        Response r = doChainedInvocation(httpMethod, headers, body, requestClass, inGenericType,

-                                         inAnns, responseClass, outGenericType, null, null);
+
+        Response r = null;
+        try {
+            r = doChainedInvocation(httpMethod, headers, body, requestClass, inGenericType,
+                                             inAnns, responseClass, outGenericType, null,
null);
+        } finally {
+            resetResponseStateImmediatelyIfNeeded();
+        }
+        
         if (r.getStatus() >= 300 && responseClass != Response.class) {
             throw convertToWebApplicationException(r);
         }


Mime
View raw message