cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1392413 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
Date Mon, 01 Oct 2012 16:01:11 GMT
Author: sergeyb
Date: Mon Oct  1 16:01:11 2012
New Revision: 1392413

URL: http://svn.apache.org/viewvc?rev=1392413&view=rev
Log:
[CXF-4455] Completing AsyncResponse code for now with the optional support for CompletionCallback

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AsyncResponseImpl.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/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=1392413&r1=1392412&r2=1392413&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
Mon Oct  1 16:01:11 2012
@@ -22,18 +22,20 @@ import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
 import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.CompletionCallback;
 import javax.ws.rs.container.TimeoutHandler;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
 import org.apache.cxf.continuations.Continuation;
+import org.apache.cxf.continuations.ContinuationCallback;
 import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.message.Message;
 
 
-public class AsyncResponseImpl implements AsyncResponse {
+public class AsyncResponseImpl implements AsyncResponse, ContinuationCallback {
     
     private Continuation cont;
     private long timeout = AsyncResponse.NO_TIMEOUT;
@@ -43,13 +45,17 @@ public class AsyncResponseImpl implement
     private boolean newTimeoutRequested;
     private boolean resumedByApplication;
     private TimeoutHandler timeoutHandler;
+    
+    private CompletionCallback completionCallback;
+    
     public AsyncResponseImpl(Message inMessage) {
+        inMessage.put(AsyncResponse.class, this);
+        inMessage.getExchange().put(ContinuationCallback.class, this);
+        this.inMessage = inMessage;
+        
         ContinuationProvider provider = 
             (ContinuationProvider)inMessage.get(ContinuationProvider.class.getName());
         cont = provider.getContinuation();
-        inMessage.put(AsyncResponse.class, this);
-        this.inMessage = inMessage;
-       
     }
     
     @Override
@@ -128,26 +134,43 @@ public class AsyncResponseImpl implement
 
     @Override
     public boolean register(Class<?> callback) throws NullPointerException {
-        // TODO Auto-generated method stub
-        return false;
+        return register(callback, CompletionCallback.class)[0];
     }
 
     @Override
     public boolean[] register(Class<?> callback, Class<?>... callbacks) throws
NullPointerException {
-        // TODO Auto-generated method stub
-        return null;
+        try {
+            return register(callback.newInstance(), CompletionCallback.class);    
+        } catch (Throwable t) {
+            return new boolean[]{false};
+        }
+        
     }
 
     @Override
     public boolean register(Object callback) throws NullPointerException {
-        // TODO Auto-generated method stub
-        return false;
+        return register(callback, CompletionCallback.class)[0];
     }
 
+    //TODO: API bug, has to be Class<?>...
     @Override
     public boolean[] register(Object callback, Object... callbacks) throws NullPointerException
{
-        // TODO Auto-generated method stub
-        return null;
+        boolean[] result = new boolean[callbacks.length];
+        
+        for (int i = 0; i < callbacks.length; i++) {
+            Object interf = callbacks[i];
+            if (interf == null) {
+                throw new NullPointerException();
+            }
+            Class<?> cls = (Class<?>)interf;
+            if (cls == CompletionCallback.class) {
+                completionCallback = (CompletionCallback)callback;
+                result[i] = true;
+            } else {
+                result[i] = false;
+            }
+        }
+        return result;
     }
     
     private void checkCancelled() {
@@ -195,4 +218,19 @@ public class AsyncResponseImpl implement
         return false;
         
     }
+
+    @Override
+    public void onComplete() {
+        if (completionCallback != null) {
+            completionCallback.onComplete();
+        }
+    }
+
+    @Override
+    public void onError(Throwable error) {
+        if (completionCallback != null) {
+            completionCallback.onError(error);
+        }
+        
+    }
 }

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=1392413&r1=1392412&r2=1392413&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
Mon Oct  1 16:01:11 2012
@@ -31,6 +31,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.CompletionCallback;
 import javax.ws.rs.container.TimeoutHandler;
 
 @Path("/bookstore")
@@ -47,6 +48,7 @@ public class BookContinuationStore {
     @GET
     @Path("/books/defaulttimeout")
     public void getBookDescriptionWithHandler(AsyncResponse async) {
+        async.register(new CompletionCallbackImpl());
         async.setTimeout(2000, TimeUnit.MILLISECONDS);
     }
     
@@ -115,6 +117,22 @@ public class BookContinuationStore {
         }
         
     }
+    
+    private class CompletionCallbackImpl implements CompletionCallback {
+
+        @Override
+        public void onComplete() {
+            System.out.println("CompletionCallbackImpl: onComplete");
+            
+        }
+
+        @Override
+        public void onError(Throwable throwable) {
+            // TODO Auto-generated method stub
+            
+        }
+        
+    }
 }
 
 



Mime
View raw message