You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2011/02/24 12:58:27 UTC

svn commit: r1074119 - in /cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport: http/AbstractHTTPDestination.java http/Servlet3ContinuationProvider.java servlet/ServletDestination.java

Author: ningjiang
Date: Thu Feb 24 11:58:26 2011
New Revision: 1074119

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

Modified:
    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java

Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1074119&r1=1074118&r2=1074119&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original)
+++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Thu Feb 24 11:58:26 2011
@@ -384,7 +384,7 @@ public abstract class AbstractHTTPDestin
     protected void setupContinuation(Message inMessage,
                       final HttpServletRequest req, 
                       final HttpServletResponse resp) {
-        if (isServlet3) {
+        if (isServlet3 && req.isAsyncSupported()) {
             inMessage.put(ContinuationProvider.class.getName(), 
                           new Servlet3ContinuationProvider(req, resp, inMessage));
         }

Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java?rev=1074119&r1=1074118&r2=1074119&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java (original)
+++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java Thu Feb 24 11:58:26 2011
@@ -39,6 +39,7 @@ public class Servlet3ContinuationProvide
     HttpServletResponse resp; 
     Message inMessage;
     
+    
     public Servlet3ContinuationProvider(HttpServletRequest req,
                                         HttpServletResponse resp, 
                                         Message inMessage) {
@@ -64,7 +65,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 +86,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/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java?rev=1074119&r1=1074118&r2=1074119&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java (original)
+++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java Thu Feb 24 11:58:26 2011
@@ -30,7 +30,9 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.continuations.SuspendedInvocationException;
 import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
@@ -70,6 +72,15 @@ 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
+        if (req.isAsyncSupported()) {
+            return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
+        }
+        return null;
+    }
 
     public void invoke(final ServletContext context, 
                        final HttpServletRequest req, 
@@ -81,20 +92,32 @@ public class ServletDestination extends 
                        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
+        }
  
     }
     protected String getBasePath(String contextPath) throws IOException {



Re: svn commit: r1074119 - in /cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport: http/AbstractHTTPDestination.java http/Servlet3ContinuationProvider.java servlet/ServletDestination.java

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Willem

Are you planning to commit to the trunk ? Just wondering why you
started from the 2.3.x branch...

Cheers, Sergey

On Thu, Feb 24, 2011 at 11:58 AM,  <ni...@apache.org> wrote:
> Author: ningjiang
> Date: Thu Feb 24 11:58:26 2011
> New Revision: 1074119
>
> URL: http://svn.apache.org/viewvc?rev=1074119&view=rev
> Log:
> CXF-3362 Fix the issue of CXF Servlet deploying into Servlet3 container
>
> Modified:
>    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
>    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
>    cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
>
> Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
> URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1074119&r1=1074118&r2=1074119&view=diff
> ==============================================================================
> --- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java (original)
> +++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java Thu Feb 24 11:58:26 2011
> @@ -384,7 +384,7 @@ public abstract class AbstractHTTPDestin
>     protected void setupContinuation(Message inMessage,
>                       final HttpServletRequest req,
>                       final HttpServletResponse resp) {
> -        if (isServlet3) {
> +        if (isServlet3 && req.isAsyncSupported()) {
>             inMessage.put(ContinuationProvider.class.getName(),
>                           new Servlet3ContinuationProvider(req, resp, inMessage));
>         }
>
> Modified: cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
> URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java?rev=1074119&r1=1074118&r2=1074119&view=diff
> ==============================================================================
> --- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java (original)
> +++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java Thu Feb 24 11:58:26 2011
> @@ -39,6 +39,7 @@ public class Servlet3ContinuationProvide
>     HttpServletResponse resp;
>     Message inMessage;
>
> +
>     public Servlet3ContinuationProvider(HttpServletRequest req,
>                                         HttpServletResponse resp,
>                                         Message inMessage) {
> @@ -64,7 +65,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 +86,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/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
> URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java?rev=1074119&r1=1074118&r2=1074119&view=diff
> ==============================================================================
> --- cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java (original)
> +++ cxf/branches/2.3.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java Thu Feb 24 11:58:26 2011
> @@ -30,7 +30,9 @@ import javax.servlet.http.HttpServletRes
>
>  import org.apache.cxf.Bus;
>  import org.apache.cxf.common.logging.LogUtils;
> +import org.apache.cxf.continuations.SuspendedInvocationException;
>  import org.apache.cxf.message.ExchangeImpl;
> +import org.apache.cxf.message.Message;
>  import org.apache.cxf.message.MessageImpl;
>  import org.apache.cxf.service.model.EndpointInfo;
>  import org.apache.cxf.transport.http.AbstractHTTPDestination;
> @@ -70,6 +72,15 @@ 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
> +        if (req.isAsyncSupported()) {
> +            return (Message)req.getAttribute(CXF_CONTINUATION_MESSAGE);
> +        }
> +        return null;
> +    }
>
>     public void invoke(final ServletContext context,
>                        final HttpServletRequest req,
> @@ -81,20 +92,32 @@ public class ServletDestination extends
>                        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
> +        }
>
>     }
>     protected String getBasePath(String contextPath) throws IOException {
>
>
>