You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/07/09 14:33:24 UTC

svn commit: r1501222 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/

Author: sergeyb
Date: Tue Jul  9 12:33:24 2013
New Revision: 1501222

URL: http://svn.apache.org/r1501222
Log:
Merged revisions 1501213 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1501213 | sergeyb | 2013-07-09 13:13:39 +0100 (Tue, 09 Jul 2013) | 1 line
  
  [CXF-5104] Releasing contexts when CXF continuations are used, using PhaseInterceptorChain when the call is resumed directly on a subresource instance
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSCxfContinuationsTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1501213

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1501222&r1=1501221&r2=1501222&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Tue Jul  9 12:33:24 2013
@@ -106,19 +106,17 @@ public class JAXRSInvoker extends Abstra
             return handleFault(ex, exchange.getInMessage());
         } finally {
             boolean suspended = exchange.getInMessage().getInterceptorChain().getState() == State.SUSPENDED;
+            if (exchange.isOneWay() || suspended) {
+                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
+            }
             if (!suspended) {
-                if (exchange.isOneWay()) {
-                    ProviderFactory.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);
             }
+            persistRoots(exchange, rootInstance, provider);
         }
     }
 

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java?rev=1501222&r1=1501221&r2=1501222&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookCxfContinuationStore.java Tue Jul  9 12:33:24 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) {

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSCxfContinuationsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSCxfContinuationsTest.java?rev=1501222&r1=1501221&r2=1501222&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSCxfContinuationsTest.java (original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSCxfContinuationsTest.java Tue Jul  9 12:33:24 2013
@@ -51,6 +51,12 @@ public class JAXRSCxfContinuationsTest e
         
         doTestContinuation("books");
     }
+
+    @Test
+    public void testContinuationSubresource() throws Exception {
+        
+        doTestContinuation("books/subresources");
+    }
     
     private void doTestContinuation(String pathSegment) throws Exception {
         ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS,