cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1232880 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/
Date Wed, 18 Jan 2012 13:45:16 GMT
Author: sergeyb
Date: Wed Jan 18 13:45:15 2012
New Revision: 1232880

URL: http://svn.apache.org/viewvc?rev=1232880&view=rev
Log:
Merged revisions 1232877 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1232877 | sergeyb | 2012-01-18 13:41:04 +0000 (Wed, 18 Jan 2012) | 1 line
  
  [CXF-4006] Cleaning the thread-local state for clients
........

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1232877

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1232880&r1=1232879&r2=1232880&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Jan 18 13:45:15 2012
@@ -512,20 +512,24 @@ public class ClientProxyImpl extends Abs
     
     protected Object handleResponse(Message outMessage) 
         throws Throwable {
-        Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
-        Method method = outMessage.getExchange().get(Method.class);
-        checkResponse(method, r, outMessage);
-        if (method.getReturnType() == Void.class) { 
-            return null;
-        }
-        if (method.getReturnType() == Response.class
-            && (r.getEntity() == null || InputStream.class.isAssignableFrom(r.getEntity().getClass())
-                && ((InputStream)r.getEntity()).available() == 0)) {
-            return r;
+        try {
+            Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
+            Method method = outMessage.getExchange().get(Method.class);
+            checkResponse(method, r, outMessage);
+            if (method.getReturnType() == Void.class) { 
+                return null;
+            }
+            if (method.getReturnType() == Response.class
+                && (r.getEntity() == null || InputStream.class.isAssignableFrom(r.getEntity().getClass())
+                    && ((InputStream)r.getEntity()).available() == 0)) {
+                return r;
+            }
+            
+            return readBody(r, outMessage, method.getReturnType(), 
+                            method.getGenericReturnType(), method.getDeclaredAnnotations());
+        } finally {
+            ProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
         }
-        
-        return readBody(r, outMessage, method.getReturnType(), 
-                        method.getGenericReturnType(), method.getDeclaredAnnotations());
     }
 
     public Object getInvocationHandler() {

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=1232880&r1=1232879&r2=1232880&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Wed Jan 18 13:45:15 2012
@@ -48,7 +48,8 @@ public class JAXRSClientFactoryBean exte
     private boolean inheritHeaders; 
     private MultivaluedMap<String, String> headers;
     private ClientState initialState;
-    private boolean threadSafe; 
+    private boolean threadSafe;
+    private long timeToKeepState;
     private Class serviceClass;
     
     public JAXRSClientFactoryBean() {
@@ -71,7 +72,16 @@ public class JAXRSClientFactoryBean exte
     public void setThreadSafe(boolean threadSafe) {
         this.threadSafe = threadSafe;
     }
-    
+
+    /**
+     * Sets the time a thread-local client state will be kept.
+     * This property is ignored for thread-unsafe clients
+     * @param secondsToKeepState
+     */
+    public void setSecondsToKeepState(long time) {
+        this.timeToKeepState = time;
+    }
+
     /**
      * Gets the user name
      * @return the name
@@ -196,10 +206,12 @@ public class JAXRSClientFactoryBean exte
             throw new RuntimeException(ex);
         }
     }
+
+    
     
     private ClientState getActualState() {
         if (threadSafe) {
-            initialState = new ThreadLocalClientState(getAddress());
+            initialState = new ThreadLocalClientState(getAddress(), timeToKeepState);
         }
         if (initialState != null) {
             return headers != null

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java?rev=1232880&r1=1232879&r2=1232880&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
Wed Jan 18 13:45:15 2012
@@ -41,14 +41,20 @@ public class ThreadLocalClientState impl
     private LocalClientState initialState;
     
     private Map<Thread, Long> checkpointMap;
-    private long secondsToKeepState;
+    private long timeToKeepState;
     
     public ThreadLocalClientState(String baseURI) {
         this.initialState = new LocalClientState(URI.create(baseURI));
     }
     
-    public ThreadLocalClientState(LocalClientState initialState) {
+    public ThreadLocalClientState(String baseURI, long timeToKeepState) {
+        this.initialState = new LocalClientState(URI.create(baseURI));
+        this.timeToKeepState = timeToKeepState;
+    }
+    
+    public ThreadLocalClientState(LocalClientState initialState, long timeToKeepState) {
         this.initialState = initialState;
+        this.timeToKeepState = timeToKeepState;
     }
     
     public void setCurrentBuilder(UriBuilder currentBuilder) {
@@ -101,7 +107,7 @@ public class ThreadLocalClientState impl
         LocalClientState ls = new LocalClientState(baseURI);
         ls.setRequestHeaders(headers);
         ls.setTemplates(templates);
-        return new ThreadLocalClientState(ls);
+        return new ThreadLocalClientState(ls, timeToKeepState);
     }
     
     private void removeThreadLocalState(Thread t) {
@@ -116,7 +122,7 @@ public class ThreadLocalClientState impl
         if (cs == null) {
             cs = new LocalClientState(initialState);
             state.put(Thread.currentThread(), cs);
-            if (secondsToKeepState > 0) {
+            if (timeToKeepState > 0) {
                 long currentTime = System.currentTimeMillis();
                 checkpointMap.put(Thread.currentThread(), currentTime);
                 new CleanupThread(Thread.currentThread(), currentTime).start();
@@ -125,9 +131,9 @@ public class ThreadLocalClientState impl
         return cs;
     }
 
-    public void setSecondsToKeepState(long secondsToKeepState) {
-        this.secondsToKeepState = secondsToKeepState;
-        if (secondsToKeepState > 0) {
+    public void setTimeToKeepState(long timeToKeepState) {
+        this.timeToKeepState = timeToKeepState;
+        if (timeToKeepState > 0) {
             checkpointMap = new ConcurrentHashMap<Thread, Long>();
         }
     }
@@ -144,7 +150,7 @@ public class ThreadLocalClientState impl
         @Override
         public void run() {
             try {
-                Thread.sleep(secondsToKeepState);
+                Thread.sleep(timeToKeepState);
                 long actualTime = checkpointMap.get(thread);
                 // if times do not match then the original worker thread
                 // has called reset() but came back again to create new local state

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1232880&r1=1232879&r2=1232880&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Wed Jan 18 13:45:15 2012
@@ -49,6 +49,7 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.ext.form.Form;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ParameterizedCollectionType;
@@ -769,6 +770,8 @@ public class WebClient extends AbstractC
         } catch (Throwable ex) {
             throw (ex instanceof ClientWebApplicationException) ? (ClientWebApplicationException)ex
                                                               : new ClientWebApplicationException(ex);
+        } finally {
+            ProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
         }
     }
     



Mime
View raw message