cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1501213 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java
Date Tue, 09 Jul 2013 12:13:39 GMT
Author: sergeyb
Date: Tue Jul  9 12:13:39 2013
New Revision: 1501213

URL: http://svn.apache.org/r1501213
Log:
[CXF-5104] Releasing contexts when CXF continuations are used, using PhaseInterceptorChain
when the call is resumed directly on a subresource instance

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java

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=1501213&r1=1501212&r2=1501213&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 Tue Jul
 9 12:13:39 2013
@@ -65,7 +65,6 @@ public class JAXRSInvoker extends Abstra
     private static final String SERVICE_OBJECT_SCOPE = "org.apache.cxf.service.scope";
     private static final String REQUEST_SCOPE = "request";    
     private static final String LAST_SERVICE_OBJECT = "org.apache.cxf.service.object.last";
-    private static final String REQUEST_WAS_SUSPENDED = "org.apache.cxf.service.request.suspended";
     private static final String PROXY_INVOCATION_ERROR_FRAGMENT 
         = "object is not an instance of declaring class"; 
     
@@ -104,19 +103,13 @@ public class JAXRSInvoker extends Abstra
             return handleFault(ex, exchange.getInMessage());
         } finally {
             boolean suspended = exchange.getInMessage().getInterceptorChain().getState()
== State.SUSPENDED;
-            if (!suspended) {
-                if (exchange.isOneWay()) {
-                    ServerProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
-                }
-                if (!isServiceObjectRequestScope(exchange.getInMessage())) {
-                    provider.releaseInstance(exchange.getInMessage(), rootInstance);
-                } else {
-                    persistRoots(exchange, rootInstance, provider);
-                }
-            } else {
-                persistRoots(exchange, rootInstance, provider);
-                exchange.put(REQUEST_WAS_SUSPENDED, true);
+            if (exchange.isOneWay() || suspended) {
+                ServerProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
+            }
+            if (!suspended && !isServiceObjectRequestScope(exchange.getInMessage()))
{
+                provider.releaseInstance(exchange.getInMessage(), rootInstance);
             }
+            persistRoots(exchange, rootInstance, provider);
         }
     }
 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java?rev=1501213&r1=1501212&r2=1501213&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java
Tue Jul  9 12:13:39 2013
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 
+import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ArrayBlockingQueue;
@@ -30,11 +31,16 @@ import java.util.concurrent.TimeUnit;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.continuations.Continuation;
 import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.impl.UriInfoImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 @Path("/bookstore")
 public class BookCxfContinuationStore {
@@ -55,16 +61,17 @@ public class BookCxfContinuationStore {
     @GET
     @Path("/books/{id}")
     public String getBookDescription(@PathParam("id") String id) {
-        
+        URI uri = context.getUriInfo().getAbsolutePath();
+        if (!uri.toString().contains("/books/")) {
+            throw new WebApplicationException(500);
+        }
         return handleContinuationRequest(id);
         
     }
     
     @Path("/books/subresources/")
     public BookCxfContinuationStore getBookStore() {
-        
         return this;
-        
     }
     
     @GET
@@ -129,10 +136,23 @@ public class BookCxfContinuationStore {
     
     private Continuation getContinuation(String name) {
         
-        //System.out.println("Getting continuation for " + name);
         ContinuationProvider provider = 
             (ContinuationProvider)context.get(ContinuationProvider.class.getName());
-        provider.getClass();
+        
+        if (provider == null) {
+            Message m = PhaseInterceptorChain.getCurrentMessage();
+            UriInfo uriInfo = new UriInfoImpl(m);
+            if (uriInfo.getAbsolutePath().toString().contains("/books/subresources/")) {
+                // when we suspend a CXF continuation from a sub-resource, the invocation
will
+                // return directly to that object - and sub-resources do not have contexts
supported
+                // by default - so we just need to depend on PhaseInterceptorChain
+                provider = (ContinuationProvider)m.get(ContinuationProvider.class.getName());
+            } 
+        }
+        if (provider == null) {
+            throw new WebApplicationException(500);
+        }
+        
         synchronized (suspended) {
             Continuation suspendedCont = suspended.remove(name);
             if (suspendedCont != null) {



Mime
View raw message