cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1037789 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 22 Nov 2010 17:34:33 GMT
Author: sergeyb
Date: Mon Nov 22 17:34:32 2010
New Revision: 1037789

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

........
  r1037786 | sergeyb | 2010-11-22 17:30:14 +0000 (Mon, 22 Nov 2010) | 1 line
  
  [CXF-3133] Support for invocations suspended from JAX-RS subresources, thanks to Willem
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 22 17:34:32 2010
@@ -1 +1 @@
-/cxf/trunk:1036840,1036917,1037707
+/cxf/trunk:1036840,1036917,1037707,1037786

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1037789&r1=1037788&r2=1037789&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Mon Nov 22 17:34:32 2010
@@ -37,6 +37,7 @@ import org.apache.cxf.common.logging.Log
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.InterceptorChain.State;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -60,6 +61,8 @@ public class JAXRSInvoker extends Abstra
     private static final String SERVICE_LOADER_AS_CONTEXT = "org.apache.cxf.serviceloader-context";
     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";
     
     public JAXRSInvoker() {
     }
@@ -77,45 +80,62 @@ public class JAXRSInvoker extends Abstra
             return new MessageContentsList(response);
         }
         ResourceProvider provider = getResourceProvider(exchange);
-        Object serviceObject = getServiceObject(exchange);
+        Object rootInstance = getServiceObject(exchange);
+        Object serviceObject = getActualServiceObject(exchange, rootInstance);
+        
         try {
             return invoke(exchange, request, serviceObject);
         } finally {
-            if (exchange.isOneWay()) {
-                ProviderFactory.getInstance(exchange.getInMessage()).clearThreadLocalProxies();
-            }
-            if (!isServiceObjectRequestScope(exchange.getInMessage())) {
-                provider.releaseInstance(exchange.getInMessage(), serviceObject);
+            boolean suspended = exchange.getInMessage().getInterceptorChain().getState()
== State.SUSPENDED;
+            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 {
-                exchange.put(JAXRSUtils.ROOT_INSTANCE, serviceObject);
-                exchange.put(JAXRSUtils.ROOT_PROVIDER, provider);
+                persistRoots(exchange, rootInstance, provider);
+                exchange.put(REQUEST_WAS_SUSPENDED, true);
             }
         }
     }
 
+    private void persistRoots(Exchange exchange, Object rootInstance, Object provider) {
+        exchange.put(JAXRSUtils.ROOT_INSTANCE, rootInstance);
+        exchange.put(JAXRSUtils.ROOT_PROVIDER, provider);
+    }
+    
     @SuppressWarnings("unchecked")
     public Object invoke(Exchange exchange, Object request, Object resourceObject) {
 
         OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
         ClassResourceInfo cri = ori.getClassResourceInfo();
-        
-        pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), exchange.getInMessage());
-                
-        Method methodToInvoke = InjectionUtils.checkProxy(
-             cri.getMethodDispatcher().getMethod(ori), resourceObject);
 
-        if (cri.isRoot()) {
-            JAXRSUtils.handleSetters(ori, resourceObject,
-                                     exchange.getInMessage());
-
-            InjectionUtils.injectContextFields(resourceObject,
-                                               ori.getClassResourceInfo(),
-                                               exchange.getInMessage());
-            InjectionUtils.injectResourceFields(resourceObject,
-                                            ori.getClassResourceInfo(),
-                                            exchange.getInMessage());
+        boolean wasSuspended = exchange.remove(REQUEST_WAS_SUSPENDED) != null;
+        
+        if (!wasSuspended) {
+            pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), exchange.getInMessage());
+                    
+            if (cri.isRoot()) {
+                JAXRSUtils.handleSetters(ori, resourceObject,
+                                         exchange.getInMessage());
+    
+                InjectionUtils.injectContextFields(resourceObject,
+                                                   ori.getClassResourceInfo(),
+                                                   exchange.getInMessage());
+                InjectionUtils.injectResourceFields(resourceObject,
+                                                ori.getClassResourceInfo(),
+                                                exchange.getInMessage());
+            }
         }
+        
 
+        Method methodToInvoke = InjectionUtils.checkProxy(
+            cri.getMethodDispatcher().getMethod(ori), resourceObject);
+        
         List<Object> params = null;
         if (request instanceof List) {
             params = CastUtils.cast((List<?>)request);
@@ -147,6 +167,7 @@ public class JAXRSInvoker extends Abstra
             }
             return new MessageContentsList(excResponse);
         } finally {
+            exchange.put(LAST_SERVICE_OBJECT, resourceObject);
             if (contextLoader != null) {
                 Thread.currentThread().setContextClassLoader(contextLoader);
             }
@@ -230,18 +251,37 @@ public class JAXRSInvoker extends Abstra
     }
     
     private ResourceProvider getResourceProvider(Exchange exchange) {
-        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
-        ClassResourceInfo cri = ori.getClassResourceInfo();
-        return cri.getResourceProvider();
+        Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER);
+        if (provider == null) {
+            OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
+            ClassResourceInfo cri = ori.getClassResourceInfo();
+            return cri.getResourceProvider();
+        } else {
+            return (ResourceProvider)provider;
+        }
     }
     
     public Object getServiceObject(Exchange exchange) {
+        
+        Object root = exchange.remove(JAXRSUtils.ROOT_INSTANCE);
+        if (root != null) {
+            return root;
+        }
+        
         OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
         ClassResourceInfo cri = ori.getClassResourceInfo();
 
         return cri.getResourceProvider().getInstance(exchange.getInMessage());
     }
-
+    
+    public Object getActualServiceObject(Exchange exchange, Object rootInstance) {
+        
+        Object last = exchange.get(LAST_SERVICE_OBJECT);
+        return last !=  null ? last : rootInstance;
+    }
+    
+    
+    
     private static Object checkResultObject(Object result, String subResourcePath) {
         
 

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java?rev=1037789&r1=1037788&r2=1037789&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
Mon Nov 22 17:34:32 2010
@@ -56,6 +56,20 @@ public class BookContinuationStore {
     @Path("/books/{id}")
     public String getBookDescription(@PathParam("id") String id) {
         
+        return handleContinuationRequest(id);
+        
+    }
+    
+    @Path("/books/subresources/")
+    public BookContinuationStore getBookStore() {
+        
+        return this;
+        
+    }
+    
+    @GET
+    @Path("{id}")
+    public String handleContinuationRequest(@PathParam("id") String id) {
         Continuation continuation = getContinuation(id);
         if (continuation == null) {
             throw new RuntimeException("Failed to get continuation");
@@ -76,7 +90,6 @@ public class BookContinuationStore {
         return null;
     }
     
-    
     private void resumeRequest(final String name) {
         
         Continuation suspendedCont = null;

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1037789&r1=1037788&r2=1037789&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Mon Nov 22 17:34:32 2010
@@ -50,7 +50,6 @@ import org.apache.cxf.jaxrs.ext.xml.XMLS
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.jaxrs.provider.XSLTJaxbProvider;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
-import org.apache.cxf.transport.http.HTTPConduit;
 
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -666,9 +665,6 @@ public class JAXRSClientServerBookTest e
         WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/adapter-list",
                                         Collections.singletonList(provider));
         
-        HTTPConduit conduit = WebClient.getConfig(wc).getHttpConduit();
-        conduit.getClient().setReceiveTimeout(1000000);
-        conduit.getClient().setConnectionTimeout(1000000);
         Collection<? extends Book> books = wc.type("application/xml").accept("application/xml")
             .postAndGetCollection(new Books(new Book("CXF", 123L)), Book.class);
         assertEquals(1, books.size());

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsTest.java?rev=1037789&r1=1037788&r2=1037789&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsTest.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsTest.java
Mon Nov 22 17:34:32 2010
@@ -45,24 +45,35 @@ public class JAXRSContinuationsTest exte
     
     @Test
     public void testContinuation() throws Exception {
+        
+        doTestContinuation("books");
+    }
+    
+    @Test
+    public void testContinuationSubresource() throws Exception {
+        
+        doTestContinuation("books/subresources");
+    }
+    
+    private void doTestContinuation(String pathSegment) throws Exception {
         ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS,
                                                              new ArrayBlockingQueue<Runnable>(10));
         CountDownLatch startSignal = new CountDownLatch(1);
         CountDownLatch doneSignal = new CountDownLatch(5);
         
-        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/books/1",

+        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/" + pathSegment
+ "/1", 
                                         "1", 
                                         "CXF in Action1", startSignal, doneSignal));
-        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/books/2",

+        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/" + pathSegment
+ "/2", 
                                         "2", 
                                         "CXF in Action2", startSignal, doneSignal));
-        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/books/3",

+        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/" + pathSegment
+ "/3", 
                                         "3", 
                                         "CXF in Action3", startSignal, doneSignal));
-        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/books/4",

+        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/" + pathSegment
+ "/4", 
                                         "4", 
                                         "CXF in Action4", startSignal, doneSignal));
-        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/books/5",

+        executor.execute(new BookWorker("http://localhost:" + PORT + "/bookstore/" + pathSegment
+ "/5", 
                                         "5", 
                                         "CXF in Action5", startSignal, doneSignal));
         
@@ -70,7 +81,6 @@ public class JAXRSContinuationsTest exte
         doneSignal.await(60, TimeUnit.SECONDS);
         executor.shutdownNow();
         assertEquals("Not all invocations have completed", 0, doneSignal.getCount());
-        
     }
     
     private void checkBook(String address, String id, String expected) throws Exception {



Mime
View raw message