cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1074157 - in /cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport: http/AbstractHTTPDestination.java http/Servlet3ContinuationProvider.java servlet/ServletDestination.java
Date Thu, 24 Feb 2011 14:13:07 GMT
Author: ningjiang
Date: Thu Feb 24 14:13:07 2011
New Revision: 1074157

URL: http://svn.apache.org/viewvc?rev=1074157&view=rev
Log:
CXF-3362 Fix the issue of CXF Servlet deploying into Servlet3 container

Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1074157&r1=1074156&r2=1074157&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Thu Feb 24 14:13:07 2011
@@ -48,6 +48,7 @@ import org.apache.cxf.common.util.String
 import org.apache.cxf.configuration.Configurable;
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.continuations.ContinuationProvider;
+import org.apache.cxf.continuations.SuspendedInvocationException;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.Interceptor;
@@ -180,20 +181,32 @@ public abstract class AbstractHTTPDestin
                        final ServletContext context, 
                        final HttpServletRequest req, 
                        final HttpServletResponse resp) throws IOException {
-        
-        MessageImpl inMessage = new MessageImpl();
-        setupMessage(inMessage,
+        Message inMessage = retrieveFromContinuation(req);
+        if (inMessage == null) {
+            LOG.fine("Create a new message for processing");
+            inMessage = new MessageImpl();
+            setupMessage(inMessage,
                      config,
                      context,
                      req,
                      resp);
 
-        ExchangeImpl exchange = new ExchangeImpl();
-        exchange.setInMessage(inMessage);
-        exchange.setSession(new HTTPSession(req));
-        inMessage.setDestination(this);
+            ExchangeImpl exchange = new ExchangeImpl();
+            exchange.setInMessage(inMessage);
+            exchange.setSession(new HTTPSession(req));
+            ((MessageImpl)inMessage).setDestination(this);
+        } else {
+            LOG.fine("Get the message from the request for processing");
+        }
 
-        incomingObserver.onMessage(inMessage);
+        try {    
+            incomingObserver.onMessage(inMessage);
+        } catch (SuspendedInvocationException ex) {
+            if (ex.getRuntimeException() != null) {
+                throw ex.getRuntimeException();
+            }
+            //else nothing to do, just finishing the processing
+        }
  
     }
 
@@ -309,17 +322,25 @@ public abstract class AbstractHTTPDestin
         return retrieveFromServlet3Async(req);
     }
     protected Message retrieveFromServlet3Async(HttpServletRequest req) {
-        if (req.isAsyncStarted()) {
-            return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
+        try {
+            if (req.isAsyncStarted()) {
+                return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
+            }
+        } catch (Throwable ex) {
+            // the request may not implement the Servlet3 API
         }
         return null;
     }
-    protected void setupContinuation(Message inMessage,
-                      final HttpServletRequest req, 
-                      final HttpServletResponse resp) {
-        if (isServlet3) {
-            inMessage.put(ContinuationProvider.class.getName(), 
-                          new Servlet3ContinuationProvider(req, resp, inMessage));
+
+    protected void setupContinuation(Message inMessage, final HttpServletRequest req,
+                                     final HttpServletResponse resp) {
+        try {
+            if (isServlet3 && req.isAsyncSupported()) {
+                inMessage.put(ContinuationProvider.class.getName(),
+                              new Servlet3ContinuationProvider(req, resp, inMessage));
+            }
+        } catch (Throwable ex) {
+            // the request may not implement the Servlet3 API
         }
     }
     protected String getBasePath(String contextPath) throws IOException {

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java?rev=1074157&r1=1074156&r2=1074157&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
Thu Feb 24 14:13:07 2011
@@ -64,7 +64,9 @@ public class Servlet3ContinuationProvide
         Object obj;
         
         public Servlet3Continuation() {
-            isNew = !req.isAsyncStarted();
+            // It looks current Servlet3 implementation request doesn't pass the isAsyncStart

+            // status to the redispatched request, so we use the attribute to check the statues
+            isNew = req.getAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE) ==
null;
             if (isNew) {
                 req.setAttribute(AbstractHTTPDestination.CXF_CONTINUATION_MESSAGE,
                                  inMessage.getExchange().getInMessage());
@@ -83,7 +85,6 @@ public class Servlet3ContinuationProvide
             isNew = false;
             // Need to get the right message which is handled in the interceptor chain
             inMessage.getExchange().getInMessage().getInterceptorChain().suspend();
-                
             isPending = true;
             return true;
         }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java?rev=1074157&r1=1074156&r2=1074157&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
Thu Feb 24 14:13:07 2011
@@ -23,8 +23,11 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.logging.Logger;
 
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.DestinationRegistry;
@@ -58,6 +61,21 @@ public class ServletDestination extends 
     protected Logger getLogger() {
         return LOG;
     }
+    
+    protected Message retrieveFromServlet3Async(HttpServletRequest req) {
+        // It looks current Servlet3 implementation request doesn't pass the isAsyncStart

+        // status to the redispatched request
+        try {
+            if (req.isAsyncSupported()) {
+                return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
+            }
+        } catch (Throwable ex) {
+            // the request may not implement the Servlet3 API
+        }
+        return null;
+    }
+         
+
 
     protected String getBasePath(String contextPath) throws IOException {
         



Mime
View raw message