cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1547820 - in /cxf/trunk: core/src/main/java/org/apache/cxf/interceptor/ core/src/main/java/org/apache/cxf/message/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/f...
Date Wed, 04 Dec 2013 15:16:12 GMT
Author: sergeyb
Date: Wed Dec  4 15:16:11 2013
New Revision: 1547820

URL: http://svn.apache.org/r1547820
Log:
Some updates to do with the request state clean-up on the JAX-RS path

Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/interceptor/ServiceInvokerInterceptor.java
    cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/interceptor/ServiceInvokerInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/interceptor/ServiceInvokerInterceptor.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/interceptor/ServiceInvokerInterceptor.java
(original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/interceptor/ServiceInvokerInterceptor.java
Wed Dec  4 15:16:11 2013
@@ -110,13 +110,18 @@ public class ServiceInvokerInterceptor e
                     super.done();
                     if (contextSwitched.get()) {
                         PhaseInterceptorChain.setCurrentMessage(chain, null);
+                        message.remove(Message.THREAD_CONTEXT_SWITCHED);
                     }
                     chain.releaseChain();
                 }
                 
                 @Override
                 public void run() {
-                    contextSwitched.getAndSet(PhaseInterceptorChain.setCurrentMessage(chain,
message));
+                    if (PhaseInterceptorChain.setCurrentMessage(chain, message)) {
+                        contextSwitched.set(true);
+                        message.put(Message.THREAD_CONTEXT_SWITCHED, true);
+                    }
+                    
                     synchronized (chain) {
                         super.run();
                     }

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/message/Message.java Wed Dec  4 15:16:11 2013
@@ -87,9 +87,11 @@ public interface Message extends StringM
     String PROCESS_ONEWAY_RESPONSE = "org.apache.cxf.transport.processOneWayResponse";
     
     /**
-     * @deprecated use PROCESS_ONEWAY_RESPONSE
+     * Boolean property specifying if the thread which runs a request is 
+     * different to the thread which created this Message.
      */
-    String PROCESS_ONEWAY_REPONSE = PROCESS_ONEWAY_RESPONSE;
+    String THREAD_CONTEXT_SWITCHED = "thread.context.switched";
+    
     
     String ROBUST_ONEWAY = "org.apache.cxf.oneway.robust";
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Dec
 4 15:16:11 2013
@@ -91,6 +91,7 @@ public class JAXRSInvoker extends Abstra
         
         ResourceProvider provider = getResourceProvider(exchange);
         Object rootInstance = null;
+        Message inMessage = exchange.getInMessage();
         try {
             rootInstance = getServiceObject(exchange);
             Object serviceObject = getActualServiceObject(exchange, rootInstance);
@@ -101,16 +102,17 @@ public class JAXRSInvoker extends Abstra
             if (responseList != null) {
                 return responseList; 
             }
-            return handleFault(ex, exchange.getInMessage());
+            return handleFault(ex, inMessage);
         } finally {
             boolean suspended = isSuspended(exchange);
-            if (exchange.isOneWay() || suspended) {
-                ServerProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
-            }
-            if (!suspended && !isServiceObjectRequestScope(exchange.getInMessage()))
{
-                provider.releaseInstance(exchange.getInMessage(), rootInstance);
-            } else {
+            if (suspended || exchange.isOneWay() || inMessage.get(Message.THREAD_CONTEXT_SWITCHED)
!= null) {
+                ServerProviderFactory.clearThreadLocalProxies(inMessage);
+            } 
+            if (suspended || isServiceObjectRequestScope(inMessage)) {
                 persistRoots(exchange, rootInstance, provider);
+            } else {
+                provider.releaseInstance(inMessage, rootInstance);
+                exchange.remove(JAXRSUtils.ROOT_INSTANCE);
             }
         }
     }
@@ -333,12 +335,6 @@ public class JAXRSInvoker extends Abstra
         }
         Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage);
         if (excResponse == null) {
-            ServerProviderFactory.getInstance(inMessage).clearThreadLocalProxies();
-            ClassResourceInfo criRoot =
-                (ClassResourceInfo)inMessage.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
-            if (criRoot != null) {
-                criRoot.clearThreadLocalProxies();
-            }
             inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION, 
                                         JAXRSUtils.propogateException(inMessage));
             throw ex;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
Wed Dec  4 15:16:11 2013
@@ -33,6 +33,7 @@ import org.apache.cxf.helpers.NSStack;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.StaxOutInterceptor;
+import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
@@ -61,6 +62,7 @@ public class JAXRSDefaultFaultOutInterce
             return;
         }
         
+        ServerProviderFactory.releaseRequestState(message);
         if (mustPropogateException(message)) {
             throw f;
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Wed Dec  4 15:16:11 2013
@@ -70,21 +70,22 @@ public class JAXRSInInterceptor extends 
     }
 
     public void handleMessage(Message message) {
+        final Exchange exchange = message.getExchange(); 
         
-        if (message.getExchange().get(OperationResourceInfo.class) != null) {
-            // it's a suspended invocation;
-            return;
-        }
-        message.getExchange().put(Message.REST_MESSAGE, Boolean.TRUE);
+        exchange.put(Message.REST_MESSAGE, Boolean.TRUE);
         
         try {
             processRequest(message);
+            if (exchange.isOneWay()) {
+                ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
+            }
         } catch (Fault ex) {
             convertExceptionToResponseIfPossible(ex.getCause(), message);
         } catch (RuntimeException ex) {
             convertExceptionToResponseIfPossible(ex, message);
         }
-        Response r = message.getExchange().get(Response.class);
+        
+        Response r = exchange.get(Response.class);
         if (r != null) {
             createOutMessage(message, r);
             message.getInterceptorChain().doInterceptStartingAt(message,

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Wed Dec  4 15:16:11 2013
@@ -51,8 +51,6 @@ import org.apache.cxf.interceptor.Abstra
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.impl.ResponseImpl;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
-import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
@@ -81,23 +79,7 @@ public class JAXRSOutInterceptor extends
         try {
             processResponse(providerFactory, message);
         } finally {
-            Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE);
-            Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER);
-            if (rootInstance != null && rootProvider != null) {
-                try {
-                    ((ResourceProvider)rootProvider).releaseInstance(message, rootInstance);
-                } catch (Throwable tex) {
-                    LOG.warning("Exception occurred during releasing the service instance,
"
-                                + tex.getMessage());
-                }
-            }
-            providerFactory.clearThreadLocalProxies();
-            ClassResourceInfo cri =
-                (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
-            if (cri != null) {
-                cri.clearThreadLocalProxies();
-            }
-            
+            ServerProviderFactory.releaseRequestState(providerFactory, message);
         }
             
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java?rev=1547820&r1=1547819&r2=1547820&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
Wed Dec  4 15:16:11 2013
@@ -51,6 +51,7 @@ import org.apache.cxf.jaxrs.impl.Configu
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.BeanParamInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.FilterProviderInfo;
@@ -58,6 +59,7 @@ import org.apache.cxf.jaxrs.model.Operat
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
 public final class ServerProviderFactory extends ProviderFactory {
@@ -462,4 +464,37 @@ public final class ServerProviderFactory
         
     }
     
+    public static void clearThreadLocalProxies(Message message) {
+        clearThreadLocalProxies(ServerProviderFactory.getInstance(message), message);
+    }
+    public static void clearThreadLocalProxies(ServerProviderFactory factory, Message message)
{
+        factory.clearThreadLocalProxies();
+        ClassResourceInfo cri =
+            (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
+        if (cri != null) {
+            cri.clearThreadLocalProxies();
+        }    
+    }
+    public static void releaseRequestState(Message message) {
+        releaseRequestState(ServerProviderFactory.getInstance(message), message);
+    }
+    public static void releaseRequestState(ServerProviderFactory factory, Message message)
{
+        Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE);
+        if (rootInstance != null) {
+            Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER);
+            if (rootProvider != null) {
+                try {
+                    ((ResourceProvider)rootProvider).releaseInstance(message, rootInstance);
+                } catch (Throwable tex) {
+                    // ignore
+                }
+            }
+        }
+        
+        clearThreadLocalProxies(factory, message);
+    }
+    
+    
+    
+    
 }



Mime
View raw message