cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1444117 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/transports/http-jetty/src/main/j...
Date Fri, 08 Feb 2013 16:37:05 GMT
Author: sergeyb
Date: Fri Feb  8 16:37:04 2013
New Revision: 1444117

URL: http://svn.apache.org/r1444117
Log:
[CXF-4817] Making sure async CompletionCallback is called

Modified:
    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/impl/AsyncResponseImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationWrapper.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.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=1444117&r1=1444116&r2=1444117&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 Fri Feb
 8 16:37:04 2013
@@ -85,7 +85,7 @@ public class JAXRSInvoker extends Abstra
                 AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp;
                 asyncImpl.prepareContinuation();
                 asyncImpl.handleTimeout();
-                return handleAsyncResponse(exchange, asyncImpl.getResponseObject());
+                return handleAsyncResponse(exchange, asyncImpl);
             }
         }
         if (response != null) {
@@ -118,10 +118,16 @@ public class JAXRSInvoker extends Abstra
         }
     }
 
-    private Object handleAsyncResponse(Exchange exchange, Object asyncObj) {
+    private Object handleAsyncResponse(Exchange exchange, AsyncResponseImpl ar) {
+        Object asyncObj = ar.getResponseObject();
         if (asyncObj instanceof Throwable) {
-            return handleFault(new Fault((Throwable)asyncObj), 
-                               exchange.getInMessage(), null, null);    
+            try {
+                return handleFault(new Fault((Throwable)asyncObj), 
+                                   exchange.getInMessage(), null, null);
+            } catch (Fault ex) {
+                ar.reset();
+                throw ex;
+            }
         } else {
             return new MessageContentsList(asyncObj);
         }
@@ -192,7 +198,7 @@ public class JAXRSInvoker extends Abstra
             }
             result = invoke(exchange, resourceObject, methodToInvoke, params);
             if (asyncResponse != null && !asyncResponse.suspendContinuationIfNeeded())
{
-                result = handleAsyncResponse(exchange, asyncResponse.getResponseObject());
+                result = handleAsyncResponse(exchange, asyncResponse);
             }
         } catch (Fault ex) {
             return handleFault(ex, inMessage, cri, methodToInvoke);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java?rev=1444117&r1=1444116&r2=1444117&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java
Fri Feb  8 16:37:04 2013
@@ -247,5 +247,8 @@ public class AsyncResponseImpl implement
         initContinuation();
     }
     
+    public void reset() {
+        cont.reset();
+    }
     
 }

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=1444117&r1=1444116&r2=1444117&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
Fri Feb  8 16:37:04 2013
@@ -53,6 +53,7 @@ import org.apache.cxf.common.util.ClassH
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.ext.ResponseHandler;
+import org.apache.cxf.jaxrs.impl.AsyncResponseImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
@@ -102,6 +103,10 @@ public class JAXRSOutInterceptor extends
             if (cri != null) {
                 cri.clearThreadLocalProxies();
             }
+            AsyncResponse ar = (AsyncResponse)message.getExchange().get(AsyncResponse.class);
+            if (ar != null) {
+                ((AsyncResponseImpl)ar).reset();
+            }
         }
             
 

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationWrapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationWrapper.java?rev=1444117&r1=1444116&r2=1444117&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationWrapper.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationWrapper.java
Fri Feb  8 16:37:04 2013
@@ -81,7 +81,12 @@ public class JettyContinuationWrapper im
     }
 
     public void reset() {
-        continuation.complete();
+        try {
+            continuation.complete();
+        } catch (Throwable ex) {
+            // explicit complete call does not seem to work 
+            // with the non-Servlet3 Jetty Continuation
+        }
         obj = null;
         pendingTimeout = 0;
     }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java?rev=1444117&r1=1444116&r2=1444117&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractJAXRSContinuationsTest.java
Fri Feb  8 16:37:04 2013
@@ -58,6 +58,22 @@ public abstract class AbstractJAXRSConti
     }
     
     @Test
+    public void testGetBookNotFound() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + getPort() + "/bookstore/books/notfound");
+        wc.accept("text/plain");
+        Response r = wc.get();
+        assertEquals(404, r.getStatus());
+    }
+    
+    @Test
+    public void testGetBookNotFoundUnmapped() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + getPort() + "/bookstore/books/notfound/unmapped");
+        wc.accept("text/plain");
+        Response r = wc.get();
+        assertEquals(500, r.getStatus());
+    }
+    
+    @Test
     public void testTimeoutAndCancel() throws Exception {
         WebClient wc = WebClient.create("http://localhost:" + getPort() + "/bookstore/books/cancel");
         WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java?rev=1444117&r1=1444116&r2=1444117&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
Fri Feb  8 16:37:04 2013
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -101,6 +102,21 @@ public class BookContinuationStore {
         resumeSuspended(id, response);
     }
     
+    @GET
+    @Path("books/notfound")
+    @Produces("text/plain")
+    public void handleContinuationRequestNotFound(AsyncResponse response) {
+        response.register(new CallbackImpl());
+        resumeSuspendedNotFound(response);
+    }
+    
+    @GET
+    @Path("books/notfound/unmapped")
+    @Produces("text/plain")
+    public void handleContinuationRequestNotFoundUnmapped(AsyncResponse response) {
+        response.register(new CallbackImpl());
+        resumeSuspendedNotFoundUnmapped(response);
+    }
     
     
     private void resumeSuspended(final String id, final AsyncResponse response) {
@@ -118,6 +134,35 @@ public class BookContinuationStore {
         
     }
     
+    private void resumeSuspendedNotFound(final AsyncResponse response) {
+        
+        executor.execute(new Runnable() {
+            public void run() {
+                try {
+                    Thread.sleep(2000);
+                } catch (InterruptedException ex) {
+                    // ignore
+                }       
+                response.resume(new NotFoundException());
+            }
+        });
+        
+    }
+    
+    private void resumeSuspendedNotFoundUnmapped(final AsyncResponse response) {
+        executor.execute(new Runnable() {
+            public void run() {
+                try {
+                    Thread.sleep(2000);
+                } catch (InterruptedException ex) {
+                    // ignore
+                }       
+                response.resume(new BookNotFoundFault(""));
+            }
+        });
+        
+    }
+    
     private void init() {
         books.put("1", "CXF in Action1");
         books.put("2", "CXF in Action2");
@@ -162,7 +207,6 @@ public class BookContinuationStore {
         @Override
         public void onComplete(Throwable throwable) {
             System.out.println("CompletionCallback: onComplete");
-            
         }
         
     }



Mime
View raw message