cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1340168 - in /cxf/trunk: distribution/src/main/release/samples/jaxws_async/ rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/ rt/transports/http-jetty/src/main/resources/META-INF/cxf/ rt/transports/h...
Date Fri, 18 May 2012 16:46:26 GMT
Author: dkulp
Date: Fri May 18 16:46:26 2012
New Revision: 1340168

URL: http://svn.apache.org/viewvc?rev=1340168&view=rev
Log:
[CXF-4323] Switch to the documented Jetty continuation API
Enable the continuations when war deployed to plain Jetty 7.x install

Modified:
    cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationProviderFactory.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationWrapper.java
    cxf/trunk/rt/transports/http-jetty/src/main/resources/META-INF/cxf/bus-extensions.txt
    cxf/trunk/rt/transports/http-jetty/src/main/resources/OSGI-INF/blueprint/httpj.xml

Modified: cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml?rev=1340168&r1=1340167&r2=1340168&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml (original)
+++ cxf/trunk/distribution/src/main/release/samples/jaxws_async/pom.xml Fri May 18 16:46:26
2012
@@ -149,5 +149,23 @@
             <artifactId>spring-web</artifactId>
             <version>3.0.7.RELEASE</version>
         </dependency>
+        <dependency>
+            <!-- With this dependency, if you deploy the war into a standard Jetty 7.x
-->
+            <!-- container, the async methods should still work fine -->
+            <!-- Not needed if deploying to a Servlet 3 based container or non-jetty container
-->
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-transports-http-jetty</artifactId>
+            <version>2.6.1-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.eclipse.jetty</groupId>
+                    <artifactId>jetty-server</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.eclipse.jetty</groupId>
+                    <artifactId>jetty-security</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
 </project>

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationProviderFactory.java?rev=1340168&r1=1340167&r2=1340168&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationProviderFactory.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/continuations/JettyContinuationProviderFactory.java
Fri May 18 16:46:26 2012
@@ -19,25 +19,52 @@
 
 package org.apache.cxf.transport.http_jetty.continuations;
 
+import java.lang.reflect.Method;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestWrapper;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.ContinuationProviderFactory;
-import org.eclipse.jetty.server.Request;
 
 /**
  * 
  */
 public class JettyContinuationProviderFactory implements ContinuationProviderFactory {
 
+    final boolean disableJettyContinuations 
+        = Boolean.getBoolean("org.apache.cxf.transport.http_jetty.continuations.disable");

+    
+    public JettyContinuationProviderFactory() {
+    }
+    
     public ContinuationProvider createContinuationProvider(Message inMessage, 
                                                            HttpServletRequest req,
                                                            HttpServletResponse resp) {
-        if (req instanceof Request && ((Request)req).isAsyncSupported()) {
-            return new JettyContinuationProvider(req, resp, inMessage);
+        if (!disableJettyContinuations) {
+            ServletRequest r2 = req;
+            while (r2 instanceof ServletRequestWrapper) {
+                r2 = ((ServletRequestWrapper)r2).getRequest();
+            }
+            if (!r2.getClass().getName().contains("jetty")) {
+                return null;
+            }
+    
+            try {
+                Method m = r2.getClass().getMethod("isAsyncSupported");
+                Object o = ReflectionUtil.setAccessible(m).invoke(r2);
+                if (((Boolean)o).booleanValue()) {
+                    return new JettyContinuationProvider(req, resp, inMessage);
+                }
+            } catch (Throwable t) {
+                //ignore - either not a proper Jetty request object or classloader issue
+                //or similar.
+            }
         }
         return null;
     }

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=1340168&r1=1340167&r2=1340168&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 May 18 16:46:26 2012
@@ -26,8 +26,7 @@ import org.apache.cxf.continuations.Cont
 import org.apache.cxf.message.Message;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.eclipse.jetty.continuation.ContinuationListener;
-import org.eclipse.jetty.server.AsyncContext;
-import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.continuation.ContinuationSupport;
 
 public class JettyContinuationWrapper implements Continuation, ContinuationListener {
     volatile boolean isNew;
@@ -36,23 +35,19 @@ public class JettyContinuationWrapper im
     volatile Object obj;
     
     private Message message;
-    private final AsyncContext context;
-    private final Request req;
+    private org.eclipse.jetty.continuation.Continuation continuation;
     
     public JettyContinuationWrapper(HttpServletRequest request, 
                                     HttpServletResponse resp, 
                                     Message m) {
-        req = (Request)request;
+        continuation = ContinuationSupport.getContinuation(request);
+        
         message = m;
-        isNew = req.getAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE) == null;
+        isNew = request.getAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE) ==
null;
         if (isNew) {
-            req.setAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE,
-                             message.getExchange().getInMessage());
-            context = req.startAsync(req, resp);
-            context.addContinuationListener(this);
-            req.setAttribute(AbstractHTTPDestination.CXF_ASYNC_CONTEXT, context);
-        } else {
-            context = (AsyncContext)req.getAttribute(AbstractHTTPDestination.CXF_ASYNC_CONTEXT);
+            request.setAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE,
+                                 message.getExchange().getInMessage());
+            continuation.addContinuationListener(this);
         }
     }
 
@@ -65,7 +60,7 @@ public class JettyContinuationWrapper im
 
     public void resume() {
         isResumed = true;
-        context.dispatch();
+        continuation.resume();
     }
 
     public boolean isNew() {
@@ -81,7 +76,7 @@ public class JettyContinuationWrapper im
     }
 
     public void reset() {
-        context.complete();
+        continuation.complete();
         obj = null;
     }
 
@@ -90,11 +85,12 @@ public class JettyContinuationWrapper im
         if (isPending) {
             return false;
         }
-        context.setTimeout(timeout);
         isNew = false;
         // Need to get the right message which is handled in the interceptor chain
         message.getExchange().getInMessage().getInterceptorChain().suspend();
         isPending = true;
+        continuation.setTimeout(timeout);
+        continuation.suspend();
         return true;
     }
     
@@ -107,14 +103,13 @@ public class JettyContinuationWrapper im
     }
     
 
-    public void onComplete(org.eclipse.jetty.continuation.Continuation continuation) {
+    public void onComplete(org.eclipse.jetty.continuation.Continuation cont) {
         getMessage().remove(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE);
         isPending = false;
     }
 
-    public void onTimeout(org.eclipse.jetty.continuation.Continuation continuation) {
+    public void onTimeout(org.eclipse.jetty.continuation.Continuation cont) {
         isPending = false;
-        context.dispatch();
     }
     
 }

Modified: cxf/trunk/rt/transports/http-jetty/src/main/resources/META-INF/cxf/bus-extensions.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/resources/META-INF/cxf/bus-extensions.txt?rev=1340168&r1=1340167&r2=1340168&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/resources/META-INF/cxf/bus-extensions.txt
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/resources/META-INF/cxf/bus-extensions.txt
Fri May 18 16:46:26 2012
@@ -1,3 +1,3 @@
 org.apache.cxf.transport.http_jetty.JettyDestinationFactory::true
 org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory::true
-
+org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProviderFactory:org.apache.cxf.transport.http.ContinuationProviderFactory:true

Modified: cxf/trunk/rt/transports/http-jetty/src/main/resources/OSGI-INF/blueprint/httpj.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/resources/OSGI-INF/blueprint/httpj.xml?rev=1340168&r1=1340167&r2=1340168&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/resources/OSGI-INF/blueprint/httpj.xml (original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/resources/OSGI-INF/blueprint/httpj.xml Fri
May 18 16:46:26 2012
@@ -26,8 +26,4 @@
     </service-properties>
     <bean class="org.apache.cxf.transport.http_jetty.blueprint.HTTPJettyTransportNamespaceHandler"/>
   </service>
-  
-  <service interface="org.apache.cxf.transport.http.ContinuationProviderFactory">
-      <bean class="org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProviderFactory"/>
-  </service>
 </blueprint>
\ No newline at end of file



Mime
View raw message