You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by ms...@apache.org on 2016/04/14 14:29:19 UTC

[39/50] [abbrv] portals-pluto git commit: Fixed bug where portlet request context was initialized with the wrong wrapped request. Introduced code to display proper dispatcher type during processing.

Fixed bug where portlet request context was initialized with the wrong
wrapped request. Introduced code to display proper dispatcher type during
processing.


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/8d98baf2
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/8d98baf2
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/8d98baf2

Branch: refs/heads/master
Commit: 8d98baf2d1aa903ac108653b2a022c861055096e
Parents: 78dee92
Author: Scott Nicklous <ms...@apache.org>
Authored: Sat Apr 2 21:29:41 2016 +0200
Committer: Scott Nicklous <ms...@apache.org>
Committed: Sat Apr 2 21:29:41 2016 +0200

----------------------------------------------------------------------
 .../pluto/container/PortletAsyncContext.java    |  2 +-
 .../pluto/container/PortletRequestContext.java  |  6 +++
 .../pluto/container/driver/PortletServlet3.java | 31 ++++++++------
 .../bean/processor/PortletInvoker.java          | 27 ++++++------
 .../impl/PortletRequestDispatcherImpl.java      |  5 +++
 .../container/PortletAsyncContextImpl.java      |  2 +-
 .../container/PortletRequestContextImpl.java    | 45 +++++++++++++++++++-
 .../PortletResourceRequestContextImpl.java      |  5 ---
 8 files changed, 91 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-container-api/src/main/java/org/apache/pluto/container/PortletAsyncContext.java
----------------------------------------------------------------------
diff --git a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletAsyncContext.java b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletAsyncContext.java
index 1567767..709306e 100644
--- a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletAsyncContext.java
+++ b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletAsyncContext.java
@@ -4,7 +4,7 @@ import javax.servlet.AsyncContext;
 
 public interface PortletAsyncContext extends AsyncContext {
 
-   void requestComplete(PortletResourceRequestContext prctx);
+   void init(PortletResourceRequestContext prctx);
 
    /**
     * @param actx the async context to set

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
----------------------------------------------------------------------
diff --git a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
index 322e427..185f940 100644
--- a/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
+++ b/pluto-container-api/src/main/java/org/apache/pluto/container/PortletRequestContext.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import javax.portlet.ActionParameters;
 import javax.portlet.PortletConfig;
 import javax.portlet.RenderParameters;
+import javax.servlet.DispatcherType;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.Cookie;
@@ -80,4 +81,9 @@ public interface PortletRequestContext
     // for render headers support
     void setRenderHeaders(String renderHeaders);
     String getRenderHeaders();
+    
+    // for async support
+    DispatcherType getDispatcherType();
+    boolean isExecutingRequestBody();
+    void setExecutingRequestBody(boolean executingRequestBody);
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletServlet3.java
----------------------------------------------------------------------
diff --git a/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletServlet3.java b/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletServlet3.java
index b936626..c831773 100644
--- a/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletServlet3.java
+++ b/pluto-container-driver-api/src/main/java/org/apache/pluto/container/driver/PortletServlet3.java
@@ -336,6 +336,7 @@ public class PortletServlet3 extends HttpServlet {
          
          // the contexts are already initialized if this is part of a resource request async sequence
          requestContext.init(portletConfig, getServletContext(), request, response);
+         requestContext.setExecutingRequestBody(true);
          responseContext.init(request, response);
       
       }
@@ -343,12 +344,8 @@ public class PortletServlet3 extends HttpServlet {
       PortletWindow window = requestContext.getPortletWindow();
 
       PortletInvocationEvent event = new PortletInvocationEvent(portletRequest, window, methodId.intValue());
-
       notify(event, true, null);
-
-      // FilterManager filtermanager = (FilterManager) request.getAttribute(
-      // "filter-manager");
-
+      
       try {
 
          // The requested method is RENDER: call Portlet.render(..)
@@ -441,15 +438,25 @@ public class PortletServlet3 extends HttpServlet {
          throw new ServletException(ex);
 
       } finally {
-         // If an async request is running or has been dispatched, resources will
-         // be released by the PortletAsyncListener. Otherwise release here.
-         if (!request.isAsyncStarted() && (request.getDispatcherType() != DispatcherType.ASYNC)) {
+         
+         // If an async request is running or has been dispatched, resources
+         // will be released by the PortletAsyncListener. Otherwise release here.
+         
+         requestContext.setExecutingRequestBody(false);
+         if (!request.isAsyncStarted()) {
+            
+            LOG.debug("Async not started, releasing resources. executing req body: " + requestContext.isExecutingRequestBody());
+            
+            if (request.getDispatcherType() != DispatcherType.ASYNC) {
 
-            request.removeAttribute(PortletInvokerService.METHOD_ID);
-            request.removeAttribute(PortletInvokerService.PORTLET_REQUEST);
-            request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
-            request.removeAttribute(PortletInvokerService.FILTER_MANAGER);
+               request.removeAttribute(PortletInvokerService.METHOD_ID);
+               request.removeAttribute(PortletInvokerService.PORTLET_REQUEST);
+               request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
+               request.removeAttribute(PortletInvokerService.FILTER_MANAGER);
 
+            }
+         } else {
+            LOG.debug("Async started, not releasing resources. executing req body: " + requestContext.isExecutingRequestBody());
          }
       }
    }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
index 982cee5..7507f2c 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/bean/processor/PortletInvoker.java
@@ -54,7 +54,6 @@ import javax.xml.namespace.QName;
 import org.apache.pluto.container.PortletAsyncContext;
 import org.apache.pluto.container.PortletInvokerService;
 import org.apache.pluto.container.PortletResourceRequestContext;
-import org.apache.pluto.container.impl.PortletAsyncRequestWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -335,20 +334,24 @@ public class PortletInvoker implements Portlet, ResourceServingPortlet, EventPor
                
                LOG.debug("Async processing was started during method: " + meth.toString());
                req.setAttribute(PortletInvokerService.ASYNC_METHOD, meth);
+
+               // Initialize the async context after the request during which async is 
+               // first started.
                
-               PortletResourceRequestContext reqctx = (PortletResourceRequestContext) req.getAttribute(PortletInvokerService.REQUEST_CONTEXT);
-               if (reqctx != null) {
-                  PortletAsyncContext pac = reqctx.getPortletAsyncContext();
-                  if (pac != null) {
-                     pac.requestComplete(reqctx);
+               if (req.getDispatcherType() != DispatcherType.ASYNC) {
+                  PortletResourceRequestContext reqctx = (PortletResourceRequestContext) req
+                        .getAttribute(PortletInvokerService.REQUEST_CONTEXT);
+                  if (reqctx != null) {
+                     PortletAsyncContext pac = reqctx.getPortletAsyncContext();
+                     if (pac != null) {
+                        pac.init(reqctx);
+                     } else {
+                        LOG.warn("Couldn't get portlet async context.");
+                     }
                   } else {
-                     LOG.warn("Couldn't get portlet async context.");
+                     LOG.warn("Couldn't get request context.");
                   }
-               } else {
-                  LOG.warn("Couldn't get request context.");
-               }
-            
-               
+               }            
                
                break;
                

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
----------------------------------------------------------------------
diff --git a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
index 90c6904..29a939a 100644
--- a/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
+++ b/pluto-container/src/main/java/org/apache/pluto/container/impl/PortletRequestDispatcherImpl.java
@@ -159,6 +159,10 @@ public class PortletRequestDispatcherImpl implements PortletRequestDispatcher, R
                                                                                       request,
                                                                                       response,
                                                                                       included);
+        
+        boolean executingReqBody = requestContext.isExecutingRequestBody();
+        requestContext.setExecutingRequestBody(false);
+        
         try
         {
             request.setAttribute(PortletInvokerService.PORTLET_CONFIG, requestContext.getPortletConfig());
@@ -192,6 +196,7 @@ public class PortletRequestDispatcherImpl implements PortletRequestDispatcher, R
             request.removeAttribute(PortletInvokerService.PORTLET_CONFIG);
             request.removeAttribute(PortletInvokerService.PORTLET_REQUEST);
             request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE);
+            requestContext.setExecutingRequestBody(executingReqBody);
         }
     }
     

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletAsyncContextImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletAsyncContextImpl.java b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletAsyncContextImpl.java
index 2e0288d..d638db1 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletAsyncContextImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletAsyncContextImpl.java
@@ -53,7 +53,7 @@ public class PortletAsyncContextImpl implements PortletAsyncContext {
     * @see org.apache.pluto.driver.services.container.PortletAsyncContext#requestComplete(org.apache.pluto.container.PortletResourceRequestContext)
     */
    @Override
-   public void requestComplete(PortletResourceRequestContext prctx) {
+   public void init(PortletResourceRequestContext prctx) {
 
       // get the original container req & resp to pass to listener for resource releasing
 

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
index 694b955..a059fef 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletRequestContextImpl.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import javax.portlet.ActionParameters;
 import javax.portlet.PortletConfig;
 import javax.portlet.RenderParameters;
+import javax.servlet.DispatcherType;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.http.Cookie;
@@ -46,12 +47,18 @@ import org.apache.pluto.container.impl.ResourceParametersImpl;
 import org.apache.pluto.driver.core.PortalRequestContext;
 import org.apache.pluto.driver.url.PortalURL;
 import org.apache.pluto.driver.url.PortletParameterFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Id$
  *
  */
 public class PortletRequestContextImpl implements PortletRequestContext {
+   private static final Logger LOG = LoggerFactory.getLogger(PortletRequestContextImpl.class);
+   private static final boolean isDebug = LOG.isDebugEnabled();
+   private static final boolean isTrace = LOG.isTraceEnabled();
+   
 
    private PortletContainer    container;
    private HttpServletRequest  containerRequest;
@@ -62,7 +69,8 @@ public class PortletRequestContextImpl implements PortletRequestContext {
    private PortletConfig       portletConfig;
    private ServletContext      servletContext;
    private Cookie              cookies[];
-   private String              renderHeaders = null;      
+   private String              renderHeaders = null; 
+   private boolean             executingRequestBody = false;
    
    // make sure these classes are loaded first by the container classloader
    // so that the logs from these classes land in the Pluto log file.
@@ -244,4 +252,39 @@ public class PortletRequestContextImpl implements PortletRequestContext {
    public ActionParameters getActionParameters() {
       return new ActionParametersImpl(urlProvider, windowId);
    }
+
+   /**
+    * Make it look like request type while the portlet request body is executing.
+    */
+   @Override
+   public DispatcherType getDispatcherType() {
+      DispatcherType type = getServletRequest().getDispatcherType();
+      if (isDebug) {
+         StringBuilder txt = new StringBuilder();
+         txt.append("Dispatcher type: ").append(type);
+         txt.append(", executing request body: ").append(executingRequestBody);
+         LOG.debug(txt.toString());
+      }
+      if (executingRequestBody && (type != DispatcherType.ASYNC)) {
+         type = DispatcherType.REQUEST;
+      }
+      return type;
+   }
+
+   /**
+    * @return the executingRequestBody
+    */
+   @Override
+   public boolean isExecutingRequestBody() {
+      return executingRequestBody;
+   }
+
+   /**
+    * @param executingRequestBody the executingRequestBody to set
+    */
+   @Override
+   public void setExecutingRequestBody(boolean executingRequestBody) {
+      this.executingRequestBody = executingRequestBody;
+   }
+
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/8d98baf2/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResourceRequestContextImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResourceRequestContextImpl.java b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResourceRequestContextImpl.java
index cadc36f..f607449 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResourceRequestContextImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletResourceRequestContextImpl.java
@@ -274,11 +274,6 @@ public class PortletResourceRequestContextImpl extends PortletRequestContextImpl
       return getServletRequest().getAsyncContext();
    }
 
-   @Override
-   public DispatcherType getDispatcherType() {
-      return getServletRequest().getDispatcherType();
-   }
-
    // For use within the wrapper.
    // PLT.10.4.3. Proxied session is created and passed if
    // javax.portlet.servletDefaultSessionScope == PORTLET_SCOPE